mirror of
https://github.com/nushell/nushell.git
synced 2025-04-18 10:18:17 +02:00
Use writer from host instead of always std::err (#3112)
This commit is contained in:
parent
079e575cac
commit
f83ff0e47d
@ -79,7 +79,7 @@ pub async fn run_script_file(
|
|||||||
syncer.sync_path_vars(ctx);
|
syncer.sync_path_vars(ctx);
|
||||||
|
|
||||||
if let Err(reason) = syncer.autoenv(ctx) {
|
if let Err(reason) = syncer.autoenv(ctx) {
|
||||||
print_err(reason, &Text::from(""));
|
print_err(reason, &Text::from(""), ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = register_plugins(ctx);
|
let _ = register_plugins(ctx);
|
||||||
@ -107,7 +107,7 @@ pub async fn cli(mut context: EvaluationContext) -> Result<(), Box<dyn Error>> {
|
|||||||
syncer.sync_path_vars(ctx);
|
syncer.sync_path_vars(ctx);
|
||||||
|
|
||||||
if let Err(reason) = syncer.autoenv(ctx) {
|
if let Err(reason) = syncer.autoenv(ctx) {
|
||||||
print_err(reason, &Text::from(""));
|
print_err(reason, &Text::from(""), ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = configure_ctrl_c(ctx);
|
let _ = configure_ctrl_c(ctx);
|
||||||
@ -199,14 +199,14 @@ pub async fn cli(mut context: EvaluationContext) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
crate::cli::print_err(e, &Text::from(prompt_line));
|
crate::cli::print_err(e, &Text::from(prompt_line), &context);
|
||||||
context.clear_errors();
|
context.clear_errors();
|
||||||
|
|
||||||
"> ".to_string()
|
"> ".to_string()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
crate::cli::print_err(e, &Text::from(prompt_line));
|
crate::cli::print_err(e, &Text::from(prompt_line), &context);
|
||||||
context.clear_errors();
|
context.clear_errors();
|
||||||
|
|
||||||
"> ".to_string()
|
"> ".to_string()
|
||||||
@ -274,7 +274,7 @@ pub async fn cli(mut context: EvaluationContext) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Err(reason) = syncer.autoenv(ctx) {
|
if let Err(reason) = syncer.autoenv(ctx) {
|
||||||
print_err(reason, &Text::from(""));
|
print_err(reason, &Text::from(""), ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = configure_rustyline_editor(&mut rl, config);
|
let _ = configure_rustyline_editor(&mut rl, config);
|
||||||
@ -296,9 +296,7 @@ pub async fn cli(mut context: EvaluationContext) -> Result<(), Box<dyn Error>> {
|
|||||||
rl.add_history_entry(&line);
|
rl.add_history_entry(&line);
|
||||||
let _ = rl.save_history(&history_path);
|
let _ = rl.save_history(&history_path);
|
||||||
|
|
||||||
context.with_host(|_host| {
|
print_err(err, &Text::from(session_text.clone()), &context);
|
||||||
print_err(err, &Text::from(session_text.clone()));
|
|
||||||
});
|
|
||||||
|
|
||||||
maybe_print_errors(&context, Text::from(session_text.clone()));
|
maybe_print_errors(&context, Text::from(session_text.clone()));
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ pub fn maybe_print_errors(context: &EvaluationContext, source: Text) -> bool {
|
|||||||
let error = errors[0].clone();
|
let error = errors[0].clone();
|
||||||
*errors = vec![];
|
*errors = vec![];
|
||||||
|
|
||||||
crate::script::print_err(error, &source);
|
crate::script::print_err(error, &source, context);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -33,15 +33,13 @@ fn chomp_newline(s: &str) -> &str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_err(err: ShellError, source: &Text) {
|
pub fn print_err(err: ShellError, source: &Text, ctx: &EvaluationContext) {
|
||||||
if let Some(diag) = err.into_diagnostic() {
|
if let Some(diag) = err.into_diagnostic() {
|
||||||
let source = source.to_string();
|
let source = source.to_string();
|
||||||
let mut files = codespan_reporting::files::SimpleFiles::new();
|
let mut files = codespan_reporting::files::SimpleFiles::new();
|
||||||
files.add("shell", source);
|
files.add("shell", source);
|
||||||
|
|
||||||
let writer = codespan_reporting::term::termcolor::StandardStream::stderr(
|
let writer = ctx.host.lock().err_termcolor();
|
||||||
codespan_reporting::term::termcolor::ColorChoice::Always,
|
|
||||||
);
|
|
||||||
let config = codespan_reporting::term::Config::default();
|
let config = codespan_reporting::term::Config::default();
|
||||||
|
|
||||||
let _ = std::panic::catch_unwind(move || {
|
let _ = std::panic::catch_unwind(move || {
|
||||||
@ -260,7 +258,7 @@ pub async fn run_script_standalone(
|
|||||||
|
|
||||||
LineResult::Error(line, err) => {
|
LineResult::Error(line, err) => {
|
||||||
context.with_host(|_host| {
|
context.with_host(|_host| {
|
||||||
print_err(err, &Text::from(line.clone()));
|
print_err(err, &Text::from(line.clone()), &context);
|
||||||
});
|
});
|
||||||
|
|
||||||
maybe_print_errors(&context, Text::from(line));
|
maybe_print_errors(&context, Text::from(line));
|
||||||
|
Loading…
Reference in New Issue
Block a user