Way better

This commit is contained in:
jif-oai
2025-12-08 19:01:48 +00:00
parent 0de14edf58
commit 6b3631f499

View File

@@ -62,60 +62,16 @@ const UNIFIED_EXEC_ENV: [(&str, &str); 8] = [
("GIT_PAGER", "cat"),
];
#[cfg(target_os = "windows")]
fn normalize_unified_exec_text(raw: &str) -> String {
let rows: u16 = 40;
let cols: u16 = 120;
let mut parser = vt100::Parser::new(rows, cols, 0);
parser.process(raw.as_bytes());
parser.screen().contents()
}
#[cfg(not(target_os = "windows"))]
fn normalize_unified_exec_text(raw: &str) -> String {
raw.to_string()
}
fn strip_ansi_escape_sequences(input: &str) -> String {
let mut result = String::with_capacity(input.len());
let mut iter = input.chars().peekable();
while let Some(ch) = iter.next() {
if ch == '\u{1b}' {
match iter.peek().copied() {
Some('[') => {
let _ = iter.next();
for c in iter.by_ref() {
if ('@'..='~').contains(&c) {
break;
}
}
}
Some(']') => {
let _ = iter.next();
while let Some(c) = iter.next() {
if c == '\u{7}' {
break;
}
if c == '\u{1b}'
&& let Some('\\') = iter.peek().copied()
{
let _ = iter.next();
break;
}
}
}
Some(_) => {
let _ = iter.next();
}
None => {}
}
} else {
result.push(ch);
}
if cfg!(target_os = "windows") {
let rows: u16 = 40;
let cols: u16 = 120;
let mut parser = vt100::Parser::new(rows, cols, 0);
parser.process(raw.as_bytes());
parser.screen().contents()
} else {
raw.to_string()
}
result
}
fn apply_unified_exec_env(mut env: HashMap<String, String>) -> HashMap<String, String> {
@@ -220,10 +176,7 @@ impl UnifiedExecSessionManager {
let wall_time = Instant::now().saturating_duration_since(start);
let raw_text = String::from_utf8_lossy(&collected).to_string();
#[cfg(target_os = "windows")]
let text = normalize_unified_exec_text(&raw_text);
#[cfg(not(target_os = "windows"))]
let text = raw_text;
let output = formatted_truncate_text(&text, TruncationPolicy::Tokens(max_tokens));
let has_exited = session.has_exited();
let exit_code = session.exit_code();
@@ -346,10 +299,7 @@ impl UnifiedExecSessionManager {
let wall_time = Instant::now().saturating_duration_since(start);
let raw_text = String::from_utf8_lossy(&collected).to_string();
#[cfg(target_os = "windows")]
let text = normalize_unified_exec_text(&raw_text);
#[cfg(not(target_os = "windows"))]
let text = raw_text;
let output = formatted_truncate_text(&text, TruncationPolicy::Tokens(max_tokens));
let original_token_count = approx_token_count(&text);
let chunk_id = generate_chunk_id();