Compare commits

...

2 Commits

Author SHA1 Message Date
Bennet Bo Fenner
6a707c315d support reading last command output
Co-authored-by: jean-philippe martel <jpmartel98@gmail.com>
2024-09-13 14:56:51 -04:00
Bennet Bo Fenner
656b8319ad Handle cell type
Co-authored-by: jean-philippe martel <jpmartel98@gmail.com>
2024-09-13 14:29:47 -04:00
5 changed files with 109 additions and 21 deletions

18
Cargo.lock generated
View File

@@ -88,7 +88,6 @@ dependencies = [
[[package]]
name = "alacritty_terminal"
version = "0.24.1-dev"
source = "git+https://github.com/alacritty/alacritty?rev=91d034ff8b53867143c005acfaa14609147c9a2c#91d034ff8b53867143c005acfaa14609147c9a2c"
dependencies = [
"base64 0.22.1",
"bitflags 2.6.0",
@@ -200,7 +199,7 @@ dependencies = [
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
"utf8parse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -215,7 +214,7 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
dependencies = [
"utf8parse",
"utf8parse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -12435,6 +12434,11 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "git+https://github.com/zed-industries/vte?branch=osc-133-2#018e5445f02271669136718db865e9bf43aa1ea3"
[[package]]
name = "util"
version = "0.1.0"
@@ -12629,22 +12633,20 @@ dependencies = [
[[package]]
name = "vte"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40eb22ae96f050e0c0d6f7ce43feeae26c348fc4dea56928ca81537cfaa6188b"
source = "git+https://github.com/zed-industries/vte?branch=osc-133-2#018e5445f02271669136718db865e9bf43aa1ea3"
dependencies = [
"bitflags 2.6.0",
"cursor-icon",
"log",
"serde",
"utf8parse",
"utf8parse 0.2.2 (git+https://github.com/zed-industries/vte?branch=osc-133-2)",
"vte_generate_state_changes",
]
[[package]]
name = "vte_generate_state_changes"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e369bee1b05d510a7b4ed645f5faa90619e05437111783ea5848f28d97d3c2e"
source = "git+https://github.com/zed-industries/vte?branch=osc-133-2#018e5445f02271669136718db865e9bf43aa1ea3"
dependencies = [
"proc-macro2",
"quote",

View File

@@ -306,7 +306,7 @@ zed_actions = { path = "crates/zed_actions" }
#
aho-corasick = "1.1"
alacritty_terminal = { git = "https://github.com/alacritty/alacritty", rev = "91d034ff8b53867143c005acfaa14609147c9a2c" }
alacritty_terminal = { path = "../alacritty/alacritty_terminal" }
any_vec = "0.14"
anyhow = "1.0.86"
arrayvec = { version = "0.7.4", features = ["serde"] }

View File

@@ -74,11 +74,7 @@ impl SlashCommand for TerminalSlashCommand {
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(DEFAULT_CONTEXT_LINES);
let lines = active_terminal
.read(cx)
.model()
.read(cx)
.last_n_non_empty_lines(line_count);
let lines = active_terminal.read(cx).model().read(cx).last_command();
let mut text = String::new();
text.push_str("Terminal output:\n");

View File

@@ -700,6 +700,9 @@ impl Terminal {
AlacTermEvent::ChildExit(error_code) => {
self.register_task_finished(Some(*error_code), cx);
}
AlacTermEvent::Osc133(command) => {
dbg!(command);
}
}
}
@@ -1153,6 +1156,64 @@ impl Terminal {
}
}
pub fn last_command(&self) -> Vec<String> {
let term = self.term.clone();
let terminal = term.lock_unfair();
let mut current_line = Line(terminal.bottommost_line().0.saturating_sub(1));
dbg!(&current_line);
let mut lines = Vec::new();
let mut found_start = false;
let mut found_end = false;
loop {
let mut line_buffer = String::new();
let line = &terminal.grid()[current_line];
let s = line.into_iter().next().and_then(|cell| cell.cell_type());
current_line = Line(current_line.0.saturating_sub(1));
let Some(cell_type) = s else {
if current_line == terminal.topmost_line() {
break;
}
continue;
};
match cell_type {
alacritty_terminal::term::cell::Osc133CellType::Prompt => {
if !found_start {
continue;
}
found_end = true;
}
alacritty_terminal::term::cell::Osc133CellType::Output => {
found_start = true;
if found_end {
break;
}
}
_ => {}
}
for cell in 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;
}
}
lines.reverse();
dbg!(&lines);
lines
}
pub fn last_n_non_empty_lines(&self, n: usize) -> Vec<String> {
let term = self.term.clone();
let terminal = term.lock_unfair();

View File

@@ -1,6 +1,6 @@
use editor::{CursorLayout, HighlightedRange, HighlightedRangeLine};
use gpui::{
div, fill, point, px, relative, size, AnyElement, AvailableSpace, Bounds, ContentMask,
div, fill, hsla, point, px, relative, size, AnyElement, AvailableSpace, Bounds, ContentMask,
DispatchPhase, Element, ElementId, FocusHandle, Font, FontStyle, FontWeight, GlobalElementId,
HighlightStyle, Hitbox, Hsla, InputHandler, InteractiveElement, Interactivity, IntoElement,
LayoutId, Model, ModelContext, ModifiersChangedEvent, MouseButton, MouseMoveEvent, Pixels,
@@ -225,7 +225,17 @@ impl TerminalElement {
if matches!(bg, Named(NamedColor::Background)) {
//Continue to next cell, resetting variables if necessary
cur_alac_color = None;
if let Some(rect) = cur_rect {
if let Some(mut rect) = cur_rect {
if let Some(ty) = cell.cell.cell_type() {
dbg!(&ty);
let color = match ty {
terminal::alacritty_terminal::term::cell::Osc133CellType::Prompt => hsla(1.0, 1.0, 0.0, 0.5),
terminal::alacritty_terminal::term::cell::Osc133CellType::Input => hsla(0.0, 1.0, 0.0, 0.5),
terminal::alacritty_terminal::term::cell::Osc133CellType::Output => hsla(0.0, 0.0, 1.0, 0.5),
};
rect.color = color;
}
rects.push(rect);
cur_rect = None
}
@@ -251,8 +261,18 @@ impl TerminalElement {
);
} else {
cur_alac_color = Some(bg);
if cur_rect.is_some() {
rects.push(cur_rect.take().unwrap());
if let Some(mut rect) = cur_rect.take() {
dbg!("About to psuh");
if let Some(ty) = cell.cell.cell_type() {
dbg!(&ty);
let color = match ty {
terminal::alacritty_terminal::term::cell::Osc133CellType::Prompt => hsla(1.0, 1.0, 0.0, 0.5),
terminal::alacritty_terminal::term::cell::Osc133CellType::Input => hsla(0.0, 1.0, 0.0, 0.5),
terminal::alacritty_terminal::term::cell::Osc133CellType::Output => hsla(0.0, 0.0, 1.0, 0.5),
};
rect.color = color;
}
rects.push(rect);
}
cur_rect = Some(LayoutRect::new(
AlacPoint::new(
@@ -280,9 +300,18 @@ impl TerminalElement {
{
if !is_blank(&cell) {
let cell_text = cell.c.to_string();
let cell_style =
let mut cell_style =
TerminalElement::cell_style(&cell, fg, theme, text_style, hyperlink);
if let Some(ty) = cell.cell.cell_type() {
let color = match ty {
terminal::alacritty_terminal::term::cell::Osc133CellType::Prompt => Hsla::red(),
terminal::alacritty_terminal::term::cell::Osc133CellType::Input => Hsla::green(),
terminal::alacritty_terminal::term::cell::Osc133CellType::Output => Hsla::blue(),
};
cell_style.background_color = Some(color);
}
let layout_cell = text_system
.shape_line(
cell_text.into(),
@@ -299,8 +328,8 @@ impl TerminalElement {
}
}
if cur_rect.is_some() {
rects.push(cur_rect.take().unwrap());
if let Some(rect) = cur_rect.take() {
rects.push(rect);
}
}
(cells, rects)