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