Struct Readline

Source
pub struct Readline { /* private fields */ }
Expand description

Structure for reading lines of input from a terminal while lines are output to the terminal concurrently.

Terminal input is retrieved by calling Readline::readline(), which returns each complete line of input once the user presses Enter.

Each Readline instance is associated with one or more SharedWriter instances. Lines written to an associated SharedWriter are output while retrieving input with readline() or by calling flush().

Implementations§

Source§

impl Readline

Source

pub fn new(prompt: String) -> Result<(Self, SharedWriter), ReadlineError>

Create a new Readline instance with an associated SharedWriter

Source

pub fn update_prompt(&mut self, prompt: &str) -> Result<(), ReadlineError>

Change the prompt

Source

pub fn clear(&mut self) -> Result<(), ReadlineError>

Clear the screen

Source

pub fn set_max_history(&mut self, max_size: usize)

Set maximum history length. The default length is 1000.

Source

pub fn should_print_line_on(&mut self, enter: bool, control_c: bool)

Set whether the input line should remain on the screen after events.

If enter is true, then when the user presses “Enter”, the prompt and the text they entered will remain on the screen, and the cursor will move to the next line. If enter is false, the prompt & input will be erased instead.

control_c similarly controls the behavior for when the user presses Ctrl-C.

The default value for both settings is true.

Source

pub fn flush(&mut self) -> Result<(), ReadlineError>

Flush all writers to terminal and erase the prompt string

Source

pub async fn readline(&mut self) -> Result<ReadlineEvent, ReadlineError>

Polling function for readline, manages all input and output. Returns either an Readline Event or an Error

Source

pub fn add_history_entry(&mut self, entry: String) -> Option<()>

Add a line to the input history

Source

pub fn get_history_entries(&self) -> &VecDeque<String>

Returns the entries of the history in the order they were added in.

Source

pub fn set_history_entries(&mut self, entries: impl IntoIterator<Item = String>)

Replaces the current history.

Source

pub fn clear_history(&mut self)

Clears the current history.

Trait Implementations§

Source§

impl Drop for Readline

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.