Skip to main content

revue/widget/developer/terminal/
types.rs

1//! Terminal widget types
2
3use crate::render::Modifier;
4use crate::style::Color;
5
6/// Terminal cell with character and styling
7#[derive(Clone, Debug)]
8pub struct TermCell {
9    /// Character
10    pub ch: char,
11    /// Foreground color
12    pub fg: Color,
13    /// Background color
14    pub bg: Color,
15    /// Text modifiers
16    pub modifiers: Modifier,
17}
18
19impl Default for TermCell {
20    fn default() -> Self {
21        Self {
22            ch: ' ',
23            fg: Color::WHITE,
24            bg: Color::BLACK,
25            modifiers: Modifier::empty(),
26        }
27    }
28}
29
30impl TermCell {
31    /// Create a new terminal cell
32    pub fn new(ch: char) -> Self {
33        Self {
34            ch,
35            ..Default::default()
36        }
37    }
38
39    /// Set foreground color
40    pub fn fg(mut self, color: Color) -> Self {
41        self.fg = color;
42        self
43    }
44
45    /// Set background color
46    pub fn bg(mut self, color: Color) -> Self {
47        self.bg = color;
48        self
49    }
50
51    /// Set modifiers
52    pub fn modifiers(mut self, modifiers: Modifier) -> Self {
53        self.modifiers = modifiers;
54        self
55    }
56}
57
58/// Terminal line containing cells
59#[derive(Clone, Debug)]
60pub struct TermLine {
61    /// Cells in this line
62    pub cells: Vec<TermCell>,
63    /// Whether line is wrapped from previous
64    pub wrapped: bool,
65}
66
67impl TermLine {
68    /// Create empty line
69    pub fn new() -> Self {
70        Self {
71            cells: Vec::new(),
72            wrapped: false,
73        }
74    }
75
76    /// Create line with capacity
77    pub fn with_capacity(capacity: usize) -> Self {
78        Self {
79            cells: Vec::with_capacity(capacity),
80            wrapped: false,
81        }
82    }
83}
84
85impl Default for TermLine {
86    fn default() -> Self {
87        Self::new()
88    }
89}
90
91/// Cursor display style
92#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
93pub enum CursorStyle {
94    /// Block cursor █
95    #[default]
96    Block,
97    /// Underline cursor _
98    Underline,
99    /// Vertical bar cursor |
100    Bar,
101}
102
103/// Actions from terminal input
104#[derive(Clone, Debug, PartialEq, Eq)]
105pub enum TerminalAction {
106    /// User submitted command
107    Submit(String),
108    /// User cancelled
109    Cancel,
110    /// Tab completion requested
111    TabComplete(String),
112}