assistant: Add term slash command (#13162)

This adds a `term` slash command to the assistant which allows to inject
the latest terminal output into the context.

Release Notes:

- N/A
This commit is contained in:
Bennet Bo Fenner 2024-06-20 20:20:34 +02:00 committed by GitHub
parent 710c387395
commit 0150192e26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 135 additions and 1 deletions

View file

@ -1083,6 +1083,31 @@ impl Terminal {
}
}
pub fn last_n_non_empty_lines(&self, n: usize) -> Vec<String> {
let term = self.term.clone();
let terminal = term.lock_unfair();
let mut lines = Vec::new();
let mut current_line = terminal.bottommost_line();
while lines.len() < n {
let mut line_buffer = String::new();
for cell in &terminal.grid()[current_line] {
line_buffer.push(cell.c);
}
let line = line_buffer.trim_end();
if !line.is_empty() {
lines.push(line.to_string());
}
if current_line == terminal.topmost_line() {
break;
}
current_line = Line(current_line.0 - 1);
}
lines.reverse();
lines
}
pub fn focus_in(&self) {
if self.last_content.mode.contains(TermMode::FOCUS_IN_OUT) {
self.write_to_pty("\x1b[I".to_string());