pub trait Backend {
Show 13 methods
// Required methods
fn poll_event(&mut self) -> Option<Event>;
fn set_title(&mut self, title: String);
fn refresh(&mut self);
fn has_colors(&self) -> bool;
fn screen_size(&self) -> XY<usize>;
fn move_to(&self, pos: XY<usize>);
fn print(&self, text: &str);
fn clear(&self, color: Color);
fn set_color(&self, colors: ColorPair) -> ColorPair;
fn set_effect(&self, effect: Effect);
fn unset_effect(&self, effect: Effect);
// Provided methods
fn is_persistent(&self) -> bool { ... }
fn name(&self) -> &str { ... }
}
Expand description
Trait defining the required methods to be a backend.
A backend is the interface between the abstract view tree and the actual input/output, like a terminal.
It usually delegates the work to a terminal-handling library like ncurses
or termion, or it can entirely simulate a terminal and show it as a
graphical window (BearLibTerminal
).
When creating a new cursive tree with Cursive::new()
, you will need to
provide a backend initializer - usually their init()
function.
Backends are responsible for handling input and converting it to Event
.
Input must be non-blocking, it will be polled regularly.
Required Methods§
Sourcefn poll_event(&mut self) -> Option<Event>
fn poll_event(&mut self) -> Option<Event>
Polls the backend for any input.
Should return immediately:
None
if no event is currently available.Some(event)
for each event to process.
Sourcefn set_title(&mut self, title: String)
fn set_title(&mut self, title: String)
Sets the title for the backend.
This usually sets the terminal window title.
Sourcefn refresh(&mut self)
fn refresh(&mut self)
Refresh the screen.
This will be called each frame after drawing has been done.
A backend could, for example, buffer any print command, and apply everything when refresh() is called.
Sourcefn has_colors(&self) -> bool
fn has_colors(&self) -> bool
Should return true
if this backend supports colors.
Sourcefn screen_size(&self) -> XY<usize>
fn screen_size(&self) -> XY<usize>
Returns the screen size.
Sourcefn move_to(&self, pos: XY<usize>)
fn move_to(&self, pos: XY<usize>)
Move the cursor to the given cell.
The next call to print()
will start at this place.
Sourcefn print(&self, text: &str)
fn print(&self, text: &str)
Print some text at the current cursor.
The cursor will then be moved past the end of the printed text.
Sourcefn set_color(&self, colors: ColorPair) -> ColorPair
fn set_color(&self, colors: ColorPair) -> ColorPair
Starts using a new color.
This should return the previously active color.
Any call to print_at
from now on should use the given color.
Sourcefn set_effect(&self, effect: Effect)
fn set_effect(&self, effect: Effect)
Enables the given effect.
Any call to print_at
from now on should use the given effect.
Sourcefn unset_effect(&self, effect: Effect)
fn unset_effect(&self, effect: Effect)
Disables the given effect.
Provided Methods§
Sourcefn is_persistent(&self) -> bool
fn is_persistent(&self) -> bool
Returns true
if the backend has persistent output.
If true, this means that output stays there between calls to
refresh()
, so only delta needs to be sent.
Implementors§
impl Backend for cursive::backends::crossterm::Backend
crossterm-backend
only.impl Backend for cursive::backends::curses::pan::Backend
pancurses-backend
only.impl Backend for cursive::backends::puppet::Backend
impl Backend for cursive::backends::termion::Backend
termion-backend
only.