pub trait UI {
// Required methods
fn print_message(&mut self, data: &str) -> Result<()>;
fn print_command_documentation(&mut self) -> Result<()>;
fn get_command(
&mut self,
ed: &Ed<'_>,
prefix: Option<char>
) -> Result<String>;
fn get_input(
&mut self,
ed: &Ed<'_>,
terminator: char
) -> Result<Vec<String>>;
fn print_selection(
&mut self,
ed: &Ed<'_>,
selection: (usize, usize),
numbered: bool,
literal: bool
) -> Result<()>;
fn lock_ui(&mut self) -> UILock<'_>;
fn unlock_ui(&mut self);
// Provided method
fn print_commands(&mut self) -> Result<()> { ... }
}
Expand description
The UI trait used to abstract all common UI operations
Required Methods§
sourcefn print_message(&mut self, data: &str) -> Result<()>
fn print_message(&mut self, data: &str) -> Result<()>
A basic print for errors and other information messages
sourcefn print_command_documentation(&mut self) -> Result<()>
fn print_command_documentation(&mut self) -> Result<()>
Print commands documentation
Print usage documentation for the commands. You can use the std::concat
macro to add your own documentation to the commands documentation string
at add_ed::messages::COMMANDS_DOCUMENTATION
.
sourcefn get_command(&mut self, ed: &Ed<'_>, prefix: Option<char>) -> Result<String>
fn get_command(&mut self, ed: &Ed<'_>, prefix: Option<char>) -> Result<String>
Get a command for parsing and execution
- Ed passed in for interactive viewing and status printouts. Ignore if unused.
- Prefix is printed at start of the line if given. Ignore if unsuited for your UI.
- Must return a single line to be parsed, trimming optional
sourcefn get_input(&mut self, ed: &Ed<'_>, terminator: char) -> Result<Vec<String>>
fn get_input(&mut self, ed: &Ed<'_>, terminator: char) -> Result<Vec<String>>
Get input lines until given character is entered alone on a line
- Ed passed in for interactive viewing and status printouts. Ignore if unused.
- Must return a vector newline terminated strings and not return the terminating line
sourcefn print_selection(
&mut self,
ed: &Ed<'_>,
selection: (usize, usize),
numbered: bool,
literal: bool
) -> Result<()>
fn print_selection( &mut self, ed: &Ed<'_>, selection: (usize, usize), numbered: bool, literal: bool ) -> Result<()>
Print the given selection with the given options
Depending on UI this may mean changing viewport settings and moving to given selection.
- Ed passed in for path based highlighting and status printouts. Ignore if unused.
- Separate selection passed in since the selection to print isn’t saved to state until after printing.
Provided Methods§
sourcefn print_commands(&mut self) -> Result<()>
fn print_commands(&mut self) -> Result<()>
Print a listing of the commands with short descriptions
Default implementation uses self.print_message()
to print the const
string exported at add_ed::messages::COMMANDS_LISTING
.