1use vt100::Cell;
2
3#[derive(Clone, PartialEq, Default, Debug)]
5pub struct TerminalSelection {
6 pub dragging: bool,
7 pub start_row: usize,
8 pub start_col: usize,
9 pub start_scroll: usize,
10 pub end_row: usize,
11 pub end_col: usize,
12 pub end_scroll: usize,
13}
14
15impl TerminalSelection {
16 pub fn display_positions(&self, current_scroll: usize) -> (i64, usize, i64, usize) {
18 let current_scroll = current_scroll as i64;
19 let start_display = self.start_row as i64 - self.start_scroll as i64 + current_scroll;
20 let end_display = self.end_row as i64 - self.end_scroll as i64 + current_scroll;
21 if start_display < end_display
22 || (start_display == end_display && self.start_col <= self.end_col)
23 {
24 (start_display, self.start_col, end_display, self.end_col)
25 } else {
26 (end_display, self.end_col, start_display, self.start_col)
27 }
28 }
29
30 pub fn is_empty(&self) -> bool {
31 let start_content = self.start_row as i64 - self.start_scroll as i64;
32 let end_content = self.end_row as i64 - self.end_scroll as i64;
33 start_content == end_content && self.start_col == self.end_col
34 }
35}
36
37#[derive(Clone, PartialEq, Default)]
39pub struct TerminalBuffer {
40 pub rows: Vec<Vec<Cell>>,
42 pub cursor_row: usize,
44 pub cursor_col: usize,
46 pub cols: usize,
48 pub rows_count: usize,
50 pub selection: Option<TerminalSelection>,
52 pub scroll_offset: usize,
54 pub total_scrollback: usize,
56}