Skip to content

Commit cfdc711

Browse files
committed
Replace generic widget footers with compact distinct facts
1 parent 9a0b6ab commit cfdc711

10 files changed

Lines changed: 859 additions & 140 deletions

‎crates/jcode-tui/src/tui/info_widget.rs‎

Lines changed: 130 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(crate) use git::{edited_paths_from_tool_call, resolve_edited_path};
6262
pub use graph::{GraphEdge, GraphNode, build_graph_topology, graph_node_score};
6363
pub(crate) use memory_utils::is_traceworthy_memory_event;
6464
use memory_utils::{memory_active_summary, memory_last_trace_summary, memory_state_detail};
65-
use model::{render_model_info, render_model_widget, runtime_has_data, runtime_height};
65+
use model::{overview_runtime_height, render_model_info, render_model_widget, runtime_has_data};
6666
use swarm_background::{render_background_compact, render_background_widget, render_swarm_widget};
6767
use text::{truncate_smart, truncate_with_ellipsis};
6868
pub(crate) use tips::occasional_status_tip;
@@ -80,7 +80,7 @@ pub(super) fn changes_section_height(data: &InfoWidgetData) -> u16 {
8080

8181
/// Overview rows used by the Runtime section, mirroring [`render_sections`].
8282
pub(super) fn model_info_height(data: &InfoWidgetData) -> u16 {
83-
runtime_height(data)
83+
overview_runtime_height(data)
8484
}
8585

8686
/// Types of info widgets that can be displayed
@@ -120,28 +120,6 @@ pub enum WidgetKind {
120120
}
121121

122122
impl WidgetKind {
123-
/// A quiet description for widgets without a more specific footer (such
124-
/// as an overflow count, account hint, legend, or page indicator).
125-
fn footer_description(self) -> &'static str {
126-
match self {
127-
Self::Overview => "Session overview",
128-
Self::WorkspaceMap => "Workspace layout",
129-
Self::MemoryActivity => "Memory activity",
130-
Self::SwarmStatus => "Agent sessions",
131-
Self::BackgroundTasks => "Background work",
132-
Self::Compaction => "Context summary",
133-
Self::UsageLimits => "Provider limits",
134-
Self::KvCache => "Prompt caching",
135-
Self::ModelInfo => "Runtime details",
136-
Self::Diagrams => "Latest diagram",
137-
Self::AmbientMode => "Scheduled activity",
138-
Self::Tips => "Tips & shortcuts",
139-
Self::GitStatus => "Working tree",
140-
Self::CloudVm => "Remote machine",
141-
Self::Commits => "Recent history",
142-
}
143-
}
144-
145123
/// Priority for display (lower = higher priority)
146124
pub fn priority(self) -> u8 {
147125
match self {
@@ -1398,11 +1376,9 @@ fn render_single_widget(frame: &mut Frame, placement: &WidgetPlacement, data: &I
13981376

13991377
// Diagrams need special handling - render image instead of text
14001378
if placement.kind == WidgetKind::Diagrams {
1401-
let mut chrome = Framed::default().title(frame::label("◇ Diagram"));
1402-
if data.diagrams.len() > 1 {
1403-
chrome = chrome.title_right(frame::dim(format!("1/{}", data.diagrams.len())));
1404-
}
1405-
let chrome = chrome.footer_if_empty(frame::dim(placement.kind.footer_description()));
1379+
let chrome = Framed::default()
1380+
.title(frame::label("◇ Diagram"))
1381+
.footer(frame::dim(diagram_footer(data)));
14061382
frame.render_widget(chrome.apply(block, rect.width), rect);
14071383
render_diagrams_widget(frame, inner, data);
14081384
return;
@@ -1422,7 +1398,7 @@ fn render_single_widget(frame: &mut Frame, placement: &WidgetPlacement, data: &I
14221398
}
14231399
let chrome = Framed::default()
14241400
.title(frame::label("Workspace"))
1425-
.footer_if_empty(frame::dim(placement.kind.footer_description()));
1401+
.footer(frame::dim(workspace_footer(data)));
14261402
frame.render_widget(chrome.apply(block, rect.width), rect);
14271403
super::workspace_map_widget::render_workspace_map(
14281404
frame.buffer_mut(),
@@ -1441,6 +1417,67 @@ fn render_single_widget(frame: &mut Frame, placement: &WidgetPlacement, data: &I
14411417
frame.render_widget(Paragraph::new(framed.lines), inner);
14421418
}
14431419

1420+
fn diagram_footer(data: &InfoWidgetData) -> String {
1421+
let Some(diagram) = data.diagrams.first() else {
1422+
return "image pending".into();
1423+
};
1424+
let dimensions = format!("{}×{}", diagram.width, diagram.height);
1425+
if data.diagrams.len() > 1 {
1426+
format!("{dimensions} · 1/{}", data.diagrams.len())
1427+
} else {
1428+
dimensions
1429+
}
1430+
}
1431+
1432+
fn workspace_footer(data: &InfoWidgetData) -> String {
1433+
use super::workspace_map::WorkspaceSessionVisualState;
1434+
let (count, running) = data
1435+
.workspace_rows
1436+
.iter()
1437+
.flat_map(|row| &row.sessions)
1438+
.fold((0, 0), |(count, running), session| {
1439+
(
1440+
count + 1,
1441+
running + usize::from(session.state == WorkspaceSessionVisualState::Running),
1442+
)
1443+
});
1444+
let noun = if count == 1 { "session" } else { "sessions" };
1445+
if running > 0 {
1446+
format!("{count} {noun} · {running} running")
1447+
} else {
1448+
format!("{count} {noun}")
1449+
}
1450+
}
1451+
1452+
/// Token headroom complements the status line's context percentage rather
1453+
/// than relabeling the Overview or repeating one of its detail rows.
1454+
fn overview_footer(data: &InfoWidgetData) -> String {
1455+
if data.context_info_stale {
1456+
return "context syncing".into();
1457+
}
1458+
let used = data.observed_context_tokens.or_else(|| {
1459+
data.context_info
1460+
.as_ref()
1461+
.filter(|info| info.total_chars > 0)
1462+
.map(|info| info.estimated_tokens() as u64)
1463+
});
1464+
match (used, data.context_limit) {
1465+
(Some(used), Some(limit)) => {
1466+
let left = (limit as u64).saturating_sub(used);
1467+
let estimate = if data.observed_context_tokens.is_none() {
1468+
"~"
1469+
} else {
1470+
""
1471+
};
1472+
format!(
1473+
"{estimate}{} ctx left",
1474+
crate::kv_cache_monitor::format_token_count(left)
1475+
)
1476+
}
1477+
_ => "context not reported".into(),
1478+
}
1479+
}
1480+
14441481
/// Render mermaid diagrams widget (renders images, not text)
14451482
fn render_diagrams_widget(frame: &mut Frame, inner: Rect, data: &InfoWidgetData) {
14461483
if data.diagrams.is_empty() {
@@ -1545,7 +1582,7 @@ fn render_overview_framed(data: &InfoWidgetData, inner: Rect) -> Option<Framed>
15451582
}
15461583
framed = framed.footer_right(Line::from(dots));
15471584
}
1548-
Some(framed.footer_if_empty(frame::dim(WidgetKind::Overview.footer_description())))
1585+
Some(framed.footer_if_empty(frame::dim(overview_footer(data))))
15491586
}
15501587
#[cfg(test)]
15511588
#[derive(Debug, Clone)]
@@ -1726,6 +1763,7 @@ fn render_widget_content(kind: WidgetKind, data: &InfoWidgetData, inner: Rect) -
17261763
.collect(),
17271764
)
17281765
.title(frame::label("OpenAI limits"))
1766+
.footer(frame::dim("first snapshot"))
17291767
}
17301768
WidgetKind::UsageLimits => render_usage_widget(data, inner),
17311769
WidgetKind::KvCache => render_kv_cache_widget(data, inner),
@@ -1735,9 +1773,7 @@ fn render_widget_content(kind: WidgetKind, data: &InfoWidgetData, inner: Rect) -
17351773
WidgetKind::CloudVm => super::info_widget_cloud::render_cloud_widget(data, inner),
17361774
WidgetKind::Commits => render_commits_widget(data, inner),
17371775
};
1738-
framed
1739-
.settle()
1740-
.footer_if_empty(frame::dim(kind.footer_description()))
1776+
framed.settle()
17411777
}
17421778

17431779
fn render_compaction_widget(data: &InfoWidgetData, inner: Rect) -> Framed {
@@ -1757,9 +1793,18 @@ fn render_compaction_widget(data: &InfoWidgetData, inner: Rect) -> Framed {
17571793
let summary_tokens = (info.summary_chars / crate::compaction::CHARS_PER_TOKEN)
17581794
.max(usize::from(info.summary_chars > 0));
17591795
let detail = format!(
1760-
"{} old · {} active · ~{} summary tok",
1761-
info.compacted_messages, info.active_messages, summary_tokens
1796+
"{} old · {} active",
1797+
info.compacted_messages, info.active_messages
1798+
);
1799+
let summary = format!(
1800+
"~{} tok",
1801+
crate::kv_cache_monitor::format_token_count(summary_tokens as u64)
17621802
);
1803+
let footer = if info.mode.trim().is_empty() {
1804+
summary
1805+
} else {
1806+
format!("{summary} · {}", info.mode.trim())
1807+
};
17631808
Framed::body(vec![Line::from(Span::styled(
17641809
truncate_smart(&detail, inner.width as usize),
17651810
Style::default().fg(rgb(180, 180, 190)),
@@ -1768,7 +1813,7 @@ fn render_compaction_widget(data: &InfoWidgetData, inner: Rect) -> Framed {
17681813
frame::label("Compaction "),
17691814
Span::styled(status, Style::default().fg(title_color).bold()),
17701815
]))
1771-
.title_right(frame::dim(info.mode.to_string()))
1816+
.footer(frame::dim(footer))
17721817
}
17731818

17741819
fn render_kv_cache_widget(data: &InfoWidgetData, inner: Rect) -> Framed {
@@ -2007,6 +2052,14 @@ fn render_ambient_widget(data: &InfoWidgetData, inner: Rect) -> Framed {
20072052
let dim = rgb(100, 100, 110);
20082053
let label_color = rgb(140, 140, 150);
20092054
let max_w = inner.width.saturating_sub(2) as usize;
2055+
let next_due = if matches!(info.status, AmbientStatus::Disabled) && info.reminder_count > 0 {
2056+
info.next_reminder_wake.as_ref()
2057+
} else {
2058+
info.next_wake.as_ref()
2059+
};
2060+
let budget = info.budget_percent.filter(|pct| pct.is_finite());
2061+
let schedule_in_footer = budget.is_none();
2062+
let last_run_in_footer = schedule_in_footer && next_due.is_none();
20102063

20112064
// Status line with icon
20122065
let (icon, status_text, status_color) = match &info.status {
@@ -2077,30 +2130,41 @@ fn render_ambient_widget(data: &InfoWidgetData, inner: Rect) -> Framed {
20772130

20782131
// Last run
20792132
if let Some(ref ago) = info.last_run_ago {
2080-
let mut spans = vec![Span::styled(
2081-
format!("Ran {}", ago),
2082-
Style::default().fg(label_color),
2083-
)];
2133+
let mut spans = if last_run_in_footer {
2134+
Vec::new()
2135+
} else {
2136+
vec![Span::styled(
2137+
format!("Ran {}", ago),
2138+
Style::default().fg(label_color),
2139+
)]
2140+
};
20842141
if let Some(ref summary) = info.last_summary {
2085-
let remaining = max_w.saturating_sub(4 + ago.len());
2142+
let remaining = if last_run_in_footer {
2143+
max_w
2144+
} else {
2145+
max_w.saturating_sub(4 + ago.len())
2146+
};
20862147
if remaining > 5 {
20872148
spans.push(Span::styled(
2088-
truncate_smart(&format!(" - {}", summary), remaining),
2149+
truncate_smart(
2150+
&if last_run_in_footer {
2151+
summary.clone()
2152+
} else {
2153+
format!(" - {}", summary)
2154+
},
2155+
remaining,
2156+
),
20892157
Style::default().fg(dim),
20902158
));
20912159
}
20922160
}
2093-
lines.push(Line::from(spans));
2161+
if !spans.is_empty() {
2162+
lines.push(Line::from(spans));
2163+
}
20942164
}
20952165

20962166
// Next scheduled run
2097-
let next_due = if matches!(info.status, AmbientStatus::Disabled) && info.reminder_count > 0 {
2098-
info.next_reminder_wake.as_ref()
2099-
} else {
2100-
info.next_wake.as_ref()
2101-
};
2102-
2103-
if let Some(next) = next_due {
2167+
if let Some(next) = next_due.filter(|_| !schedule_in_footer) {
21042168
let prefix = if matches!(info.status, AmbientStatus::Disabled) && info.reminder_count > 0 {
21052169
"Next scheduled task"
21062170
} else {
@@ -2115,26 +2179,22 @@ fn render_ambient_widget(data: &InfoWidgetData, inner: Rect) -> Framed {
21152179
let mut framed = Framed::body(lines).title(title);
21162180

21172181
// Budget meter rides the bottom border.
2118-
if let Some(budget) = info.budget_percent {
2182+
if let Some(budget) = budget {
21192183
let pct = (budget * 100.0).round().clamp(0.0, 100.0) as u8;
2120-
let bar_width = inner.width.saturating_sub(16).clamp(4, 10) as usize;
2121-
let filled = ((budget * bar_width as f32).round() as usize).min(bar_width);
2122-
let empty = bar_width.saturating_sub(filled);
2123-
2124-
let bar_color = if pct < 20 {
2125-
rgb(255, 100, 100)
2126-
} else if pct <= 50 {
2127-
rgb(255, 200, 100)
2128-
} else {
2129-
rgb(100, 200, 100)
2130-
};
2131-
2132-
framed = framed.footer_right(Line::from(vec![
2133-
frame::dim("budget "),
2134-
Span::styled("▰".repeat(filled), Style::default().fg(bar_color)),
2135-
Span::styled("▱".repeat(empty), Style::default().fg(rgb(60, 60, 70))),
2136-
Span::styled(format!(" {}%", pct), Style::default().fg(bar_color)),
2137-
]));
2184+
framed = framed.footer_right(render_usage_limit_bar(
2185+
"budget",
2186+
100 - pct,
2187+
pct,
2188+
None,
2189+
inner.width,
2190+
false,
2191+
));
2192+
} else if let Some(next) = next_due {
2193+
framed = framed.footer(frame::dim(format!("next {next}")));
2194+
} else if let Some(ago) = &info.last_run_ago {
2195+
framed = framed.footer(frame::dim(format!("ran {ago}")));
2196+
} else {
2197+
framed = framed.footer(frame::dim("no run recorded"));
21382198
}
21392199

21402200
framed

‎crates/jcode-tui/src/tui/info_widget_cloud.rs‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,11 @@ pub(super) fn render_cloud_widget(data: &InfoWidgetData, inner: Rect) -> Framed
258258
let probe = info
259259
.probe_duration_ms
260260
.map(|v| format!("{v}ms"))
261-
.unwrap_or_else(|| "unavailable".into());
261+
.unwrap_or_else(|| "n/a".into());
262262
lines.push(fit(
263263
Line::from(vec![
264264
frame::dim("Updated "),
265265
Span::styled(age, value_style()),
266-
frame::dim(" · probe "),
267-
Span::styled(probe, value_style()),
268266
]),
269267
w,
270268
));
@@ -310,7 +308,9 @@ pub(super) fn render_cloud_widget(data: &InfoWidgetData, inner: Rect) -> Framed
310308
.unwrap_or_else(|| "unknown".into()),
311309
w,
312310
));
313-
Framed::body(lines).title(frame::label("Cloud VM"))
311+
Framed::body(lines)
312+
.title(frame::label("Cloud VM"))
313+
.footer(frame::dim(format!("probe {probe}")))
314314
}
315315

316316
#[cfg(test)]
@@ -362,6 +362,26 @@ mod tests {
362362
assert!(render_cloud_widget(&data, Rect::default()).is_empty());
363363
assert!(render_cloud_summary(&data, 60).is_empty());
364364
}
365+
366+
#[test]
367+
fn cloud_probe_timing_is_only_in_footer() {
368+
let mut data = fixture();
369+
let card = render_cloud_widget(&data, Rect::new(0, 0, 40, 20));
370+
assert_eq!(card.footer.unwrap().to_string(), "probe 120ms");
371+
assert!(
372+
card.lines
373+
.iter()
374+
.all(|line| !line.to_string().contains("probe"))
375+
);
376+
data.cloud_info.as_mut().unwrap().probe_duration_ms = None;
377+
assert_eq!(
378+
render_cloud_widget(&data, Rect::new(0, 0, 40, 20))
379+
.footer
380+
.unwrap()
381+
.to_string(),
382+
"probe n/a"
383+
);
384+
}
365385
#[test]
366386
fn cloud_populated_and_used_convention() {
367387
let mut data = fixture();

0 commit comments

Comments
 (0)