diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-05-23 14:48:51 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-05-23 14:48:51 +0200 |
| commit | e4c0fc7beab2a6dd53210263a857f2b3ec29b604 (patch) | |
| tree | 47137f101e5caaa93273cb03eeea92e0616537ca /src/run | |
| parent | ba9414b17a107bdb30fe462aa2d42f6e91b3ad74 (diff) | |
| download | pish-e4c0fc7beab2a6dd53210263a857f2b3ec29b604.tar.gz | |
customizable syntax highlighting
Diffstat (limited to 'src/run')
| -rw-r--r-- | src/run/builtin.rs | 40 | ||||
| -rw-r--r-- | src/run/mod.rs | 10 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/run/builtin.rs b/src/run/builtin.rs index c946472..2255997 100644 --- a/src/run/builtin.rs +++ b/src/run/builtin.rs @@ -967,6 +967,46 @@ impl Builtin for export { } } +#[derive(Copy, Clone)] +pub struct pish_theme; + +impl Builtin for pish_theme { + fn name(&self) -> &str { + "pish_theme" + } + + fn io( + &self, + session: Arc<Mutex<Session>>, + args: &[BString], + _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: ")?; + 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)); + } + + 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)) + } + }, + } + } +} + #[cfg(debug_assertions)] mod dbg { use super::*; diff --git a/src/run/mod.rs b/src/run/mod.rs index f34b678..842a918 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -451,7 +451,14 @@ impl Executor { stdin: InputReader, stdout: OutputWriter, ) -> SpawnedCmd { - self.execute_block(parse::Block { commands: s.stmts, finished_parsing: true }, stdin, stdout) + self.execute_block( + parse::Block { + commands: s.stmts, + finished_parsing: true, + }, + stdin, + stdout, + ) } } @@ -711,6 +718,7 @@ const BUILTINS: &[&'static dyn BuiltinClone] = &[ &builtin::Here, &builtin::logo, &builtin::export, + &builtin::pish_theme, ]; pub fn builtin_map() -> HashMap<BString, &'static dyn BuiltinClone> { |
