display/tui.rs
1use crossterm::style::Colors;
2
3use super::{color_mode::ColorMode, Size};
4use crate::DisplayError;
5
6/// An interface that describes interactions with a terminal interface.
7pub trait Tui {
8 /// Get the supported color mode.
9 fn get_color_mode(&self) -> ColorMode;
10
11 /// Reset the terminal interface to a default state.
12 ///
13 /// # Errors
14 ///
15 /// Errors if the Tui cannot be reset for any reason. In general this should not error, and if
16 /// this does generate an error, the Tui should be considered to be in a non-recoverable state.
17 fn reset(&mut self) -> Result<(), DisplayError>;
18
19 /// Flush the contents printed to the terminal interface.
20 ///
21 /// # Errors
22 ///
23 /// Errors if the Tui cannot be flushed for any reason. In general this should not error, and if
24 /// this does generate an error, the Tui should be considered to be in a non-recoverable state.
25 fn flush(&mut self) -> Result<(), DisplayError>;
26
27 /// Print text to the terminal interface.
28 ///
29 /// # Errors
30 ///
31 /// Errors if the Tui cannot be printed to for any reason. In general this should not error, and
32 /// if this does generate an error, the Tui should be considered to be in a non-recoverable
33 /// state.
34 fn print(&mut self, s: &str) -> Result<(), DisplayError>;
35
36 /// Set the color attribute of text printed to the terminal interface.
37 ///
38 /// # Errors
39 ///
40 /// Errors if the Tui cannot set the color for any reason. In general this should not error, and
41 /// if this does generate an error, the Tui should be considered to be in a non-recoverable
42 /// state.
43 fn set_color(&mut self, colors: Colors) -> Result<(), DisplayError>;
44
45 /// Set the dimmed style attribute of text printed to the terminal interface.
46 ///
47 /// # Errors
48 ///
49 /// Errors if the Tui cannot set the dimmed state for any reason. In general this should not
50 /// error, and if this does generate an error, the Tui should be considered to be in a
51 /// non-recoverable state.
52 fn set_dim(&mut self, dim: bool) -> Result<(), DisplayError>;
53
54 /// Set the underlined style attribute of text printed to the terminal interface.
55 ///
56 /// # Errors
57 ///
58 /// Errors if the Tui cannot set the underline state for any reason. In general this should not
59 /// error, and if this does generate an error, the Tui should be considered to be in a
60 /// non-recoverable state.
61 fn set_underline(&mut self, underline: bool) -> Result<(), DisplayError>;
62
63 /// Set the reversed style attribute of text printed to the terminal interface.
64 ///
65 /// # Errors
66 ///
67 /// Errors if the Tui cannot set the reversed state for any reason. In general this should not
68 /// error, and if this does generate an error, the Tui should be considered to be in a
69 /// non-recoverable state.
70 fn set_reverse(&mut self, reverse: bool) -> Result<(), DisplayError>;
71
72 /// Get the number of columns and rows of the terminal interface.
73 fn get_size(&self) -> Size;
74
75 /// Move the cursor position `x` characters from the start of the line.
76 ///
77 /// # Errors
78 ///
79 /// Errors if the Tui cannot move to a column for any reason. In general this should not error,
80 /// and if this does generate an error, the Tui should be considered to be in a non-recoverable
81 /// state.
82 fn move_to_column(&mut self, x: u16) -> Result<(), DisplayError>;
83
84 /// Move the cursor to the next line.
85 ///
86 /// # Errors
87 ///
88 /// Errors if the Tui cannot move to the next line for any reason. In general this should not
89 /// error, and if this does generate an error, the Tui should be considered to be in a
90 /// non-recoverable state.
91 fn move_next_line(&mut self) -> Result<(), DisplayError>;
92
93 /// Start the terminal interface interactions.
94 ///
95 /// # Errors
96 ///
97 /// Errors if the Tui cannot move to a started state any reason. In general this should not
98 /// error,and if this does generate an error, the Tui should be considered to be in a
99 /// non-recoverable state.
100 fn start(&mut self) -> Result<(), DisplayError>;
101
102 /// End the terminal interface interactions.
103 ///
104 /// # Errors
105 ///
106 /// Errors if the Tui cannot move to an ended state any reason. In general this should not
107 /// error,and if this does generate an error, the Tui should be considered to be in a
108 /// non-recoverable state.
109 fn end(&mut self) -> Result<(), DisplayError>;
110}