Add configuration option to disable hinter (#2403) (#2405)

* Add configuration option to disable hinter

* Move hint configuration inside line_editor
This commit is contained in:
Amit Dev
2020-08-27 15:45:55 +10:00
committed by GitHub
parent 7702d683c7
commit 39f402c8cc
2 changed files with 19 additions and 5 deletions

View File

@ -820,7 +820,9 @@ pub async fn cli(
let cwd = context.shell_manager.path();
rl.set_helper(Some(crate::shell::Helper::new(context.clone())));
let hinter = init_hinter(&config);
rl.set_helper(Some(crate::shell::Helper::new(context.clone(), hinter)));
let colored_prompt = {
if let Some(prompt) = config.get("prompt") {
@ -967,6 +969,18 @@ pub async fn cli(
Ok(())
}
fn init_hinter(config: &IndexMap<String, Value>) -> Option<rustyline::hint::HistoryHinter> {
// Show hints unless explicitly disabled in config
if let Some(line_editor_vars) = config.get("line_editor") {
for (idx, value) in line_editor_vars.row_entries() {
if idx == "show_hints" && value.expect_string() == "false" {
return None;
}
}
}
Some(rustyline::hint::HistoryHinter {})
}
fn chomp_newline(s: &str) -> &str {
if s.ends_with('\n') {
&s[..s.len() - 1]