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>,
impl<I> ReadLine<I>where
I: ApplicationInfo<ContentId = ReadLineId>,
Sourcepub fn new<B: BindingMachine<TerminalKey, Action<I>, RepeatType, EditContext> + 'static>(
bindings: B,
) -> Result<Self, Error>
pub fn new<B: BindingMachine<TerminalKey, Action<I>, RepeatType, EditContext> + 'static>( bindings: B, ) -> Result<Self, Error>
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}Sourcepub fn readline(&mut self, prompt: Option<String>) -> ReadLineResult<I>
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§
impl<I> Freeze for ReadLine<I>where
<I as ApplicationInfo>::Store: Freeze,
<I as ApplicationInfo>::Action: Freeze,
<I as ApplicationInfo>::WindowId: Freeze,
impl<I = ReadLineInfo> !RefUnwindSafe for ReadLine<I>
impl<I = ReadLineInfo> !Send for ReadLine<I>
impl<I = ReadLineInfo> !Sync for ReadLine<I>
impl<I> Unpin for ReadLine<I>where
<I as ApplicationInfo>::Store: Unpin,
<I as ApplicationInfo>::Action: Unpin,
I: Unpin,
<I as ApplicationInfo>::WindowId: Unpin,
impl<I> UnsafeUnpin for ReadLine<I>where
<I as ApplicationInfo>::Store: UnsafeUnpin,
<I as ApplicationInfo>::Action: UnsafeUnpin,
<I as ApplicationInfo>::WindowId: UnsafeUnpin,
impl<I = ReadLineInfo> !UnwindSafe for ReadLine<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more