Port terminal tool to agent2 (#35918)

Release Notes:

- N/A

---------

Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
This commit is contained in:
Antonio Scandurra 2025-08-11 12:31:13 +02:00 committed by GitHub
parent 422e0a2eb7
commit 086ea3c619
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 882 additions and 112 deletions

View file

@ -5,6 +5,13 @@ edition.workspace = true
publish.workspace = true
license = "GPL-3.0-or-later"
[features]
test-support = [
"collections/test-support",
"gpui/test-support",
"settings/test-support",
]
[lints]
workspace = true
@ -39,5 +46,6 @@ workspace-hack.workspace = true
windows.workspace = true
[dev-dependencies]
gpui = { workspace = true, features = ["test-support"] }
rand.workspace = true
url.workspace = true

View file

@ -58,7 +58,7 @@ use std::{
path::PathBuf,
process::ExitStatus,
sync::Arc,
time::{Duration, Instant},
time::Instant,
};
use thiserror::Error;
@ -534,10 +534,15 @@ impl TerminalBuilder {
'outer: loop {
let mut events = Vec::new();
#[cfg(any(test, feature = "test-support"))]
let mut timer = cx.background_executor().simulate_random_delay().fuse();
#[cfg(not(any(test, feature = "test-support")))]
let mut timer = cx
.background_executor()
.timer(Duration::from_millis(4))
.timer(std::time::Duration::from_millis(4))
.fuse();
let mut wakeup = false;
loop {
futures::select_biased! {
@ -2104,16 +2109,56 @@ pub fn rgba_color(r: u8, g: u8, b: u8) -> Hsla {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
IndexedCell, TerminalBounds, TerminalBuilder, TerminalContent, content_index_for_mouse,
rgb_for_index,
};
use alacritty_terminal::{
index::{Column, Line, Point as AlacPoint},
term::cell::Cell,
};
use gpui::{Pixels, Point, bounds, point, size};
use collections::HashMap;
use gpui::{Pixels, Point, TestAppContext, bounds, point, size};
use rand::{Rng, distributions::Alphanumeric, rngs::ThreadRng, thread_rng};
use crate::{
IndexedCell, TerminalBounds, TerminalContent, content_index_for_mouse, rgb_for_index,
};
#[cfg_attr(windows, ignore = "TODO: fix on windows")]
#[gpui::test]
async fn test_basic_terminal(cx: &mut TestAppContext) {
cx.executor().allow_parking();
let (completion_tx, completion_rx) = smol::channel::unbounded();
let terminal = cx.new(|cx| {
TerminalBuilder::new(
None,
None,
None,
task::Shell::WithArguments {
program: "echo".into(),
args: vec!["hello".into()],
title_override: None,
},
HashMap::default(),
CursorShape::default(),
AlternateScroll::On,
None,
false,
0,
completion_tx,
cx,
)
.unwrap()
.subscribe(cx)
});
assert_eq!(
completion_rx.recv().await.unwrap(),
Some(ExitStatus::default())
);
assert_eq!(
terminal.update(cx, |term, _| term.get_content()).trim(),
"hello"
);
}
#[test]
fn test_rgb_for_index() {