diff options
| author | Jonas Maier <> | 2026-05-23 16:25:54 +0200 |
|---|---|---|
| committer | Jonas Maier <> | 2026-05-23 16:25:54 +0200 |
| commit | a22ed24eb0b20f05ab60a877511e37bd8c4f03a4 (patch) | |
| tree | 548b94aa6453f4de83b916fd15c0c59e3905f94b /src/run | |
| parent | e4c0fc7beab2a6dd53210263a857f2b3ec29b604 (diff) | |
| download | pish-a22ed24eb0b20f05ab60a877511e37bd8c4f03a4.tar.gz | |
allow syntax highlighting to be enabled or disabled
Diffstat (limited to 'src/run')
| -rw-r--r-- | src/run/builtin.rs | 49 |
1 files changed, 38 insertions, 11 deletions
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(()) } } |
