Skip to content

Commit e423feb

Browse files
authored
feat(cli-rs): quiet the session footer and add side panel bars behind an experiment (#68500)
1 parent 099198d commit e423feb

21 files changed

Lines changed: 1347 additions & 107 deletions

File tree

‎packages/cli-rs/crates/local/src/cli_config.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ section!(Session {
226226
markdown: Markdown,
227227
new_location: NewLocation,
228228
permissions: Permissions,
229+
footer_cost: bool,
229230
});
230231
section!(Tabs { mode: TabsMode, enabled: bool, scope: TabsScope, layout: TabsLayout, indicators: TabsIndicators });
231232
section!(Mini {

‎packages/cli-rs/crates/plugin-abi/src/lib.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,8 +2801,11 @@ pub trait Read {
28012801
Vec::new()
28022802
}
28032803
/// The user's setting `name`, one of the host's named settings ([`SETTINGS`]), as the TUI config (`tui.json`)
2804-
/// holds it; `None` when it holds none, and for a name the host does not name. A change of it is a change of the
2805-
/// host's own state ([`Changed::local`]).
2804+
/// holds it; `None` when it holds none, and for a name the host does not name. The host also answers
2805+
/// `experimental.<id>` with whether its experiment `id` is on, for each experiment it lists, and
2806+
/// `session.footer_cost` with whether the user's setting shows the session's cost in the prompt footer. These are
2807+
/// read-only: [`Host::set_setting`] still refuses them. A change of any of them is a change of the host's own
2808+
/// state ([`Changed::local`]).
28062809
fn setting(&self, _name: &str) -> Option<serde_json::Value> {
28072810
None
28082811
}

‎packages/cli-rs/crates/tui/src/dialogs/experiments.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ pub const EXPERIMENTS: &[Experiment] = &[
3434
title: "Model picker: older versions",
3535
description: "Collapse older model versions in the model picker; needs Model picker on too",
3636
},
37+
Experiment { id: "quiet-chrome", title: "Quiet chrome", description: "Show less around the prompt" },
38+
Experiment {
39+
id: "drawer-slide",
40+
title: "Sliding drawers",
41+
description: "Slide floating side panels in from their edge (with Quiet chrome)",
42+
},
3743
];
3844

3945
fn options(tui: &Tui) -> Vec<SelectOption<&'static str>> {

‎packages/cli-rs/crates/tui/src/dialogs/settings.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ pub const SETTINGS: &[Setting] = &[
230230
true,
231231
&["tokens per second", "throughput"],
232232
),
233+
toggle(
234+
"Session cost",
235+
"Session",
236+
&["session", "footer_cost"],
237+
"Whether the session's cost is shown in the footer (Quiet chrome)",
238+
false,
239+
&["spend", "cost", "price", "footer", "money"],
240+
),
233241
choice(
234242
"New session location",
235243
"Session",

‎packages/cli-rs/crates/tui/src/frame/layout.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pub const SESSION_SIDEBAR_WIDTH: u16 = 42;
44
pub const SESSION_TABS_COMPACT_WIDTH: i64 = 5;
55
pub const SESSION_TABS_COMPACT_BREAKPOINT: u16 = 12;
66
pub const SESSION_SIDEBAR_MAX_WIDTH: i64 = 72;
7+
/// The narrowest the docked sidebar's sections still read at.
8+
pub const SESSION_SIDEBAR_MIN_WIDTH: i64 = 36;
79
const SESSION_CONTENT_MIN_WIDTH: i64 = 44;
810
const SESSION_CONTENT_PREFERRED_WIDTH: i64 = 64;
911
/// A docked panel fits when the session keeps its preferred width beside a minimum-width pane.
@@ -16,6 +18,13 @@ pub fn clamp_tabs_width(width: i64, total: i64) -> u16 {
1618
as u16
1719
}
1820

21+
/// The sidebar's width beside `room` columns of session: as wide as leaves the session its preferred width, and never
22+
/// narrower than its sections read at.
23+
pub fn clamp_sidebar_width(width: i64, room: i64) -> u16 {
24+
SESSION_SIDEBAR_MIN_WIDTH.max(width.min(SESSION_SIDEBAR_MAX_WIDTH).min(room - SESSION_CONTENT_PREFERRED_WIDTH))
25+
as u16
26+
}
27+
1928
pub fn clamp_pane_width(width: i64, total: i64) -> u16 {
2029
let half = (total / 2).max(1);
2130
24.min(half).max(width.min(half.max(total - SESSION_CONTENT_MIN_WIDTH))).max(0) as u16
@@ -41,4 +50,21 @@ mod tests {
4150
}
4251
}
4352
}
53+
54+
#[test]
55+
fn the_sidebar_stays_between_its_bounds_and_leaves_the_session_its_preferred_width() {
56+
let (min, max) = (SESSION_SIDEBAR_MIN_WIDTH, SESSION_SIDEBAR_MAX_WIDTH);
57+
for room in 20..=300 {
58+
for saved in 0..=120 {
59+
let shown = i64::from(clamp_sidebar_width(saved, room));
60+
assert!((min..=max).contains(&shown), "{saved} in {room}: {shown}");
61+
if room >= min + SESSION_CONTENT_PREFERRED_WIDTH {
62+
assert!(room - shown >= SESSION_CONTENT_PREFERRED_WIDTH, "{saved} in {room}: {shown}");
63+
}
64+
if (min..=max).contains(&saved) && room - saved >= SESSION_CONTENT_PREFERRED_WIDTH {
65+
assert_eq!(shown, saved, "{saved} in {room}");
66+
}
67+
}
68+
}
69+
}
4470
}

0 commit comments

Comments
 (0)