Display-only ACP terminals (#39419)
Codex needs (and future projects are anticipated to need as well) a concept of display-only terminals. This refactors terminals to decouple the PTY part from the display part, so that we can render terminal changes based on a series of events - regardless of whether they're being driven from a PTY inside Zed or from an outside source (e.g. `codex-acp`). Release Notes: - N/A
This commit is contained in:
@@ -339,6 +339,29 @@ pub struct TerminalBuilder {
|
||||
}
|
||||
|
||||
impl TerminalBuilder {
|
||||
pub fn new_display_only(
|
||||
working_directory: Option<PathBuf>,
|
||||
cursor_shape: CursorShape,
|
||||
alternate_scroll: AlternateScroll,
|
||||
max_scroll_history_lines: Option<usize>,
|
||||
window_id: u64,
|
||||
cx: &App,
|
||||
) -> Result<TerminalBuilder> {
|
||||
Self::new(
|
||||
working_directory,
|
||||
None,
|
||||
Shell::System,
|
||||
HashMap::default(),
|
||||
cursor_shape,
|
||||
alternate_scroll,
|
||||
max_scroll_history_lines,
|
||||
false,
|
||||
window_id,
|
||||
None,
|
||||
cx,
|
||||
Vec::new(),
|
||||
)
|
||||
}
|
||||
pub fn new(
|
||||
working_directory: Option<PathBuf>,
|
||||
task: Option<TaskState>,
|
||||
@@ -1132,6 +1155,19 @@ impl Terminal {
|
||||
self.term.lock().set_options(self.term_config.clone());
|
||||
}
|
||||
|
||||
pub fn write_output(&mut self, bytes: &[u8], cx: &mut Context<Self>) {
|
||||
// Inject bytes directly into the terminal emulator and refresh the UI.
|
||||
// This bypasses the PTY/event loop for display-only terminals.
|
||||
let mut processor = alacritty_terminal::vte::ansi::Processor::<
|
||||
alacritty_terminal::vte::ansi::StdSyncHandler,
|
||||
>::new();
|
||||
{
|
||||
let mut term = self.term.lock();
|
||||
processor.advance(&mut *term, bytes);
|
||||
}
|
||||
cx.emit(Event::Wakeup);
|
||||
}
|
||||
|
||||
pub fn total_lines(&self) -> usize {
|
||||
let term = self.term.clone();
|
||||
let terminal = term.lock_unfair();
|
||||
@@ -2272,6 +2308,17 @@ mod tests {
|
||||
terminal.update(cx, |term, _| term.get_content()).trim(),
|
||||
"hello"
|
||||
);
|
||||
|
||||
// Inject additional output directly into the emulator (display-only path)
|
||||
terminal.update(cx, |term, cx| {
|
||||
term.write_output(b"\nfrom_injection", cx);
|
||||
});
|
||||
|
||||
let content_after = terminal.update(cx, |term, _| term.get_content());
|
||||
assert!(
|
||||
content_after.contains("from_injection"),
|
||||
"expected injected output to appear, got: {content_after}"
|
||||
);
|
||||
}
|
||||
|
||||
// TODO should be tested on Linux too, but does not work there well
|
||||
|
||||
Reference in New Issue
Block a user