pub struct Chaos<'a> { /* private fields */ }Expand description
The primary struct of chaos-engine.
This struct must be instantiated once to start using chaos-engine and its features.
§Examples
use chaos_engine::{Chaos, ChaosOptions};
let stdout = std::io::stdout();
let options = ChaosOptions::default();
let mut chaos = Chaos::new(stdout, options);Implementations§
Source§impl<'a> Chaos<'a>
impl<'a> Chaos<'a>
Sourcepub fn new(stdout: Stdout, options: ChaosOptions<'a>) -> Self
pub fn new(stdout: Stdout, options: ChaosOptions<'a>) -> Self
Instantiate the chaos engine with specified options.
It enables raw mode where input must be handled manually.
Sourcepub fn clear_terminal(&mut self)
pub fn clear_terminal(&mut self)
Completely clears the terminal screen of any visible text.
§Panics
Panics in the case of a terminal error.
Sourcepub fn get_input(&mut self, page: &mut Page) -> Result<String, Error>
pub fn get_input(&mut self, page: &mut Page) -> Result<String, Error>
Gets input from the user.
It takes a page to resize in the event of a terminal resize, then writes the input prompt on the last line of the terminal, overwriting anything on that line.
§Examples
use chaos_engine::{Chaos, ChaosOptions, Page};
let mut page = Page::new();
let mut chaos = Chaos::new(std::io::stdout(), ChaosOptions::default());
loop {
chaos.clear_terminal();
chaos.print(&mut page);
let input = chaos.get_input(&mut page).unwrap();
if input == "exit" {
chaos.alternate_screen(false);
break;
}
// do stuff here
}§Panics
This can panic when it fails to read the terminal events.
Sourcepub fn move_cursor(&mut self, x: u16, y: u16)
pub fn move_cursor(&mut self, x: u16, y: u16)
Moves the cursor to the specified X and Y positions.
§Panics
Panics in the case of a terminal error.
Sourcepub fn alternate_screen(&mut self, on: bool)
pub fn alternate_screen(&mut self, on: bool)
Enables and disables the terminal’s alternate screen.
An alternate screen is a separate buffer. On entering an alternate screen, the terminal gets completely cleared to allow for program output, and once the screen is disabled, the original buffer is restored.
§Panics
Panics in the case of a terminal error.
Sourcepub fn print(&mut self, page: &mut Page)
pub fn print(&mut self, page: &mut Page)
Prints the given Page onto the screen, respecting the paddings and word wrapping.
Calls Page::align() on the given Page to apply the word wrapping before
printing it to the output.
Sourcepub fn dimensions(&self) -> &Vector2<u16>
pub fn dimensions(&self) -> &Vector2<u16>
Returns the last stored dimensions of the terminal.
Sourcepub fn paddings(&self) -> &ChaosPaddings
pub fn paddings(&self) -> &ChaosPaddings
Returns the current paddings.
Sourcepub fn update_paddings(
&mut self,
padding: PaddingType,
new_padding: Vector2<u16>,
)
pub fn update_paddings( &mut self, padding: PaddingType, new_padding: Vector2<u16>, )
Updates the paddings to new values. Any active page must be printed again to take effect.