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
impl Readline
Sourcepub fn new(prompt: String) -> Result<(Self, SharedWriter), ReadlineError>
pub fn new(prompt: String) -> Result<(Self, SharedWriter), ReadlineError>
Create a new Readline
instance with an associated
SharedWriter
Sourcepub fn update_prompt(&mut self, prompt: &str) -> Result<(), ReadlineError>
pub fn update_prompt(&mut self, prompt: &str) -> Result<(), ReadlineError>
Change the prompt
Sourcepub fn clear(&mut self) -> Result<(), ReadlineError>
pub fn clear(&mut self) -> Result<(), ReadlineError>
Clear the screen
Sourcepub fn set_max_history(&mut self, max_size: usize)
pub fn set_max_history(&mut self, max_size: usize)
Set maximum history length. The default length is 1000.
Sourcepub fn should_print_line_on(&mut self, enter: bool, control_c: bool)
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
.
Sourcepub fn flush(&mut self) -> Result<(), ReadlineError>
pub fn flush(&mut self) -> Result<(), ReadlineError>
Flush all writers to terminal and erase the prompt string
Sourcepub async fn readline(&mut self) -> Result<ReadlineEvent, ReadlineError>
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
Sourcepub fn add_history_entry(&mut self, entry: String) -> Option<()>
pub fn add_history_entry(&mut self, entry: String) -> Option<()>
Add a line to the input history
Sourcepub fn get_history_entries(&self) -> &VecDeque<String>
pub fn get_history_entries(&self) -> &VecDeque<String>
Returns the entries of the history in the order they were added in.
Sourcepub fn set_history_entries(&mut self, entries: impl IntoIterator<Item = String>)
pub fn set_history_entries(&mut self, entries: impl IntoIterator<Item = String>)
Replaces the current history.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clears the current history.