Merge pull request 'TUI redesign: Catppuccin Mocha + new layout' (#144) from feat/tui-design into main

This commit was merged in pull request #144.
This commit is contained in:
hermes committed 2026-10-09 19:22:48 +00:00
commit 255819cbbc
12 files changed
+1132 -470

No files matched your search

+45 -3
View File
@@ -314,6 +314,9 @@ impl Tool for AskUser {
}
}
/// Bytes of running bash output kept for the live view.
const LIVE_TAIL: usize = 2048;
pub struct Bash;
#[async_trait]
impl Tool for Bash {
@@ -340,14 +343,37 @@ impl Tool for Bash {
// own process group so timeouts kill children too
#[cfg(unix)]
c.process_group(0);
let child = match c.spawn() {
let mut child = match c.spawn() {
Ok(c) => c,
Err(e) => return ToolResult::err(format!("spawn: {e}")),
};
let pid = child.id();
let res = tokio::time::timeout(Duration::from_secs(secs), child.wait_with_output()).await;
// read output as it comes so the UI can show the last lines live (state.live)
let mut so = child.stdout.take().expect("piped");
let live = &cx.state.live;
let run = async {
use tokio::io::AsyncReadExt;
let mut out = vec![];
let mut chunk = [0u8; 8192];
loop {
match so.read(&mut chunk).await {
Ok(0) | Err(_) => break,
Ok(n) => {
out.extend_from_slice(&chunk[..n]);
let start = out.len().saturating_sub(LIVE_TAIL);
live.lock().unwrap_or_else(|e| e.into_inner()).insert(
cmd.to_string(),
String::from_utf8_lossy(&out[start..]).into(),
);
}
}
}
child.wait().await.map(|st| (out, st))
};
let res = tokio::time::timeout(Duration::from_secs(secs), run).await;
live.lock().unwrap_or_else(|e| e.into_inner()).remove(cmd);
let (out, code) = match res {
Ok(Ok(o)) => (o.stdout, o.status.code()),
Ok(Ok((o, st))) => (o, st.code()),
Ok(Err(e)) => return ToolResult::err(format!("wait: {e}")),
Err(_) => {
#[cfg(unix)]
@@ -451,6 +477,22 @@ mod tests {
use super::*;
use std::time::Instant;
#[tokio::test]
async fn bash_streams_live_tail() {
let d = tempfile::tempdir().unwrap();
let c = cx(d.path());
let cmd = "echo one; sleep 0.4; echo two";
let st = c.state.clone();
let peek = tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(200)).await;
st.live.lock().unwrap().get(cmd).cloned()
});
let r = Bash.call(json!({"command": cmd}), &c).await;
assert_eq!(peek.await.unwrap().as_deref(), Some("one\n"));
assert_eq!(r.content, "one\ntwo\n");
assert!(c.state.live.lock().unwrap().is_empty(), "cleared when done");
}
fn cx(d: &Path) -> ToolCtx {
ToolCtx {
cwd: d.into(),