diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/profile | 3 | ||||
| -rw-r--r-- | src/run/builtin.rs | 49 | ||||
| -rw-r--r-- | src/syntax_highlighting.rs | 2 |
3 files changed, 42 insertions, 12 deletions
diff --git a/src/profile b/src/profile index 2f4100b..18382fa 100644 --- a/src/profile +++ b/src/profile @@ -20,4 +20,7 @@ bind key \x1bd ct prompt_del_right_word bind key \x17 ct prompt_del_left_word bind key '|' ct prompt_pipe_previous +pish_theme enable + alias ls = 'ls --color=auto' + diff --git a/src/run/builtin.rs b/src/run/builtin.rs index 2255997..dfafcbe 100644 --- a/src/run/builtin.rs +++ b/src/run/builtin.rs @@ -982,28 +982,55 @@ impl Builtin for pish_theme { _stdin: &mut dyn Read, stdout: &mut dyn Write, ) -> Result { - if args.len() != 2 { - stdout.write_all(b"usage: pish_theme <kind> <color>\nwhere color is an ansi escape code,\nand where kind is one of the following: ")?; + let mut usage = || { + stdout.write_all(b"usage:\n")?; + stdout.write_all(b"pish_theme disable\n")?; + stdout.write_all(b"pish_theme enable\n")?; + stdout.write_all(b"pish_theme set <kind> <color>\nwhere color is an ansi escape code,\nand where kind is one of the following: ")?; for ident in crate::parse::HighlightKind::all_identifiers() { stdout.write_all(&ident)?; stdout.write_all(b" ")?; } stdout.write_all(b"\n")?; return Err(Error::Exit(-1)); + }; + + if args.is_empty() { + return usage(); } let mut se = session.lock().unwrap(); - match se.highlighter.set_color(&args[0], &args[1]) { - Ok(_) => Ok(()), - Err(e) => match e { - syntax_highlighting::SetColorError::NoSuchKeyword => { - stdout.write_all(b"no such kind: ")?; - stdout.write_all(&args[0])?; - stdout.write_all(b"\n")?; - Err(Error::Exit(-1)) + + match &args[0][..] { + b"disable" => { + se.highlighter.enabled = false; + } + b"enable" => { + se.highlighter.enabled = true; + } + b"set" => { + if args.len() != 3 { + return usage(); } - }, + + let kind = &args[1][..]; + let color = &args[2][..]; + + if let Err(e) = se.highlighter.set_color(kind, color) { + match e { + syntax_highlighting::SetColorError::NoSuchKeyword => { + stdout.write_all(b"no such kind: ")?; + stdout.write_all(&args[0])?; + stdout.write_all(b"\n")?; + return Err(Error::Exit(-1)); + } + } + } + } + _ => return usage(), } + + Ok(()) } } diff --git a/src/syntax_highlighting.rs b/src/syntax_highlighting.rs index b76aa4b..1a6e626 100644 --- a/src/syntax_highlighting.rs +++ b/src/syntax_highlighting.rs @@ -18,7 +18,7 @@ pub enum SetColorError { impl Highlighter { pub fn new() -> Self { let mut this = Self { - enabled: true, + enabled: false, colors: HashMap::new(), }; let mut sc = |a: &str, b: &str| this.set_color(a.as_bytes(), b.as_bytes()).unwrap(); |
