ConsoleRenderer

Trait ConsoleRenderer 

Source
pub trait ConsoleRenderer: Send + Sync {
    // Required methods
    fn should_use_renderer(
        &self,
        stream_features: &dyn ConsoleOutputFeatures,
        environment_prefix: &str,
    ) -> bool;
    fn supports_ansi(&self) -> bool;
    fn default_ps1(&self) -> String;
    fn update_ps1(&self, new_ps1: String);
    fn clear_input(&self, term_width: u16) -> String;
    fn clear_task_list(&self, task_list_size: usize) -> String;
    fn should_pause_log_events(&self, provider: &dyn InputProvider) -> bool;
    fn render_message(
        &self,
        app_name: &'static str,
        log: SuperConsoleLogMessage,
        term_width: u16,
    ) -> Result<String, LisaError>;
    fn render_input(
        &self,
        app_name: &'static str,
        provider: &dyn InputProvider,
        term_width: u16,
    ) -> Result<String, LisaError>;
    fn rerender_tasks(
        &self,
        new_task_events: &[TaskEvent],
        current_task_states: &FnvHashMap<GloballyUniqueTaskId, (DateTime<Utc>, String, LisaTaskStatus)>,
        tasks_running_since: Option<DateTime<Utc>>,
        term_height: u16,
    ) -> Result<String, LisaError>;
    fn on_input(
        &self,
        event: TerminalInputEvent,
        provider: &dyn InputProvider,
    ) -> Result<String, LisaError>;
}
Expand description

An arbitrary structure that is capable of rendering log lines.

Required Methods§

Source

fn should_use_renderer( &self, stream_features: &dyn ConsoleOutputFeatures, environment_prefix: &str, ) -> bool

Get a renderer if it is compatible, and should be used with a set of stream features.

The first console renderer that returns true will be used.

§Parameters
  • features: The current features for this particular stream.
  • environment_prefix: a prefix to apply to environment variables, usually the app name. This makes it so you can have multiple CLI tools that are each controlled with things like: ${APP_NAME}_LOG_FORMAT. Lets say your app name was “sprig”, in this case the environment prefix would be: “SPRIG_”.
Source

fn supports_ansi(&self) -> bool

Return if this renderer supports ‘cursor movement’, using ANSI escape codes or similar to move the cursor.

This will enable left/right arrow movement on the associated input provider.

Source

fn default_ps1(&self) -> String

Get the default PS1 to use for this renderer, if none was provided.

Source

fn update_ps1(&self, new_ps1: String)

Update the ‘PS1’, or characters the get rendered before typing in a command.

Source

fn clear_input(&self, term_width: u16) -> String

Clear any previously rendered input line if one was rendered.

Source

fn clear_task_list(&self, task_list_size: usize) -> String

Clear any previous rendered tasks in our task list.

Source

fn should_pause_log_events(&self, provider: &dyn InputProvider) -> bool

A flag used to ‘pause’ rendering log events for awhile.

This will prevent ConsoleRenderer::render_message calls for your renderer until this returns false. This should ideally only be used for renderers that need to pause rendering while user input is happening because ASCII codes for erasing aren’t supported.

Source

fn render_message( &self, app_name: &'static str, log: SuperConsoleLogMessage, term_width: u16, ) -> Result<String, LisaError>

Render a log message.

This message will be printed directly to it’s source, whether that be standard out, or standard error. This can span multiple lines.

§Errors

If we can’t format the log message into a string, or some other processing error dependening on the renderer.

Source

fn render_input( &self, app_name: &'static str, provider: &dyn InputProvider, term_width: u16, ) -> Result<String, LisaError>

Render the console ‘input’ line for a particular provider.

It is the job of this method to query the provider, and determine how to render the users input in the terminal.

§Errors

If we can’t format the input line into a string, or other processing error occurs.

Source

fn rerender_tasks( &self, new_task_events: &[TaskEvent], current_task_states: &FnvHashMap<GloballyUniqueTaskId, (DateTime<Utc>, String, LisaTaskStatus)>, tasks_running_since: Option<DateTime<Utc>>, term_height: u16, ) -> Result<String, LisaError>

Re-render the task (you can assume it has been erased by this time it is called).

Passed in will be all new events that have happened (incase you want to render any task updates), along with the current task states after all new_task_events have been applied.

§Errors

If there is any error related to rendering tasks, usually a formatting error but depends on the specific renderer.

Source

fn on_input( &self, event: TerminalInputEvent, provider: &dyn InputProvider, ) -> Result<String, LisaError>

Do a ‘quick render’ of any sort of input, or handle an input on any kind.

This should be as immediate as possible to reduce any sort of latency from the users who are typing.

§Errors

If we can’t format the input line into a string, or other processing error occurs.

Implementors§