Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions codex-rs/tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub(crate) struct App<'a> {
app_event_rx: Receiver<AppEvent>,
app_state: AppState<'a>,

/// Config is stored here so we can recreate ChatWidgets as needed.
config: Config,

/// Stored parameters needed to instantiate the ChatWidget later, e.g.,
/// after dismissing the Git-repo warning.
chat_args: Option<ChatWidgetArgs>,
Expand Down Expand Up @@ -122,7 +125,7 @@ impl<'a> App<'a> {
screen: LoginScreen::new(app_event_tx.clone(), config.codex_home.clone()),
},
Some(ChatWidgetArgs {
config,
config: config.clone(),
initial_prompt,
initial_images,
}),
Expand All @@ -133,14 +136,18 @@ impl<'a> App<'a> {
screen: GitWarningScreen::new(),
},
Some(ChatWidgetArgs {
config,
config: config.clone(),
initial_prompt,
initial_images,
}),
)
} else {
let chat_widget =
ChatWidget::new(config, app_event_tx.clone(), initial_prompt, initial_images);
let chat_widget = ChatWidget::new(
config.clone(),
app_event_tx.clone(),
initial_prompt,
initial_images,
);
(
AppState::Chat {
widget: Box::new(chat_widget),
Expand All @@ -153,6 +160,7 @@ impl<'a> App<'a> {
app_event_tx,
app_event_rx,
app_state,
config,
chat_args,
}
}
Expand Down Expand Up @@ -224,10 +232,16 @@ impl<'a> App<'a> {
AppState::Login { .. } | AppState::GitWarning { .. } => {}
},
AppEvent::DispatchCommand(command) => match command {
SlashCommand::Clear => match &mut self.app_state {
AppState::Chat { widget } => widget.clear_conversation_history(),
AppState::Login { .. } | AppState::GitWarning { .. } => {}
},
SlashCommand::New => {
let new_widget = Box::new(ChatWidget::new(
self.config.clone(),
self.app_event_tx.clone(),
None,
Vec::new(),
));
self.app_state = AppState::Chat { widget: new_widget };
self.app_event_tx.send(AppEvent::Redraw);
}
SlashCommand::ToggleMouseMode => {
if let Err(e) = mouse_capture.toggle() {
tracing::error!("Failed to toggle mouse mode: {e}");
Expand Down
5 changes: 0 additions & 5 deletions codex-rs/tui/src/chatwidget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ impl ChatWidget<'_> {
self.conversation_history.scroll_to_bottom();
}

pub(crate) fn clear_conversation_history(&mut self) {
self.conversation_history.clear();
self.request_redraw();
}

pub(crate) fn handle_codex_event(&mut self, event: Event) {
let Event { id, msg } = event;
match msg {
Expand Down
6 changes: 0 additions & 6 deletions codex-rs/tui/src/conversation_history_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@ impl ConversationHistoryWidget {
});
}

/// Remove all history entries and reset scrolling.
pub fn clear(&mut self) {
self.entries.clear();
self.scroll_position = usize::MAX;
}

pub fn record_completed_exec_command(
&mut self,
call_id: String,
Expand Down
4 changes: 2 additions & 2 deletions codex-rs/tui/src/slash_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use strum_macros::IntoStaticStr;
)]
#[strum(serialize_all = "kebab-case")]
pub enum SlashCommand {
Clear,
New,
ToggleMouseMode,
Quit,
}
Expand All @@ -21,7 +21,7 @@ impl SlashCommand {
/// User-visible description shown in the popup.
pub fn description(self) -> &'static str {
match self {
SlashCommand::Clear => "Clear the chat history.",
SlashCommand::New => "Start a new chat.",
SlashCommand::ToggleMouseMode => {
"Toggle mouse mode (enable for scrolling, disable for text selection)"
}
Expand Down