-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add repl test && add config & some debug cmd
- Loading branch information
1 parent
6cf37e8
commit 59d1d22
Showing
6 changed files
with
280 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::path::Path; | ||
|
||
use rustyline::error::ReadlineError; | ||
|
||
use super::completer::REPLCompleter; | ||
|
||
pub trait TermEditor { | ||
fn set_helper(&mut self, helper: Option<REPLCompleter>); | ||
fn readline(&mut self, prompt: &str) -> Result<String, ReadlineError>; | ||
/// Load the history from the specified file. | ||
fn load_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<(), ReadlineError>; | ||
|
||
/// Save the history in the specified file. | ||
fn save_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<(), ReadlineError>; | ||
|
||
/// Append new entries in the specified file. | ||
fn append_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<(), ReadlineError>; | ||
|
||
/// Add a new entry in the history. | ||
fn add_history_entry<S: AsRef<str> + Into<String>>( | ||
&mut self, | ||
line: S, | ||
) -> Result<bool, ReadlineError>; | ||
|
||
#[cfg(test)] | ||
fn assert_err(&mut self, _err: bool) { | ||
// noop | ||
} | ||
} | ||
|
||
pub fn default_editor() -> rustyline::Editor<REPLCompleter, rustyline::history::FileHistory> { | ||
rustyline::Editor::<REPLCompleter, rustyline::history::FileHistory>::new().unwrap() | ||
} | ||
|
||
impl TermEditor for rustyline::Editor<REPLCompleter, rustyline::history::FileHistory> { | ||
fn set_helper(&mut self, helper: Option<REPLCompleter>) { | ||
self.set_helper(helper); | ||
} | ||
|
||
fn readline(&mut self, prompt: &str) -> Result<String, ReadlineError> { | ||
self.readline(prompt) | ||
} | ||
|
||
fn load_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<(), ReadlineError> { | ||
self.load_history(path) | ||
} | ||
|
||
fn save_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<(), ReadlineError> { | ||
self.save_history(path) | ||
} | ||
|
||
fn append_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<(), ReadlineError> { | ||
self.append_history(path) | ||
} | ||
|
||
fn add_history_entry<S: AsRef<str> + Into<String>>( | ||
&mut self, | ||
line: S, | ||
) -> Result<bool, ReadlineError> { | ||
self.add_history_entry(line) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.