lean_ctx/shell/
interactive.rs1use std::io::{self, BufRead, Write};
2
3use crate::core::stats;
4
5pub fn interactive() {
6 let real_shell = super::platform::detect_shell();
7
8 eprintln!(
9 "lean-ctx shell v{} (wrapping {real_shell})",
10 env!("CARGO_PKG_VERSION")
11 );
12 eprintln!("All command output is automatically compressed.");
13 eprintln!("Type 'exit' to quit.\n");
14
15 let stdin = io::stdin();
16 let mut stdout = io::stdout();
17
18 loop {
19 let _ = write!(stdout, "lean-ctx> ");
20 let _ = stdout.flush();
21
22 let mut line = String::new();
23 match stdin.lock().read_line(&mut line) {
24 Ok(0) | Err(_) => break,
25 Ok(_) => {}
26 }
27
28 let cmd = line.trim();
29 if cmd.is_empty() {
30 continue;
31 }
32 if cmd == "exit" || cmd == "quit" {
33 break;
34 }
35 if cmd == "gain" {
36 println!("{}", stats::format_gain());
37 continue;
38 }
39
40 let exit_code = super::exec::exec(cmd);
41
42 if exit_code != 0 {
43 let _ = writeln!(stdout, "[exit: {exit_code}]");
44 }
45 }
46}