Debian Codegraph @

helix-tui/src/backend/mod.rs

raw symbols SCIP
1 //! Provides interface for controlling the terminal
2
3 use std::io;
4
5 use crate::{buffer::Cell, terminal::Config};
6
7 use helix_view::{
8 graphics::{CursorKind, Rect},
9 theme::Color,
10 };
11
12 #[cfg(all(feature = "termina", not(windows)))]
13 mod termina;
14 #[cfg(all(feature = "termina", not(windows)))]
15 pub use self::termina::TerminaBackend;
16
17 #[cfg(all(feature = "termina", windows))]
18 mod crossterm;
19 #[cfg(all(feature = "termina", windows))]
20 pub use self::crossterm::CrosstermBackend;
21
22 mod test;
23 pub use self::test::TestBackend;
24
25 /// Representation of a terminal backend.
26 pub trait Backend {
27 /// Claims the terminal for TUI use.
28 fn claim(&mut self) -> Result<(), io::Error>;
29 /// Update terminal configuration.
30 fn reconfigure(&mut self, config: Config) -> Result<(), io::Error>;
31 /// Restores the terminal to a normal state, undoes `claim`
32 fn restore(&mut self) -> Result<(), io::Error>;
33 /// Draws styled text to the terminal
34 fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
35 where
36 I: Iterator<Item = (u16, u16, &'a Cell)>;
37 /// Hides the cursor
38 fn hide_cursor(&mut self) -> Result<(), io::Error>;
39 /// Sets the cursor to the given shape
40 fn show_cursor(&mut self, kind: CursorKind) -> Result<(), io::Error>;
41 /// Sets the cursor to the given position
42 fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error>;
43 /// Clears the terminal
44 fn clear(&mut self) -> Result<(), io::Error>;
45 /// Begins a synchronized-output frame (if the terminal supports it), so the
46 /// draw and cursor updates between `start_sync` and `end_sync` present as one
47 /// frame instead of flickering.
48 fn start_sync(&mut self) -> Result<(), io::Error>;
49 /// Ends the synchronized-output frame opened by `start_sync`.
50 fn end_sync(&mut self) -> Result<(), io::Error>;
51 /// Gets the size of the terminal in cells
52 fn size(&self) -> Result<Rect, io::Error>;
53 /// Flushes the terminal buffer
54 fn flush(&mut self) -> Result<(), io::Error>;
55 fn supports_true_color(&self) -> bool;
56 fn get_theme_mode(&self) -> Option<helix_view::theme::Mode>;
57 fn set_background_color(&mut self, color: Option<Color>) -> io::Result<()>;
58 }