terminal is fixed and im not happy about it

This commit is contained in:
Zacharias-Brohn
2026-04-09 23:49:32 +02:00
parent f38033c782
commit 5129612f9f
3 changed files with 59 additions and 19 deletions
+39 -8
View File
@@ -38,6 +38,7 @@ pub struct Cell {
pub bg_color: Color,
pub bold: bool,
pub italic: bool,
pub reverse: bool,
/// Underline style: 0=none, 1=single, 2=double, 3=curly, 4=dotted, 5=dashed
pub underline_style: u8,
/// Strikethrough decoration
@@ -45,6 +46,8 @@ pub struct Cell {
/// If true, this cell is the continuation of a wide (double-width) character.
/// The actual character is stored in the previous cell.
pub wide_continuation: bool,
/// Indicates if the line wrapped after this cell.
pub wrapped: bool,
}
impl Default for Cell {
@@ -55,9 +58,11 @@ impl Default for Cell {
bg_color: Color::Default,
bold: false,
italic: false,
reverse: false,
underline_style: 0,
strikethrough: false,
wide_continuation: false,
wrapped: false,
}
}
}
@@ -269,6 +274,7 @@ struct SavedCursor {
strikethrough: bool,
origin_mode: bool,
auto_wrap: bool,
reverse: bool,
}
/// Alternate screen buffer state.
@@ -509,6 +515,8 @@ pub struct Terminal {
pub current_underline_style: u8,
/// Current strikethrough state.
pub current_strikethrough: bool,
/// Current reverse video state.
pub current_reverse: bool,
/// Whether the terminal content has changed.
pub dirty: bool,
/// Bitmap of dirty lines - bit N is set if line N needs redrawing.
@@ -594,6 +602,7 @@ impl Terminal {
current_italic: false,
current_underline_style: 0,
current_strikethrough: false,
current_reverse: false,
dirty: true,
dirty_lines: [!0u64; 4], // All lines dirty initially
scroll_top: 0,
@@ -697,9 +706,11 @@ impl Terminal {
bg_color: self.current_bg,
bold: self.current_bold,
italic: self.current_italic,
reverse: self.current_reverse,
underline_style: self.current_underline_style,
strikethrough: self.current_strikethrough,
wide_continuation,
wrapped: false,
}
}
@@ -741,9 +752,11 @@ impl Terminal {
bg_color: self.current_bg,
bold: false,
italic: false,
reverse: false,
underline_style: 0,
strikethrough: false,
wide_continuation: false,
wrapped: false,
}
}
@@ -1459,6 +1472,9 @@ impl Handler for Terminal {
// Handle wrap
if self.cursor_col >= self.cols {
if self.auto_wrap {
if self.cols > 0 {
self.grid[grid_row][0].wrapped = true;
}
self.cursor_col = 0;
self.advance_row();
cached_row = self.cursor_row;
@@ -1970,6 +1986,10 @@ impl Handler for Terminal {
// Handle wrap
if self.cursor_col >= self.cols {
if self.auto_wrap {
let gr = self.line_map[self.cursor_row];
if self.cols > 0 {
self.grid[gr][0].wrapped = true;
}
self.cursor_col = 0;
self.advance_row();
self.mark_line_dirty(self.cursor_row);
@@ -2167,15 +2187,17 @@ impl Handler for Terminal {
italic: self.current_italic,
underline_style: self.current_underline_style,
strikethrough: self.current_strikethrough,
reverse: self.current_reverse,
origin_mode: self.origin_mode,
auto_wrap: self.auto_wrap,
};
log::debug!(
"ESC 7: Cursor saved at ({}, {}), origin_mode={}, auto_wrap={}",
"ESC 7: Cursor saved at ({}, {}), origin_mode={}, auto_wrap={}, reverse={}",
self.cursor_col,
self.cursor_row,
self.origin_mode,
self.auto_wrap
self.auto_wrap,
self.current_reverse
);
}
@@ -2190,14 +2212,16 @@ impl Handler for Terminal {
self.current_italic = self.saved_cursor.italic;
self.current_underline_style = self.saved_cursor.underline_style;
self.current_strikethrough = self.saved_cursor.strikethrough;
self.current_reverse = self.saved_cursor.reverse;
self.origin_mode = self.saved_cursor.origin_mode;
self.auto_wrap = self.saved_cursor.auto_wrap;
log::debug!(
"ESC 8: Cursor restored to ({}, {}), origin_mode={}, auto_wrap={}",
"ESC 8: Cursor restored to ({}, {}), origin_mode={}, auto_wrap={}, reverse={}",
self.cursor_col,
self.cursor_row,
self.origin_mode,
self.auto_wrap
self.auto_wrap,
self.current_reverse
);
}
@@ -2285,9 +2309,11 @@ impl Handler for Terminal {
bg_color: Color::Default,
bold: false,
italic: false,
reverse: false,
underline_style: 0,
strikethrough: false,
wide_continuation: false,
wrapped: false,
};
}
self.mark_line_dirty(visual_row);
@@ -2324,6 +2350,10 @@ impl Terminal {
// Check if we need to wrap before printing
if self.cursor_col >= self.cols {
if self.auto_wrap {
let grid_row = self.line_map[self.cursor_row];
if self.cols > 0 {
self.grid[grid_row][0].wrapped = true;
}
self.cursor_col = 0;
self.advance_row();
} else {
@@ -2338,6 +2368,7 @@ impl Terminal {
// Write a space in the last column and wrap
let grid_row = self.line_map[self.cursor_row];
self.grid[grid_row][self.cursor_col] = Cell::default();
self.grid[grid_row][0].wrapped = true;
self.cursor_col = 0;
self.advance_row();
} else {
@@ -2460,15 +2491,14 @@ impl Terminal {
self.current_underline_style = 1;
}
}
7 => std::mem::swap(&mut self.current_fg, &mut self.current_bg),
7 => self.current_reverse = true,
9 => self.current_strikethrough = true,
21 => self.current_underline_style = 2, // Double underline
22 => self.current_bold = false,
23 => self.current_italic = false,
24 => self.current_underline_style = 0,
27 => {
std::mem::swap(&mut self.current_fg, &mut self.current_bg)
}
27 => self.current_reverse = false,
28 => self.current_reverse = false,
29 => self.current_strikethrough = false,
// Standard foreground colors (30-37)
30..=37 => self.current_fg = Color::Indexed((code - 30) as u8),
@@ -2517,6 +2547,7 @@ impl Terminal {
self.current_italic = false;
self.current_underline_style = 0;
self.current_strikethrough = false;
self.current_reverse = false;
}
/// Handle Kitty keyboard protocol CSI sequences.