Skip to main content

UI

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

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl UI for DummyUI

Source§

impl UI for MockUI

Source§

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