aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-07-12 02:40:06 -0400
committerJesse Luehrs <doy@tozt.net>2019-07-12 02:40:06 -0400
commitff8d2f2d6f0efc363d3681c3908923ed8a1daf4b (patch)
treedade576802e24ad8f19b807cc0c9affdbcfc332b
parent55569f3db98e4214537cbad03d0024ba12aa8f73 (diff)
downloadnbsh-old-ff8d2f2d6f0efc363d3681c3908923ed8a1daf4b.tar.gz
nbsh-old-ff8d2f2d6f0efc363d3681c3908923ed8a1daf4b.zip
adjust the readline api a bit
-rw-r--r--src/lib.rs1
-rw-r--r--src/readline.rs22
-rw-r--r--src/repl.rs2
-rw-r--r--src/tui.rs2
4 files changed, 20 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4f3e3df..cfcc4a8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,6 +6,7 @@
#![allow(clippy::if_not_else)]
// match_same_arms is buggy, doesn't notice differences due to match arm order
#![allow(clippy::match_same_arms)]
+#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::multiple_crate_versions)]
#![allow(clippy::similar_names)]
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>,
diff --git a/src/repl.rs b/src/repl.rs
index c370fcf..7f4c10d 100644
--- a/src/repl.rs
+++ b/src/repl.rs
@@ -51,7 +51,7 @@ pub fn repl() {
}
fn read() -> impl futures::future::Future<Item = String, Error = Error> {
- crate::readline::readline("$ ", true)
+ crate::readline::readline()
.into_future()
.flatten()
.context(Read)
diff --git a/src/tui.rs b/src/tui.rs
index 82733c8..49f7d6f 100644
--- a/src/tui.rs
+++ b/src/tui.rs
@@ -40,7 +40,7 @@ impl Tui {
}
fn read() -> Result<crate::readline::Readline> {
- crate::readline::readline("$ ", true).context(Read)
+ crate::readline::readline().context(Read)
}
fn eval(