Skip to main content

ReadLine

Struct ReadLine 

Source
pub struct ReadLine<I = ReadLineInfo>
where I: ApplicationInfo<ContentId = ReadLineId>,
{ /* private fields */ }
Expand description

Simple editor for collecting user input.

Implementations§

Source§

impl<I> ReadLine<I>
where I: ApplicationInfo<ContentId = ReadLineId>,

Source

pub fn new<B: BindingMachine<TerminalKey, Action<I>, RepeatType, EditContext> + 'static>( bindings: B, ) -> Result<Self, Error>
where I::Store: Default,

Create a new instance.

Examples found in repository?
examples/read-loop.rs (line 59)
54fn create_readline(mode: MixedChoice) -> Result<ReadLine, std::io::Error> {
55    match mode {
56        MixedChoice::Emacs => {
57            let mut emacs = EmacsMachine::empty();
58            EmacsBindings::default().submit_on_enter().setup(&mut emacs);
59            ReadLine::new(emacs)
60        },
61        _ => {
62            let mut vi = VimMachine::<TerminalKey, ReadLineInfo>::empty();
63            VimBindings::default().submit_on_enter().setup(&mut vi);
64            ReadLine::new(vi)
65        },
66    }
67}
Source

pub fn readline(&mut self, prompt: Option<String>) -> ReadLineResult<I>

Prompt the user for input.

Examples found in repository?
examples/read-loop.rs (line 19)
12fn main() -> Result<(), std::io::Error> {
13    let mode = select_mode();
14    let mut rl = create_readline(mode)?;
15
16    println!("Reading input in {mode:?} mode; 'q' or 'quit' quits the loop.");
17
18    loop {
19        match rl.readline(Some("> ".to_string())) {
20            Ok(s) => {
21                match s.trim() {
22                    "q" | "quit" => {
23                        return Ok(());
24                    },
25                    _ => {
26                        println!("User typed: {:?}", s);
27                    },
28                }
29            },
30            Err(e) => {
31                // Print out editor error messages.
32                println!("{}", e);
33            },
34        }
35    }
36}

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.
Source§

impl<T> Any for T
where T: Any,