turn down the volume a little bit (#4412)

This commit is contained in:
Darren Schroeder 2022-02-10 15:22:39 -06:00 committed by GitHub
parent 2e3b2a48ee
commit 0e5f4d88c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 52 deletions

View file

@ -1,6 +1,4 @@
use crate::is_perf_true;
use crossterm::event::{KeyCode, KeyModifiers};
use log::info;
use nu_color_config::lookup_ansi_color_style;
use nu_protocol::{extract_value, Config, ParsedKeybinding, ShellError, Span, Type, Value};
use reedline::{
@ -66,12 +64,7 @@ pub(crate) fn add_completion_menu(line_editor: Reedline, config: &Config) -> Ree
None => completion_menu,
};
let ret_val = line_editor.with_menu(Box::new(completion_menu));
if is_perf_true() {
info!("add_completion_menu {}:{}:{}", file!(), line!(), column!());
}
ret_val
line_editor.with_menu(Box::new(completion_menu))
}
// Creates an input object for the history menu based on the dictionary
@ -127,12 +120,7 @@ pub(crate) fn add_history_menu(line_editor: Reedline, config: &Config) -> Reedli
None => history_menu,
};
let ret_val = line_editor.with_menu(Box::new(history_menu));
if is_perf_true() {
info!("add_history_menu {}:{}:{}", file!(), line!(), column!());
}
ret_val
line_editor.with_menu(Box::new(history_menu))
}
fn add_menu_keybindings(keybindings: &mut Keybindings) {
@ -165,10 +153,6 @@ fn add_menu_keybindings(keybindings: &mut Keybindings) {
KeyCode::BackTab,
ReedlineEvent::MenuPrevious,
);
if is_perf_true() {
info!("add_menu_keybindings {}:{}:{}", file!(), line!(), column!());
}
}
pub enum KeybindingsMode {
@ -202,15 +186,6 @@ pub(crate) fn create_keybindings(config: &Config) -> Result<KeybindingsMode, She
}
}
if is_perf_true() {
info!(
"create_keybindings (emacs) {}:{}:{}",
file!(),
line!(),
column!()
);
}
Ok(KeybindingsMode::Emacs(keybindings))
}
_ => {
@ -228,15 +203,6 @@ pub(crate) fn create_keybindings(config: &Config) -> Result<KeybindingsMode, She
}
}
if is_perf_true() {
info!(
"create_keybindings (vi) {}:{}:{}",
file!(),
line!(),
column!()
);
}
Ok(KeybindingsMode::Vi {
insert_keybindings,
normal_keybindings,
@ -335,10 +301,6 @@ fn add_keybinding(
keybindings.add_binding(modifier, keycode, event);
if is_perf_true() {
info!("add_keybinding {}:{}:{}", file!(), line!(), column!());
}
Ok(())
}
@ -406,10 +368,6 @@ fn parse_event(value: Value, config: &Config) -> Result<ReedlineEvent, ShellErro
}
};
if is_perf_true() {
info!("parse_event (record) {}:{}:{}", file!(), line!(), column!());
}
Ok(event)
}
Value::List { vals, .. } => {
@ -423,10 +381,6 @@ fn parse_event(value: Value, config: &Config) -> Result<ReedlineEvent, ShellErro
.map(|value| parse_event(value, config))
.collect::<Result<Vec<ReedlineEvent>, ShellError>>()?;
if is_perf_true() {
info!("parse_event (list) {}:{}:{}", file!(), line!(), column!());
}
if until_found {
Ok(ReedlineEvent::UntilFound(events))
} else {

View file

@ -41,9 +41,17 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
},
);
if is_perf_true() {
info!("read_plugin_file {}:{}:{}", file!(), line!(), column!());
}
#[cfg(feature = "plugin")]
config_files::read_plugin_file(engine_state, &mut stack);
if is_perf_true() {
info!("read_config_file {}:{}:{}", file!(), line!(), column!());
}
config_files::read_config_file(engine_state, &mut stack);
let history_path = config_files::create_history_path();
@ -66,6 +74,15 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
// Ok(())
// })?;
if is_perf_true() {
info!(
"translate environment vars {}:{}:{}",
file!(),
line!(),
column!()
);
}
// Translate environment variables from Strings to Values
if let Some(e) = convert_env_values(engine_state, &stack, &config) {
let working_set = StateWorkingSet::new(engine_state);
@ -82,6 +99,15 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
);
loop {
if is_perf_true() {
info!(
"load config each loop {}:{}:{}",
file!(),
line!(),
column!()
);
}
let config = match stack.get_config() {
Ok(config) => config,
Err(e) => {
@ -97,6 +123,10 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
ctrlc.store(false, Ordering::SeqCst);
}
if is_perf_true() {
info!("setup line editor {}:{}:{}", file!(), line!(), column!());
}
let mut line_editor = Reedline::create()
.into_diagnostic()?
.with_highlighter(Box::new(NuHighlighter {
@ -111,14 +141,30 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
.with_quick_completions(config.quick_completions)
.with_ansi_colors(config.use_ansi_coloring);
if is_perf_true() {
info!("setup reedline {}:{}:{}", file!(), line!(), column!());
}
line_editor = add_completion_menu(line_editor, &config);
line_editor = add_history_menu(line_editor, &config);
if is_perf_true() {
info!("setup colors {}:{}:{}", file!(), line!(), column!());
}
//FIXME: if config.use_ansi_coloring is false then we should
// turn off the hinter but I don't see any way to do that yet.
let color_hm = get_color_config(&config);
if is_perf_true() {
info!(
"setup history and hinter {}:{}:{}",
file!(),
line!(),
column!()
);
}
line_editor = if let Some(history_path) = history_path.clone() {
let history = std::fs::read_to_string(&history_path);
if history.is_ok() {
@ -141,6 +187,10 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
line_editor
};
if is_perf_true() {
info!("setup keybindings {}:{}:{}", file!(), line!(), column!());
}
// Changing the line editor based on the found keybindings
line_editor = match reedline_config::create_keybindings(&config) {
Ok(keybindings) => match keybindings {
@ -164,22 +214,22 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
};
if is_perf_true() {
info!("setup line editor {}:{}:{}", file!(), line!(), column!());
info!("prompt_update {}:{}:{}", file!(), line!(), column!());
}
let prompt = prompt_update::update_prompt(&config, engine_state, &stack, &mut nu_prompt);
entry_num += 1;
if is_perf_true() {
info!(
"finished prompt update {}:{}:{}",
"finished setup, starting repl {}:{}:{}",
file!(),
line!(),
column!()
);
}
entry_num += 1;
let input = line_editor.read_line(prompt);
match input {
Ok(Signal::Success(s)) => {