mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
CLI: fall back to noninteractive-with-prompt.
Sometimes it's useful to delegate REPL input handling to another piece of software, e.g. SublimeREPL, but behave in the same way, e.g. showing the prompt, in all other ways.
This commit is contained in:
parent
164f2a988e
commit
dda41ddb32
1 changed files with 12 additions and 2 deletions
|
@ -52,6 +52,18 @@ fn main_interactive() {
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
let mut rl = match Reader::new("rink") {
|
||||||
|
Err(_) => {
|
||||||
|
// If we can't initialize linefeed on this terminal for some reason,
|
||||||
|
// e.g. it being a pipe instead of a tty, use the noninteractive version
|
||||||
|
// with prompt instead.
|
||||||
|
let stdin_handle = stdin();
|
||||||
|
return main_noninteractive(stdin_handle.lock(), true);
|
||||||
|
},
|
||||||
|
Ok(rl) => rl
|
||||||
|
};
|
||||||
|
rl.set_prompt("> ");
|
||||||
|
|
||||||
struct RinkCompleter(Rc<RefCell<Context>>);
|
struct RinkCompleter(Rc<RefCell<Context>>);
|
||||||
|
|
||||||
impl<Term: Terminal> Completer<Term> for RinkCompleter {
|
impl<Term: Terminal> Completer<Term> for RinkCompleter {
|
||||||
|
@ -203,8 +215,6 @@ fn main_interactive() {
|
||||||
};
|
};
|
||||||
let ctx = Rc::new(RefCell::new(ctx));
|
let ctx = Rc::new(RefCell::new(ctx));
|
||||||
let completer = RinkCompleter(ctx.clone());
|
let completer = RinkCompleter(ctx.clone());
|
||||||
let mut rl = Reader::new("rink").unwrap();
|
|
||||||
rl.set_prompt("> ");
|
|
||||||
rl.set_completer(Rc::new(completer));
|
rl.set_completer(Rc::new(completer));
|
||||||
|
|
||||||
let mut hpath = rink::config_dir();
|
let mut hpath = rink::config_dir();
|
||||||
|
|
Loading…
Reference in a new issue