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:
whitequark 2017-08-17 15:46:18 +00:00
parent 164f2a988e
commit dda41ddb32

View file

@ -52,6 +52,18 @@ fn main_interactive() {
use std::rc::Rc;
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>>);
impl<Term: Terminal> Completer<Term> for RinkCompleter {
@ -203,8 +215,6 @@ fn main_interactive() {
};
let ctx = Rc::new(RefCell::new(ctx));
let completer = RinkCompleter(ctx.clone());
let mut rl = Reader::new("rink").unwrap();
rl.set_prompt("> ");
rl.set_completer(Rc::new(completer));
let mut hpath = rink::config_dir();