mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Share picker setup for the TUI status line and terminal title (#62126)
## Why The status line and terminal title pickers duplicated the logic for ordering configured items and displaying live rate-limit labels. ## What changed Build both pickers' item lists with the same helper. Keep configured items in order, skip unknown IDs, and collapse aliases to one row per canonical ID. Use live rate-limit names and descriptions when available. Use the shared multi-select picker directly for terminal title setup and opt it in to accepting input while disconnected. ## Testing Cover alias deduplication and configured order, and assert that the title picker accepts input while disconnected while the shared picker defaults to disabling it. GitOrigin-RevId: 48971f003bd73523599d1d1ad677d855844767db
This commit is contained in:
committed by
copyberry
parent
9c60cb0a27
commit
7d7af7b903
@@ -213,9 +213,9 @@ pub(crate) use status_line_setup::StatuslineProviderActions;
|
||||
pub(crate) use status_surface_preview::StatusSurfacePreviewData;
|
||||
pub(crate) use status_surface_preview::StatusSurfacePreviewItem;
|
||||
pub(crate) use title_setup::TerminalTitleItem;
|
||||
pub(crate) use title_setup::TerminalTitleSetupView;
|
||||
#[cfg(test)]
|
||||
pub(crate) use title_setup::preview_line_for_title_items;
|
||||
pub(crate) use title_setup::terminal_title_setup;
|
||||
mod paste_burst;
|
||||
mod pending_input_preview;
|
||||
mod pending_thread_approvals;
|
||||
|
||||
@@ -202,6 +202,7 @@ pub(crate) struct MultiSelectPicker {
|
||||
/// Whether left/right arrow reordering is enabled.
|
||||
ordering_enabled: bool,
|
||||
require_selection: bool,
|
||||
accepts_input_when_disconnected: bool,
|
||||
|
||||
/// Shared list keybindings for navigation and completion.
|
||||
keymap: ListKeymap,
|
||||
@@ -529,6 +530,10 @@ impl BottomPaneView for MultiSelectPicker {
|
||||
self.complete
|
||||
}
|
||||
|
||||
fn accepts_input_when_disconnected(&self) -> bool {
|
||||
self.accepts_input_when_disconnected
|
||||
}
|
||||
|
||||
fn on_ctrl_c(&mut self) -> CancellationEvent {
|
||||
self.close();
|
||||
CancellationEvent::Handled
|
||||
@@ -702,6 +707,7 @@ pub(crate) struct MultiSelectPickerBuilder {
|
||||
items: Vec<MultiSelectItem>,
|
||||
ordering_enabled: bool,
|
||||
require_selection: bool,
|
||||
accepts_input_when_disconnected: bool,
|
||||
app_event_tx: AppEventSender,
|
||||
keymap: ListKeymap,
|
||||
preview_builder: Option<PreviewCallback>,
|
||||
@@ -720,6 +726,7 @@ impl MultiSelectPickerBuilder {
|
||||
items: Vec::new(),
|
||||
ordering_enabled: false,
|
||||
require_selection: false,
|
||||
accepts_input_when_disconnected: false,
|
||||
app_event_tx,
|
||||
keymap: RuntimeKeymap::defaults().list,
|
||||
preview_builder: None,
|
||||
@@ -743,6 +750,11 @@ impl MultiSelectPickerBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn allow_input_when_disconnected(mut self) -> Self {
|
||||
self.accepts_input_when_disconnected = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the shared list keymap used for navigation and completion.
|
||||
pub fn list_keymap(mut self, keymap: ListKeymap) -> Self {
|
||||
self.keymap = keymap;
|
||||
@@ -855,6 +867,7 @@ impl MultiSelectPickerBuilder {
|
||||
action_footer_hint: super::popup_consts::picker_hint_line_for_keymap(&self.keymap),
|
||||
ordering_enabled: self.ordering_enabled,
|
||||
require_selection: self.require_selection,
|
||||
accepts_input_when_disconnected: self.accepts_input_when_disconnected,
|
||||
keymap: self.keymap,
|
||||
search_query: String::new(),
|
||||
filtered_indices: Vec::new(),
|
||||
@@ -903,12 +916,33 @@ pub(crate) fn match_item(
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(super) mod tests {
|
||||
use super::*;
|
||||
use crate::app_event::AppEvent;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
pub(in crate::bottom_pane) fn render_lines(view: &impl Renderable, width: u16) -> String {
|
||||
let area = Rect::new(0, 0, width, view.desired_height(width));
|
||||
let mut buf = Buffer::empty(area);
|
||||
view.render(area, &mut buf);
|
||||
(0..area.height)
|
||||
.map(|row| {
|
||||
let mut line = String::new();
|
||||
for col in 0..area.width {
|
||||
let symbol = buf[(area.x + col, area.y + row)].symbol();
|
||||
if symbol.is_empty() {
|
||||
line.push(' ');
|
||||
} else {
|
||||
line.push_str(symbol);
|
||||
}
|
||||
}
|
||||
line
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn test_picker(items: Vec<MultiSelectItem>) -> MultiSelectPicker {
|
||||
let (tx, _rx) = unbounded_channel::<AppEvent>();
|
||||
MultiSelectPicker::builder(
|
||||
@@ -946,6 +980,7 @@ mod tests {
|
||||
"branch", /*orderable*/ true, /*section_break_after*/ false,
|
||||
),
|
||||
]);
|
||||
assert!(!picker.accepts_input_when_disconnected());
|
||||
|
||||
picker.move_selected_item(Direction::Down);
|
||||
assert_eq!(
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use std::collections::HashSet;
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::Display;
|
||||
use strum_macros::EnumIter;
|
||||
use strum_macros::EnumString;
|
||||
@@ -326,7 +324,6 @@ impl StatusLineSetupView {
|
||||
app_event_tx: AppEventSender,
|
||||
list_keymap: ListKeymap,
|
||||
) -> Self {
|
||||
let mut used_ids = HashSet::new();
|
||||
let mut items = Vec::new();
|
||||
if !matches!(providers, StatuslineProviderActions::Hidden) {
|
||||
items.push(MultiSelectItem {
|
||||
@@ -364,34 +361,11 @@ impl StatusLineSetupView {
|
||||
on_activate: None,
|
||||
});
|
||||
|
||||
if let Some(selected_items) = status_line_items.as_ref() {
|
||||
for id in *selected_items {
|
||||
let Ok(item) = id.parse::<StatusLineItem>() else {
|
||||
continue;
|
||||
};
|
||||
let item_id = item.to_string();
|
||||
if !used_ids.insert(item_id.clone()) {
|
||||
continue;
|
||||
}
|
||||
items.push(Self::status_line_select_item(
|
||||
item,
|
||||
/*enabled*/ true,
|
||||
&preview_data,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
for item in StatusLineItem::iter() {
|
||||
let item_id = item.to_string();
|
||||
if used_ids.contains(&item_id) {
|
||||
continue;
|
||||
}
|
||||
items.push(Self::status_line_select_item(
|
||||
item,
|
||||
/*enabled*/ false,
|
||||
&preview_data,
|
||||
));
|
||||
}
|
||||
items.extend(preview_data.picker_items(
|
||||
status_line_items,
|
||||
StatusLineItem::description,
|
||||
|item| Some(item.preview_item()),
|
||||
));
|
||||
|
||||
Self {
|
||||
picker: MultiSelectPicker::builder(
|
||||
@@ -435,33 +409,6 @@ impl StatusLineSetupView {
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a [`StatusLineItem`] into a [`MultiSelectItem`] for the picker.
|
||||
fn status_line_select_item(
|
||||
item: StatusLineItem,
|
||||
enabled: bool,
|
||||
preview_data: &StatusSurfacePreviewData,
|
||||
) -> MultiSelectItem {
|
||||
let default_name = item.to_string();
|
||||
let default_description = item.description();
|
||||
let (name, description) = match item {
|
||||
StatusLineItem::FiveHourLimit | StatusLineItem::WeeklyLimit => (
|
||||
preview_data.rate_limit_item_name(item.preview_item(), &default_name),
|
||||
preview_data.rate_limit_item_description(item.preview_item(), default_description),
|
||||
),
|
||||
_ => (default_name, default_description.to_string()),
|
||||
};
|
||||
|
||||
MultiSelectItem {
|
||||
id: item.to_string(),
|
||||
name,
|
||||
description: Some(description),
|
||||
enabled,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BottomPaneView for StatusLineSetupView {
|
||||
@@ -514,15 +461,34 @@ impl Renderable for StatusLineSetupView {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use crate::bottom_pane::multi_select_picker::tests::render_lines;
|
||||
use crate::terminal_hyperlinks::HyperlinkLine;
|
||||
use insta::assert_snapshot;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
use crate::app_event::AppEvent;
|
||||
|
||||
#[test]
|
||||
fn configured_aliases_keep_their_first_position() {
|
||||
let configured = ["project", "model-name", "project-name", "invalid"].map(str::to_string);
|
||||
let rows = StatusSurfacePreviewData::default().picker_items(
|
||||
Some(&configured),
|
||||
StatusLineItem::description,
|
||||
|item| Some(item.preview_item()),
|
||||
);
|
||||
let enabled = rows
|
||||
.iter()
|
||||
.filter(|row| row.enabled)
|
||||
.map(|row| row.id.as_str())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(enabled, ["project-name", "model"]);
|
||||
assert_eq!(
|
||||
rows.iter().filter(|row| row.id == "project-name").count(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_used_accepts_context_usage_legacy_id() {
|
||||
assert_eq!(StatusLineItem::ContextUsed.to_string(), "context-used");
|
||||
@@ -892,29 +858,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
fn render_lines(view: &StatusLineSetupView, width: u16) -> String {
|
||||
let height = view.desired_height(width);
|
||||
let area = Rect::new(0, 0, width, height);
|
||||
let mut buf = Buffer::empty(area);
|
||||
view.render(area, &mut buf);
|
||||
|
||||
(0..area.height)
|
||||
.map(|row| {
|
||||
let mut line = String::new();
|
||||
for col in 0..area.width {
|
||||
let symbol = buf[(area.x + col, area.y + row)].symbol();
|
||||
if symbol.is_empty() {
|
||||
line.push(' ');
|
||||
} else {
|
||||
line.push_str(symbol);
|
||||
}
|
||||
}
|
||||
line
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn line_text(content: Option<HyperlinkLine>) -> Option<String> {
|
||||
content.map(|line| line.line.to_string())
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::terminal_hyperlinks::HyperlinkLine;
|
||||
use codex_protocol::ThreadId;
|
||||
|
||||
use super::multi_select_picker::MultiSelectItem;
|
||||
use super::status_line_from_segments;
|
||||
use super::status_line_setup::StatusLineItem;
|
||||
|
||||
@@ -222,15 +227,52 @@ impl StatusSurfacePreviewData {
|
||||
.unwrap_or_else(|| fallback.to_string())
|
||||
}
|
||||
|
||||
pub(crate) fn rate_limit_item_description(
|
||||
/// Builds canonical, configured-first rows for the status and title pickers.
|
||||
pub(crate) fn picker_items<T>(
|
||||
&self,
|
||||
item: StatusSurfacePreviewItem,
|
||||
fallback: &str,
|
||||
) -> String {
|
||||
self.live_value_for(item)
|
||||
.and_then(rate_limit_preview_copy)
|
||||
.map(|copy| copy.description.to_string())
|
||||
.unwrap_or_else(|| fallback.to_string())
|
||||
configured: Option<&[String]>,
|
||||
description: impl Fn(T) -> &'static str,
|
||||
preview_item: impl Fn(T) -> Option<StatusSurfacePreviewItem>,
|
||||
) -> Vec<MultiSelectItem>
|
||||
where
|
||||
T: Copy + Display + FromStr + IntoEnumIterator,
|
||||
{
|
||||
let selected = configured
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|id| id.parse::<T>().ok());
|
||||
let mut seen = HashSet::new();
|
||||
selected
|
||||
.map(|item| (item, true))
|
||||
.chain(T::iter().map(|item| (item, false)))
|
||||
.filter_map(|(item, enabled)| {
|
||||
let id = item.to_string();
|
||||
if !seen.insert(id.clone()) {
|
||||
return None;
|
||||
}
|
||||
let copy = preview_item(item)
|
||||
.filter(|item| {
|
||||
matches!(
|
||||
item,
|
||||
StatusSurfacePreviewItem::FiveHourLimit
|
||||
| StatusSurfacePreviewItem::WeeklyLimit
|
||||
)
|
||||
})
|
||||
.and_then(|item| self.live_value_for(item))
|
||||
.and_then(rate_limit_preview_copy);
|
||||
let (name, description) = copy.map_or_else(
|
||||
|| (id.clone(), description(item).to_string()),
|
||||
|copy| (copy.name.to_string(), copy.description.to_string()),
|
||||
);
|
||||
Some(MultiSelectItem {
|
||||
id,
|
||||
name,
|
||||
description: Some(description),
|
||||
enabled,
|
||||
..Default::default()
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn value_for(&self, item: StatusSurfacePreviewItem) -> Option<&str> {
|
||||
|
||||
@@ -7,11 +7,7 @@
|
||||
//! - Reorder items
|
||||
//! - Preview the rendered title
|
||||
|
||||
use itertools::Itertools;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::text::Line;
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::Display;
|
||||
use strum_macros::EnumIter;
|
||||
use strum_macros::EnumString;
|
||||
@@ -19,15 +15,11 @@ use strum_macros::EnumString;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use crate::bottom_pane::ACTION_REQUIRED_PREVIEW_PREFIX;
|
||||
use crate::bottom_pane::CancellationEvent;
|
||||
use crate::bottom_pane::bottom_pane_view::BottomPaneView;
|
||||
use crate::bottom_pane::build_action_required_title_text;
|
||||
use crate::bottom_pane::multi_select_picker::MultiSelectItem;
|
||||
use crate::bottom_pane::multi_select_picker::MultiSelectPicker;
|
||||
use crate::bottom_pane::status_surface_preview::StatusSurfacePreviewData;
|
||||
use crate::bottom_pane::status_surface_preview::StatusSurfacePreviewItem;
|
||||
use crate::keymap::ListKeymap;
|
||||
use crate::render::renderable::Renderable;
|
||||
|
||||
/// Available items that can be displayed in the terminal title.
|
||||
///
|
||||
@@ -255,181 +247,68 @@ where
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Interactive view for configuring terminal-title items.
|
||||
pub(crate) struct TerminalTitleSetupView {
|
||||
picker: MultiSelectPicker,
|
||||
}
|
||||
|
||||
impl TerminalTitleSetupView {
|
||||
/// Creates the terminal-title picker, preserving the configured item order first.
|
||||
///
|
||||
/// Unknown configured ids are skipped here instead of surfaced inline. The
|
||||
/// main TUI still warns about them when rendering the actual title, but the
|
||||
/// picker itself only exposes the selectable items it can meaningfully
|
||||
/// preview and persist.
|
||||
pub(crate) fn new(
|
||||
title_items: Option<&[String]>,
|
||||
preview_data: StatusSurfacePreviewData,
|
||||
app_event_tx: AppEventSender,
|
||||
list_keymap: ListKeymap,
|
||||
) -> Self {
|
||||
let selected_items = title_items
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|id| id.parse::<TerminalTitleItem>().ok())
|
||||
.unique()
|
||||
.collect_vec();
|
||||
let selected_set = selected_items
|
||||
.iter()
|
||||
.copied()
|
||||
.collect::<std::collections::HashSet<_>>();
|
||||
let items = selected_items
|
||||
.into_iter()
|
||||
.map(|item| Self::title_select_item(item, /*enabled*/ true, &preview_data))
|
||||
.chain(
|
||||
TerminalTitleItem::iter()
|
||||
.filter(|item| !selected_set.contains(item))
|
||||
.map(|item| {
|
||||
Self::title_select_item(item, /*enabled*/ false, &preview_data)
|
||||
}),
|
||||
)
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
picker: MultiSelectPicker::builder(
|
||||
"Configure Terminal Title".to_string(),
|
||||
Some("Select which items to display in the terminal title.".to_string()),
|
||||
app_event_tx,
|
||||
)
|
||||
.list_keymap(list_keymap)
|
||||
.items(items)
|
||||
.enable_ordering()
|
||||
.on_preview(move |items| {
|
||||
let items = parse_terminal_title_items(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| item.enabled)
|
||||
.map(|item| item.id.as_str()),
|
||||
)?;
|
||||
preview_line_for_title_items(&items, &preview_data)
|
||||
})
|
||||
.on_change(|items, app_event| {
|
||||
let Some(items) = parse_terminal_title_items(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| item.enabled)
|
||||
.map(|item| item.id.as_str()),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
app_event.send(AppEvent::TerminalTitleSetupPreview { items });
|
||||
})
|
||||
.on_confirm(|ids, app_event| {
|
||||
let Some(items) = parse_terminal_title_items(ids.iter().map(String::as_str)) else {
|
||||
return;
|
||||
};
|
||||
app_event.send(AppEvent::TerminalTitleSetup { items });
|
||||
})
|
||||
.on_cancel(|app_event| {
|
||||
app_event.send(AppEvent::TerminalTitleSetupCancelled);
|
||||
})
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
|
||||
fn title_select_item(
|
||||
item: TerminalTitleItem,
|
||||
enabled: bool,
|
||||
preview_data: &StatusSurfacePreviewData,
|
||||
) -> MultiSelectItem {
|
||||
let default_name = item.to_string();
|
||||
let default_description = item.description();
|
||||
let (name, description) = match item.preview_item() {
|
||||
Some(
|
||||
preview_item @ (StatusSurfacePreviewItem::FiveHourLimit
|
||||
| StatusSurfacePreviewItem::WeeklyLimit),
|
||||
) => (
|
||||
preview_data.rate_limit_item_name(preview_item, &default_name),
|
||||
preview_data.rate_limit_item_description(preview_item, default_description),
|
||||
),
|
||||
_ => (default_name, default_description.to_string()),
|
||||
/// Creates the terminal-title picker, skipping unknown IDs and preserving configured order.
|
||||
pub(crate) fn terminal_title_setup(
|
||||
title_items: Option<&[String]>,
|
||||
preview_data: StatusSurfacePreviewData,
|
||||
app_event_tx: AppEventSender,
|
||||
list_keymap: ListKeymap,
|
||||
) -> MultiSelectPicker {
|
||||
let items = preview_data.picker_items(
|
||||
title_items,
|
||||
TerminalTitleItem::description,
|
||||
TerminalTitleItem::preview_item,
|
||||
);
|
||||
MultiSelectPicker::builder(
|
||||
"Configure Terminal Title".to_string(),
|
||||
Some("Select which items to display in the terminal title.".to_string()),
|
||||
app_event_tx,
|
||||
)
|
||||
.list_keymap(list_keymap)
|
||||
.items(items)
|
||||
.enable_ordering()
|
||||
.allow_input_when_disconnected()
|
||||
.on_preview(move |items| {
|
||||
let items = parse_terminal_title_items(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| item.enabled)
|
||||
.map(|item| item.id.as_str()),
|
||||
)?;
|
||||
preview_line_for_title_items(&items, &preview_data)
|
||||
})
|
||||
.on_change(|items, app_event| {
|
||||
let Some(items) = parse_terminal_title_items(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| item.enabled)
|
||||
.map(|item| item.id.as_str()),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
|
||||
MultiSelectItem {
|
||||
id: item.to_string(),
|
||||
name,
|
||||
description: Some(description),
|
||||
enabled,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BottomPaneView for TerminalTitleSetupView {
|
||||
fn keymap_contexts(&self) -> crate::keymap::KeymapContextSet {
|
||||
crate::keymap::KeymapContextSet::new(crate::keymap::KeymapContext::List)
|
||||
}
|
||||
|
||||
fn accepts_input_when_disconnected(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {
|
||||
self.picker.handle_key_event(key_event);
|
||||
}
|
||||
|
||||
fn is_complete(&self) -> bool {
|
||||
self.picker.complete
|
||||
}
|
||||
|
||||
fn on_ctrl_c(&mut self) -> CancellationEvent {
|
||||
self.picker.close();
|
||||
CancellationEvent::Handled
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for TerminalTitleSetupView {
|
||||
fn render(&self, area: Rect, buf: &mut Buffer) {
|
||||
self.picker.render(area, buf);
|
||||
}
|
||||
|
||||
fn desired_height(&self, width: u16) -> u16 {
|
||||
self.picker.desired_height(width)
|
||||
}
|
||||
app_event.send(AppEvent::TerminalTitleSetupPreview { items });
|
||||
})
|
||||
.on_confirm(|ids, app_event| {
|
||||
let Some(items) = parse_terminal_title_items(ids.iter().map(String::as_str)) else {
|
||||
return;
|
||||
};
|
||||
app_event.send(AppEvent::TerminalTitleSetup { items });
|
||||
})
|
||||
.on_cancel(|app_event| {
|
||||
app_event.send(AppEvent::TerminalTitleSetupCancelled);
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::bottom_pane::bottom_pane_view::BottomPaneView;
|
||||
use crate::bottom_pane::multi_select_picker::tests::render_lines;
|
||||
use insta::assert_snapshot;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
fn render_lines(view: &TerminalTitleSetupView, width: u16) -> String {
|
||||
let height = view.desired_height(width);
|
||||
let area = Rect::new(0, 0, width, height);
|
||||
let mut buf = Buffer::empty(area);
|
||||
view.render(area, &mut buf);
|
||||
|
||||
let lines: Vec<String> = (0..area.height)
|
||||
.map(|row| {
|
||||
let mut line = String::new();
|
||||
for col in 0..area.width {
|
||||
let symbol = buf[(area.x + col, area.y + row)].symbol();
|
||||
if symbol.is_empty() {
|
||||
line.push(' ');
|
||||
} else {
|
||||
line.push_str(symbol);
|
||||
}
|
||||
}
|
||||
line
|
||||
})
|
||||
.collect();
|
||||
lines.join("\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renders_title_setup_popup() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
@@ -440,12 +319,13 @@ mod tests {
|
||||
"run-state".to_string(),
|
||||
"thread-title".to_string(),
|
||||
];
|
||||
let view = TerminalTitleSetupView::new(
|
||||
let view = terminal_title_setup(
|
||||
Some(&selected),
|
||||
StatusSurfacePreviewData::default(),
|
||||
tx,
|
||||
crate::keymap::RuntimeKeymap::defaults().list,
|
||||
);
|
||||
assert!(view.accepts_input_when_disconnected());
|
||||
assert_snapshot!(
|
||||
"terminal_title_setup_basic",
|
||||
render_lines(&view, /*width*/ 84)
|
||||
|
||||
@@ -52,7 +52,6 @@ use crate::bottom_pane::StatusLineSetupView;
|
||||
use crate::bottom_pane::StatusSurfacePreviewData;
|
||||
use crate::bottom_pane::StatusSurfacePreviewItem;
|
||||
use crate::bottom_pane::TerminalTitleItem;
|
||||
use crate::bottom_pane::TerminalTitleSetupView;
|
||||
use crate::diff_model::FileChange;
|
||||
use crate::git_action_directives::parse_assistant_markdown;
|
||||
use crate::legacy_core::config::Config;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
use super::*;
|
||||
use crate::bottom_pane::StatusLine;
|
||||
use crate::bottom_pane::terminal_title_setup;
|
||||
use crate::status::thread_cost_micros;
|
||||
|
||||
impl ChatWidget {
|
||||
@@ -360,7 +361,7 @@ impl ChatWidget {
|
||||
let configured_terminal_title_items = self.configured_terminal_title_items();
|
||||
self.terminal_title_setup_original_items =
|
||||
Some(self.local_settings.tui.terminal_title.clone());
|
||||
let view = TerminalTitleSetupView::new(
|
||||
let view = terminal_title_setup(
|
||||
Some(configured_terminal_title_items.as_slice()),
|
||||
self.terminal_title_preview_data(),
|
||||
self.app_event_tx.clone(),
|
||||
|
||||
Reference in New Issue
Block a user