forked from extern/nushell
respect use_ansi_coloring configuration (#7912)
# Description Use the `use_ansi_coloring` configuration point to decide whether the output will have colors, where possible. Related: https://github.com/nushell/nushell/issues/7676  - [x] `grid -c` - [x] `perf()` # User-Facing Changes _(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)_ # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -52,6 +52,7 @@ pub fn read_plugin_file(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
engine_state.get_config().use_ansi_coloring,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ pub fn evaluate_repl(
|
||||
entire_start_time: Instant,
|
||||
) -> Result<()> {
|
||||
use reedline::{FileBackedHistory, Reedline, Signal};
|
||||
let use_color = engine_state.get_config().use_ansi_coloring;
|
||||
|
||||
// Guard against invocation without a connected terminal.
|
||||
// reedline / crossterm event polling will fail without a connected tty
|
||||
@ -72,6 +73,7 @@ pub fn evaluate_repl(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
// seed env vars
|
||||
@ -91,7 +93,14 @@ pub fn evaluate_repl(
|
||||
.map(i64::from)
|
||||
.unwrap_or(0);
|
||||
engine_state.history_session_id = hist_sesh;
|
||||
perf("setup reedline", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"setup reedline",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
let config = engine_state.get_config();
|
||||
|
||||
@ -115,7 +124,14 @@ pub fn evaluate_repl(
|
||||
};
|
||||
line_editor = line_editor.with_history(history);
|
||||
};
|
||||
perf("setup history", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"setup history",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
let sys = sysinfo::System::new();
|
||||
@ -136,6 +152,7 @@ pub fn evaluate_repl(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
if let Some(s) = prerun_command {
|
||||
@ -161,21 +178,42 @@ pub fn evaluate_repl(
|
||||
if let Err(err) = engine_state.merge_env(stack, cwd) {
|
||||
report_error_new(engine_state, &err);
|
||||
}
|
||||
perf("merge env", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"merge env",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
//Reset the ctrl-c handler
|
||||
if let Some(ctrlc) = &mut engine_state.ctrlc {
|
||||
ctrlc.store(false, Ordering::SeqCst);
|
||||
}
|
||||
perf("reset ctrlc", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"reset ctrlc",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
// Reset the SIGQUIT handler
|
||||
if let Some(sig_quit) = engine_state.get_sig_quit() {
|
||||
sig_quit.store(false, Ordering::SeqCst);
|
||||
}
|
||||
perf("reset sig_quit", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"reset sig_quit",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
let config = engine_state.get_config();
|
||||
@ -198,6 +236,7 @@ pub fn evaluate_repl(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
@ -218,7 +257,14 @@ pub fn evaluate_repl(
|
||||
.with_partial_completions(config.partial_completions)
|
||||
.with_ansi_colors(config.use_ansi_coloring)
|
||||
.with_cursor_config(cursor_config);
|
||||
perf("reedline builder", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"reedline builder",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
let style_computer = StyleComputer::from_config(engine_state, stack);
|
||||
|
||||
@ -238,6 +284,7 @@ pub fn evaluate_repl(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
@ -246,7 +293,14 @@ pub fn evaluate_repl(
|
||||
report_error(&working_set, &e);
|
||||
Reedline::create()
|
||||
});
|
||||
perf("reedline menus", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"reedline menus",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
let buffer_editor = if !config.buffer_editor.is_empty() {
|
||||
@ -275,6 +329,7 @@ pub fn evaluate_repl(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
@ -283,7 +338,14 @@ pub fn evaluate_repl(
|
||||
warn!("Failed to sync history: {}", e);
|
||||
}
|
||||
}
|
||||
perf("sync_history", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"sync_history",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
// Changing the line editor based on the found keybindings
|
||||
@ -307,7 +369,14 @@ pub fn evaluate_repl(
|
||||
line_editor
|
||||
}
|
||||
};
|
||||
perf("keybindings", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"keybindings",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
// Right before we start our prompt and take input from the user,
|
||||
@ -317,7 +386,14 @@ pub fn evaluate_repl(
|
||||
report_error_new(engine_state, &err);
|
||||
}
|
||||
}
|
||||
perf("pre-prompt hook", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"pre-prompt hook",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
// Next, check all the environment variables they ask for
|
||||
@ -328,12 +404,26 @@ pub fn evaluate_repl(
|
||||
{
|
||||
report_error_new(engine_state, &error)
|
||||
}
|
||||
perf("env-change hook", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"env-change hook",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
start_time = std::time::Instant::now();
|
||||
let config = engine_state.get_config();
|
||||
let prompt = prompt_update::update_prompt(config, engine_state, stack, &mut nu_prompt);
|
||||
perf("update_prompt", start_time, file!(), line!(), column!());
|
||||
perf(
|
||||
"update_prompt",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
entry_num += 1;
|
||||
|
||||
@ -587,6 +677,7 @@ pub fn evaluate_repl(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
perf(
|
||||
@ -595,6 +686,7 @@ pub fn evaluate_repl(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -297,6 +297,7 @@ pub fn eval_source(
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
engine_state.get_config().use_ansi_coloring,
|
||||
);
|
||||
|
||||
true
|
||||
|
Reference in New Issue
Block a user