mirror of
https://github.com/openai/codex.git
synced 2026-10-21 05:22:21 +00:00
Simplify TUI restoration for the external editor (#34551)
## What changed Remove the unused `RestoreMode` selection from `Tui::with_restored`. The helper now always restores the terminal while keeping raw mode enabled, matching its external-editor call site. GitOrigin-RevId: b820aaaa933d7354d2a21b95900b059b3e8e2ac6
This commit is contained in:
@@ -31,9 +31,7 @@ impl App {
|
||||
|
||||
let seed = self.chat_widget.composer_text_with_pending();
|
||||
let editor_result = tui
|
||||
.with_restored(tui::RestoreMode::KeepRaw, || async {
|
||||
external_editor::run_editor(&seed, &editor_cmd).await
|
||||
})
|
||||
.with_restored(|| async { external_editor::run_editor(&seed, &editor_cmd).await })
|
||||
.await;
|
||||
self.reset_external_editor_state(tui);
|
||||
|
||||
|
||||
+4
-20
@@ -332,22 +332,6 @@ pub fn restore_keep_raw() -> Result<()> {
|
||||
restore_common(RawModeRestore::Keep, KeyboardRestore::PopStack)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum RestoreMode {
|
||||
#[allow(dead_code)]
|
||||
Full, // Fully restore the terminal (disables raw mode).
|
||||
KeepRaw, // Restore the terminal but keep raw mode enabled.
|
||||
}
|
||||
|
||||
impl RestoreMode {
|
||||
fn restore(self) -> Result<()> {
|
||||
match self {
|
||||
RestoreMode::Full => restore(),
|
||||
RestoreMode::KeepRaw => restore_keep_raw(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Flush the underlying stdin buffer to clear any input that may be buffered at the terminal level.
|
||||
/// For example, clears any user input that occurred while the crossterm EventStream was dropped.
|
||||
#[cfg(unix)]
|
||||
@@ -658,9 +642,9 @@ impl Tui {
|
||||
/// Temporarily restore terminal state to run an external interactive program `f`.
|
||||
///
|
||||
/// This pauses crossterm's stdin polling by dropping the underlying event stream, restores
|
||||
/// terminal modes and stderr (optionally keeping raw mode enabled), then re-applies Codex TUI
|
||||
/// modes and stderr suppression before resuming events.
|
||||
pub async fn with_restored<R, F, Fut>(&mut self, mode: RestoreMode, f: F) -> R
|
||||
/// terminal modes and stderr while keeping raw mode enabled, then re-applies Codex TUI modes
|
||||
/// and stderr suppression before resuming events.
|
||||
pub async fn with_restored<R, F, Fut>(&mut self, f: F) -> R
|
||||
where
|
||||
F: FnOnce() -> Fut,
|
||||
Fut: Future<Output = R>,
|
||||
@@ -674,7 +658,7 @@ impl Tui {
|
||||
let _ = self.leave_alt_screen();
|
||||
}
|
||||
|
||||
if let Err(err) = mode.restore() {
|
||||
if let Err(err) = restore_keep_raw() {
|
||||
tracing::warn!("failed to restore terminal modes before external program: {err}");
|
||||
}
|
||||
if let Err(err) = terminal_stderr::pause() {
|
||||
|
||||
Reference in New Issue
Block a user