Trait add_ed::ui::UI

source ·
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§

source

fn print_message(&mut self, data: &str) -> Result<()>

A basic print for errors and other information messages

source

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.

source

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
source

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
source

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.
source

fn lock_ui(&mut self) -> UILock<'_>

Prepare UI before handing down stdin/out/err to child process

The returned UIHandle should hold a mutable reference to its parent UI. Using that reference the UIHandle calls unlock_ui() when being dropped.

source

fn unlock_ui(&mut self)

Resume UI after lock_ui has been called

This method shouldn’t be called except by UIHandle’s Drop implementation.

Provided Methods§

source

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.

Implementors§

source§

impl UI for DummyUI

source§

impl UI for MockUI

source§

impl<'a> UI for ScriptedUI<'a>