commit c3950a8031d85b19ca2479ef357ec9f738994079
parent 13e360dd0c0f37714859619c395a47ce556c834d
Author: Sylvia Ivory <git@sivory.net>
Date: Fri, 20 Jun 2025 22:51:01 -0700
Allow selecting format at runtime
Diffstat:
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/src/editor.rs b/src/editor.rs
@@ -39,13 +39,20 @@ impl Editor {
match signal {
Ok(Signal::Success(line)) => {
+ if line.starts_with(".") {
+ if let Err(e) = self.eval_special(&line) {
+ eprintln!("{e}")
+ }
+
+ continue;
+ }
+
if let Err(e) = self.eval(&line) {
eprintln!("{e}")
}
}
// TODO; this should cancel the current Lua execution if possible
Ok(Signal::CtrlC) | Ok(Signal::CtrlD) => {
- println!("aborted");
break
},
_ => {}
@@ -53,6 +60,38 @@ impl Editor {
}
}
+ // .format <format> [true/false]
+ fn eval_special(&mut self, line: &str) -> LuaResult<()> {
+ let mut split = line
+ .strip_prefix(".")
+ .unwrap()
+ .split_whitespace();
+
+ let cmd = split.next();
+
+ match cmd {
+ Some("format") => {
+ match split.next() {
+ Some("inspect") => {
+ self.table_format = TableFormat::Inspect;
+ },
+ Some("address") => {
+ self.table_format = TableFormat::Address;
+ },
+ Some("comfytable") => {
+ let nested = split.next().unwrap_or("").parse::<bool>().unwrap_or_default();
+
+ self.table_format = TableFormat::ComfyTable(nested);
+ },
+ _ => println!("unknown subcommand")
+ }
+ },
+ _ => println!("unknown command")
+ }
+
+ Ok(())
+ }
+
fn eval(&mut self, line: &str) -> LuaResult<()> {
let value: LuaValue = self.lua.load(line).eval()?;