Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90b7aa9654 | ||
|
|
9ed3140bb9 | ||
|
|
caa60c65e8 | ||
|
|
9b935d2fab |
No files matched your search
@@ -26,7 +26,7 @@ offered; the default provider is the configured one, else the first logged in. T
|
||||
auto-compaction follow the active model's window (e.g. 1M for Claude 5.x).
|
||||
|
||||
Usage: once a response arrives, the footer shows subscription limits from the provider's headers:
|
||||
time windows with used % and time to reset (`5h 42% ↻2h13m · week 13%`) and, for credit billing, the
|
||||
time windows with used % and time to reset (`5h 42% 2h13m · week 13%`) and, for credit billing, the
|
||||
credit balance or extra-usage state. `/usage` shows the details.
|
||||
|
||||
Sessions: `/new` (or `/clear`) starts a new session file; the old one stays resumable. `/sessions` opens a
|
||||
|
||||
@@ -114,6 +114,8 @@ struct App {
|
||||
wide: bool,
|
||||
/// pending yes/no question from a tool
|
||||
ask: Option<(String, tokio::sync::oneshot::Sender<bool>)>,
|
||||
/// condensed lens state for the footer, refreshed by a timer
|
||||
lens: (String, bool),
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -224,6 +226,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
session_path: agent.session().path().to_path_buf(),
|
||||
wide: false,
|
||||
ask: None,
|
||||
lens: (String::new(), false),
|
||||
};
|
||||
sessions::history(&mut app.t, &agent.session().messages());
|
||||
if open_sessions {
|
||||
@@ -245,6 +248,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
let mut term = ratatui::init();
|
||||
let mut keys = EventStream::new();
|
||||
let mut tick = tokio::time::interval(std::time::Duration::from_millis(50));
|
||||
let mut lens_tick = tokio::time::interval(std::time::Duration::from_secs(2));
|
||||
let mut dirty = true;
|
||||
let mut last_title = String::new();
|
||||
while !app.quit {
|
||||
@@ -322,6 +326,15 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
_ = tick.tick(), if app.busy => dirty = true,
|
||||
_ = lens_tick.tick() => {
|
||||
// short timeout: the manager lock can be held while a server starts
|
||||
let to = std::time::Duration::from_millis(200);
|
||||
if let Ok(v) = tokio::time::timeout(to, lsp_status()).await {
|
||||
let s = status::lens_summary(&v);
|
||||
dirty |= s != app.lens;
|
||||
app.lens = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ratatui::restore();
|
||||
@@ -721,11 +734,12 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
|
||||
+ 2;
|
||||
let act_h = u16::from(app.busy);
|
||||
app.wide = f.area().width >= WIDE;
|
||||
let foot_h = status::rows_for(f.area().width, app.ask.is_some());
|
||||
let [main, act, input, status_row] = Layout::vertical([
|
||||
Constraint::Min(3),
|
||||
Constraint::Length(act_h),
|
||||
Constraint::Length(input_h),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(foot_h),
|
||||
])
|
||||
.areas(f.area());
|
||||
|
||||
@@ -786,9 +800,16 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
|
||||
queued: app.queue.len(),
|
||||
scroll: app.scroll,
|
||||
title: app.title.as_deref(),
|
||||
lens: &app.lens.0,
|
||||
lens_warn: app.lens.1,
|
||||
};
|
||||
f.render_widget(
|
||||
status::footer(&app.st, &chrome, status_row.width, status::now_secs()),
|
||||
Paragraph::new(status::rows(
|
||||
&app.st,
|
||||
&chrome,
|
||||
status_row.width,
|
||||
status::now_secs(),
|
||||
)),
|
||||
status_row,
|
||||
);
|
||||
if let Some(popup::Popup { comp, sel }) = &app.popup {
|
||||
@@ -954,6 +975,7 @@ mod tests {
|
||||
session_path: "/nonexistent/s.jsonl".into(),
|
||||
wide: false,
|
||||
ask: None,
|
||||
lens: (String::new(), false),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1010,11 +1032,16 @@ mod tests {
|
||||
let mut term = ratatui::Terminal::new(TestBackend::new(100, 10)).unwrap();
|
||||
term.draw(|f| draw(f, &mut app)).unwrap();
|
||||
let buf = term.backend().buffer().clone();
|
||||
let last: String = (0..100).map(|x| buf[(x, 9)].symbol().to_string()).collect();
|
||||
let row = |y| -> String { (0..100).map(|x| buf[(x, y)].symbol().to_string()).collect() };
|
||||
let (last, lens) = (row(8), row(9));
|
||||
assert!(
|
||||
last.starts_with("ctx ▱▱▱▱▱▱▱▱▱▱ 0k/150k · 0↑ 0↓") && last.ends_with("no match"),
|
||||
"{last}"
|
||||
);
|
||||
assert!(
|
||||
lens.starts_with("lens: starting") && lens.ends_with("Claude · m1"),
|
||||
"{lens}"
|
||||
);
|
||||
app.hint.clear();
|
||||
let mut foot = |app: &mut App| {
|
||||
term.draw(|f| draw(f, app)).unwrap();
|
||||
@@ -1027,7 +1054,7 @@ mod tests {
|
||||
app.title = Some("fix the flaky rust-analyzer test".into());
|
||||
let last = foot(&mut app);
|
||||
assert!(
|
||||
last.starts_with("ctx ▱")
|
||||
last.starts_with("lens: ")
|
||||
&& last.ends_with("fix the flaky rust-analyzer test · Claude · m1"),
|
||||
"{last}"
|
||||
);
|
||||
|
||||
+159
-15
@@ -34,15 +34,101 @@ pub struct Chrome<'a> {
|
||||
pub scroll: u16,
|
||||
/// None until the first prompt
|
||||
pub title: Option<&'a str>,
|
||||
/// `lsp 2/2 · lint 4`; empty until the first poll
|
||||
pub lens: &'a str,
|
||||
/// a server is dead/breaker-open or a runner binary is missing
|
||||
pub lens_warn: bool,
|
||||
}
|
||||
|
||||
/// `ctx ▰▰▰▱▱▱▱▱▱▱ 41k/150k · 12.3k↑ 2.1k↓ ~$0.08` left, `Claude · model · 1 queued` right.
|
||||
/// Hints replace the right side; a pending y/n question takes the whole line.
|
||||
pub fn footer(st: &Status, c: &Chrome, width: u16, now: u64) -> Line<'static> {
|
||||
let th = theme::t();
|
||||
if let Some(q) = c.ask {
|
||||
return Line::styled(format!("[y/n] {q}"), th.warn().add_modifier(Modifier::BOLD));
|
||||
/// Terminals at least this wide get a second footer row.
|
||||
pub const TWO_ROWS: u16 = 100;
|
||||
|
||||
/// Footer height for this width (the ask line always takes one row).
|
||||
pub fn rows_for(width: u16, ask: bool) -> u16 {
|
||||
if width >= TWO_ROWS && !ask { 2 } else { 1 }
|
||||
}
|
||||
|
||||
/// Condense `/lsp` lines into `lsp 2/3 · lint 4 · 1 marked`; bool = something needs attention.
|
||||
pub fn lens_summary(lines: &[String]) -> (String, bool) {
|
||||
let (mut up, mut total, mut marked, mut notes, mut lint) = (0, 0, 0, 0, 0);
|
||||
for l in lines {
|
||||
if let Some(r) = l.strip_prefix("runners: ") {
|
||||
lint = r.split(", ").filter(|x| !x.is_empty()).count();
|
||||
} else if l.starts_with("marked ") {
|
||||
marked += 1;
|
||||
} else if l.contains(" @ ") {
|
||||
total += 1;
|
||||
up += usize::from(l.contains(": running"));
|
||||
} else {
|
||||
notes += 1;
|
||||
}
|
||||
}
|
||||
let mut v = vec![];
|
||||
if total > 0 {
|
||||
v.push(format!("lsp {up}/{total}"));
|
||||
}
|
||||
if lint > 0 {
|
||||
v.push(format!("lint {lint}"));
|
||||
}
|
||||
if marked > 0 {
|
||||
v.push(format!("{marked} marked"));
|
||||
}
|
||||
if notes > 0 {
|
||||
v.push(format!("{notes} missing"));
|
||||
}
|
||||
(v.join(" · "), up < total || notes > 0)
|
||||
}
|
||||
|
||||
/// Footer lines: two rows on wide terminals (usage on top; lens left, session tail right),
|
||||
/// else the single packed line from [`footer`]. A hint only replaces the top row's right side.
|
||||
pub fn rows(st: &Status, c: &Chrome, width: u16, now: u64) -> Vec<Line<'static>> {
|
||||
if rows_for(width, c.ask.is_some()) == 1 {
|
||||
return vec![footer(st, c, width, now)];
|
||||
}
|
||||
let th = theme::t();
|
||||
let w = width as usize;
|
||||
let lw = |l: &[Span]| l.iter().map(Span::width).sum::<usize>();
|
||||
let mut top = left_spans(st, now);
|
||||
if !c.hint.is_empty() {
|
||||
let r = Span::styled(c.hint.to_string(), th.accent());
|
||||
top.push(Span::raw(
|
||||
" ".repeat(w.saturating_sub(lw(&top) + r.width()).max(1)),
|
||||
));
|
||||
top.push(r);
|
||||
}
|
||||
let lens = if c.lens.is_empty() {
|
||||
"lens: starting"
|
||||
} else {
|
||||
c.lens
|
||||
};
|
||||
let mut bot = vec![Span::styled(
|
||||
lens.to_string(),
|
||||
if c.lens_warn { th.warn() } else { th.dim() },
|
||||
)];
|
||||
let tail = tail(st, c).join(" · ");
|
||||
let room = w.saturating_sub(lw(&bot) + tail.chars().count() + 4);
|
||||
let title = c.title.unwrap_or("new session");
|
||||
let right = if room >= 12 {
|
||||
let t: String = if title.chars().count() > room.min(40) {
|
||||
title.chars().take(room.min(40) - 1).chain(['…']).collect()
|
||||
} else {
|
||||
title.into()
|
||||
};
|
||||
format!("{t} · {tail}")
|
||||
} else {
|
||||
tail
|
||||
};
|
||||
let r = Span::styled(right, th.dim());
|
||||
bot.push(Span::raw(
|
||||
" ".repeat(w.saturating_sub(lw(&bot) + r.width()).max(1)),
|
||||
));
|
||||
bot.push(r);
|
||||
vec![Line::from(top), Line::from(bot)]
|
||||
}
|
||||
|
||||
/// Context bar, quota windows, token counts and cost estimate.
|
||||
fn left_spans(st: &Status, now: u64) -> Vec<Span<'static>> {
|
||||
let th = theme::t();
|
||||
let k = |n: u64| {
|
||||
if n >= 1000 {
|
||||
format!("{:.1}k", n as f64 / 1000.0)
|
||||
@@ -84,6 +170,17 @@ pub fn footer(st: &Status, c: &Chrome, width: u16, now: u64) -> Line<'static> {
|
||||
),
|
||||
th.dim(),
|
||||
)]);
|
||||
left
|
||||
}
|
||||
|
||||
/// `ctx ▰▰▰▱▱▱▱▱▱▱ 41k/150k · 12.3k↑ 2.1k↓ ~$0.08` left, `Claude · model · 1 queued` right.
|
||||
/// Hints replace the right side; a pending y/n question takes the whole line.
|
||||
pub fn footer(st: &Status, c: &Chrome, width: u16, now: u64) -> Line<'static> {
|
||||
let th = theme::t();
|
||||
if let Some(q) = c.ask {
|
||||
return Line::styled(format!("[y/n] {q}"), th.warn().add_modifier(Modifier::BOLD));
|
||||
}
|
||||
let mut left = left_spans(st, now);
|
||||
let w = width as usize;
|
||||
let lw = |l: &[Span]| l.iter().map(Span::width).sum::<usize>();
|
||||
if !c.hint.is_empty() {
|
||||
@@ -96,13 +193,7 @@ pub fn footer(st: &Status, c: &Chrome, width: u16, now: u64) -> Line<'static> {
|
||||
left.push(right);
|
||||
return Line::from(left);
|
||||
}
|
||||
let mut tail = vec![format!("{:?}", st.kind), st.model.clone()];
|
||||
if c.queued > 0 {
|
||||
tail.push(format!("{} queued", c.queued));
|
||||
}
|
||||
if c.scroll > 0 {
|
||||
tail.push(format!("↑{}", c.scroll));
|
||||
}
|
||||
let tail = tail(st, c);
|
||||
let title = c.title.unwrap_or("new session");
|
||||
// drop in order until it fits: token counts, title, context bar
|
||||
let mut title_room = w.saturating_sub(lw(&left) + tail.join(" · ").chars().count() + 4);
|
||||
@@ -133,6 +224,17 @@ pub fn footer(st: &Status, c: &Chrome, width: u16, now: u64) -> Line<'static> {
|
||||
Line::from(left)
|
||||
}
|
||||
|
||||
fn tail(st: &Status, c: &Chrome) -> Vec<String> {
|
||||
let mut t = vec![format!("{:?}", st.kind), st.model.clone()];
|
||||
if c.queued > 0 {
|
||||
t.push(format!("{} queued", c.queued));
|
||||
}
|
||||
if c.scroll > 0 {
|
||||
t.push(format!("↑{}", c.scroll));
|
||||
}
|
||||
t
|
||||
}
|
||||
|
||||
pub fn now_secs() -> u64 {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
@@ -150,7 +252,7 @@ fn until(at: u64, now: u64) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// ` · 5h 42% ↻2h13m · week 13%`, then credits; warn at 70%, error at 90%.
|
||||
/// ` · 5h 42% 2h13m · week 13%`, then credits; warn at 70%, error at 90%.
|
||||
fn quota_spans(q: &hx_ai::Quota, now: u64) -> Vec<Span<'static>> {
|
||||
let th = theme::t();
|
||||
let mut v = vec![];
|
||||
@@ -257,7 +359,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|s| s.content.to_string())
|
||||
.collect();
|
||||
assert_eq!(t, " · 5h 42% ↻2h13m · week 91% ↻3d4h · credits: 37.5");
|
||||
assert_eq!(t, " · 5h 42% 2h13m · week 91% 3d4h · credits: 37.5");
|
||||
assert_eq!(
|
||||
quota_spans(&q, 10_000)[3].style.fg,
|
||||
Some(ratatui::style::Color::Red)
|
||||
@@ -333,6 +435,48 @@ mod tests {
|
||||
assert!(!l.contains("fix the parser") && l.contains("m1"), "{l}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lens_summary_counts() {
|
||||
let v: Vec<String> = [
|
||||
"rust-analyzer @ /w: running, 2 open",
|
||||
"pyright @ /w: dead",
|
||||
"marked Ignore: k (r)",
|
||||
"runners: clippy, ruff, shellcheck",
|
||||
"ruff not installed",
|
||||
]
|
||||
.map(String::from)
|
||||
.into();
|
||||
assert_eq!(
|
||||
lens_summary(&v),
|
||||
("lsp 1/2 · lint 3 · 1 marked · 1 missing".into(), true)
|
||||
);
|
||||
assert_eq!(lens_summary(&[]), (String::new(), false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wide_has_two_rows_and_hint_keeps_usage() {
|
||||
let mut c = Chrome {
|
||||
lens: "lsp 2/2 · lint 4",
|
||||
hint: "saved",
|
||||
title: Some("fix"),
|
||||
..Default::default()
|
||||
};
|
||||
let r = rows(&st(), &c, 120, 0);
|
||||
let (a, b) = (text(r[0].clone()), text(r[1].clone()));
|
||||
assert!(
|
||||
a.starts_with("ctx ") && a.contains("0↑ 0↓") && a.ends_with("saved"),
|
||||
"{a}"
|
||||
);
|
||||
assert!(
|
||||
b.starts_with("lsp 2/2") && b.ends_with("fix · Claude · m1"),
|
||||
"{b}"
|
||||
);
|
||||
assert_eq!(b.chars().count(), 120);
|
||||
assert_eq!(rows(&st(), &c, 80, 0).len(), 1);
|
||||
c.ask = Some("rm?");
|
||||
assert_eq!(rows(&st(), &c, 120, 0).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_bar_fill_and_color() {
|
||||
let mut s = st();
|
||||
|
||||
@@ -32,7 +32,7 @@ const UNICODE: Sym = Sym {
|
||||
info: "·",
|
||||
ellipsis: "…",
|
||||
minus: "−",
|
||||
reset: "↻",
|
||||
reset: "\u{f017} ",
|
||||
};
|
||||
|
||||
const ASCII: Sym = Sym {
|
||||
@@ -48,7 +48,7 @@ const ASCII: Sym = Sym {
|
||||
info: "-",
|
||||
ellipsis: "...",
|
||||
minus: "-",
|
||||
reset: "@",
|
||||
reset: "in ",
|
||||
};
|
||||
|
||||
pub struct Theme {
|
||||
|
||||
Reference in new issue
Block a user