diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-07-12 02:40:06 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-07-12 02:40:06 -0400 |
commit | ff8d2f2d6f0efc363d3681c3908923ed8a1daf4b (patch) | |
tree | dade576802e24ad8f19b807cc0c9affdbcfc332b /src/readline.rs | |
parent | 55569f3db98e4214537cbad03d0024ba12aa8f73 (diff) | |
download | nbsh-old-ff8d2f2d6f0efc363d3681c3908923ed8a1daf4b.tar.gz nbsh-old-ff8d2f2d6f0efc363d3681c3908923ed8a1daf4b.zip |
adjust the readline api a bit
Diffstat (limited to 'src/readline.rs')
-rw-r--r-- | src/readline.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/readline.rs b/src/readline.rs index a8c1526..f878d50 100644 --- a/src/readline.rs +++ b/src/readline.rs @@ -24,8 +24,8 @@ pub enum Error { pub type Result<T> = std::result::Result<T, Error>; -pub fn readline(prompt: &str, echo: bool) -> Result<Readline> { - Readline::new(prompt, echo) +pub fn readline() -> Result<Readline> { + Readline::new() } pub struct Readline { @@ -44,15 +44,15 @@ struct ReadlineState { } impl Readline { - fn new(prompt: &str, echo: bool) -> Result<Self> { + pub fn new() -> Result<Self> { let screen = crossterm::RawScreen::into_raw_mode().context(IntoRawMode)?; Ok(Self { reader: None, state: ReadlineState { - prompt: prompt.to_string(), - echo, + prompt: String::from("$ "), + echo: true, buffer: String::new(), cursor: 0, wrote_prompt: false, @@ -61,6 +61,18 @@ impl Readline { }) } + #[allow(dead_code)] + pub fn prompt(mut self, prompt: &str) -> Self { + self.state.prompt = prompt.to_string(); + self + } + + #[allow(dead_code)] + pub fn echo(mut self, echo: bool) -> Self { + self.state.echo = echo; + self + } + fn with_reader<F, T>(&mut self, f: F) -> Result<T> where F: FnOnce(&KeyReader, &mut ReadlineState) -> Result<T>, |