Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging implementation #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions design/refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Refactoring Projects

List of areas of the project that should be refactored/cleaned up
- Any code that involves handling `OsString` ends up looking very ugly
- DefaultCompletion code is very ugly

2 changes: 2 additions & 0 deletions shrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ lazy_static = "1.4"
shrs_line = { path = "../shrs_line" }
shrs_lang = { path = "../shrs_lang" }

log = { version = "0.4", features = ["std"] }

[dev-dependencies]
rexpect = "0.5"
2 changes: 2 additions & 0 deletions shrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ mod state;

mod jobs;

mod logger;

// TODO temp re-export anyhow
pub use anyhow;

Expand Down
31 changes: 31 additions & 0 deletions shrs/src/logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! Custom implementation of log facade
//!
//!

use log::{Level, Log, Metadata, Record, SetLoggerError};

struct Logger {}

impl Logger {
pub fn init(self) -> Result<(), SetLoggerError> {
log::set_boxed_logger(Box::new(self))
}
}

impl Log for Logger {
fn enabled(&self, metadata: &Metadata) -> bool {
true
}

fn log(&self, record: &Record) {
match record.level() {
Level::Error => todo!(),
Level::Warn => todo!(),
Level::Info => todo!(),
Level::Debug => todo!(),
Level::Trace => todo!(),
}
}

fn flush(&self) {}
}
13 changes: 9 additions & 4 deletions shrs_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ struct MyPrompt;

impl Prompt for MyPrompt {
fn prompt_left(&self) -> String {
let path = top_pwd().white().bold();
let username = username().unwrap_or_default().blue();
let hostname = hostname().unwrap_or_default().blue();
let prompt = ">".blue();
// let path = top_pwd().white().bold();
// let username = username().unwrap_or_default().blue();
// let hostname = hostname().unwrap_or_default().blue();
// let prompt = ">".blue();

let path = top_pwd();
let username = username().unwrap_or_default();
let hostname = hostname().unwrap_or_default();
let prompt = ">";
format!("{hostname}@{username} {path} {prompt} ")
}
fn prompt_right(&self) -> String {
Expand Down