mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Reset ansi more often when showing errors (#425)
This commit is contained in:
parent
df5ac9b71c
commit
8cf4402e6c
101
Cargo.lock
generated
101
Cargo.lock
generated
@ -396,6 +396,16 @@ dependencies = [
|
||||
"chrono",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono-tz"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2554a3155fec064362507487171dcc4edc3df60cb10f3a1fb10ed8094822b120"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"parse-zoneinfo",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono-tz"
|
||||
version = "0.6.0"
|
||||
@ -669,6 +679,19 @@ version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
||||
|
||||
[[package]]
|
||||
name = "dtparse"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13276c5dbd7f365e00efe6631242772fe6615e1899df84d1f6ce3ae7b48209f6"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"chrono-tz 0.5.3",
|
||||
"lazy_static",
|
||||
"num-traits",
|
||||
"rust_decimal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dunce"
|
||||
version = "1.0.2"
|
||||
@ -1434,10 +1457,11 @@ dependencies = [
|
||||
"calamine",
|
||||
"chrono",
|
||||
"chrono-humanize",
|
||||
"chrono-tz",
|
||||
"chrono-tz 0.6.0",
|
||||
"crossterm",
|
||||
"csv",
|
||||
"dialoguer",
|
||||
"dtparse",
|
||||
"eml-parser",
|
||||
"glob",
|
||||
"ical",
|
||||
@ -1454,7 +1478,7 @@ dependencies = [
|
||||
"nu-protocol",
|
||||
"nu-table",
|
||||
"nu-term-grid",
|
||||
"num",
|
||||
"num 0.4.0",
|
||||
"polars",
|
||||
"rand",
|
||||
"rayon",
|
||||
@ -1581,17 +1605,42 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36"
|
||||
dependencies = [
|
||||
"num-bigint 0.2.6",
|
||||
"num-complex 0.2.4",
|
||||
"num-integer",
|
||||
"num-iter",
|
||||
"num-rational 0.2.4",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"num-complex",
|
||||
"num-bigint 0.4.3",
|
||||
"num-complex 0.4.0",
|
||||
"num-integer",
|
||||
"num-iter",
|
||||
"num-rational",
|
||||
"num-rational 0.4.0",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
@ -1606,6 +1655,16 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.4.0"
|
||||
@ -1636,6 +1695,18 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-bigint 0.2.6",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.0"
|
||||
@ -1643,7 +1714,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-bigint",
|
||||
"num-bigint 0.4.3",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
@ -1861,7 +1932,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cc4488d2f2d6b901bb6e5728e58966013a272cae48861070b676215a79b4a99"
|
||||
dependencies = [
|
||||
"arrow2",
|
||||
"num",
|
||||
"num 0.4.0",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
@ -1878,7 +1949,7 @@ dependencies = [
|
||||
"hashbrown",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"num",
|
||||
"num 0.4.0",
|
||||
"num_cpus",
|
||||
"polars-arrow",
|
||||
"prettytable-rs",
|
||||
@ -1905,7 +1976,7 @@ dependencies = [
|
||||
"lexical",
|
||||
"memchr",
|
||||
"memmap2",
|
||||
"num",
|
||||
"num 0.4.0",
|
||||
"num_cpus",
|
||||
"polars-arrow",
|
||||
"polars-core",
|
||||
@ -2203,6 +2274,18 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust_decimal"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a93c95e3d5c1d997e6e4ba9bda898f4e1d73934cd05510c972f10087d0ef00c1"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"lazy_static",
|
||||
"num 0.2.1",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.21"
|
||||
|
@ -6,9 +6,9 @@ use thiserror::Error;
|
||||
/// forwards most methods, except for `.source_code()`, which we provide.
|
||||
#[derive(Error)]
|
||||
#[error("{0}")]
|
||||
struct CliError<'src>(
|
||||
&'src (dyn miette::Diagnostic + Send + Sync + 'static),
|
||||
&'src StateWorkingSet<'src>,
|
||||
pub struct CliError<'src>(
|
||||
pub &'src (dyn miette::Diagnostic + Send + Sync + 'static),
|
||||
pub &'src StateWorkingSet<'src>,
|
||||
);
|
||||
|
||||
impl std::fmt::Debug for CliError<'_> {
|
||||
@ -44,10 +44,3 @@ impl<'src> miette::Diagnostic for CliError<'src> {
|
||||
Some(&self.1)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report_error(
|
||||
working_set: &StateWorkingSet,
|
||||
error: &(dyn miette::Diagnostic + Send + Sync + 'static),
|
||||
) {
|
||||
eprintln!("Error: {:?}", CliError(error, working_set));
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ mod syntax_highlight;
|
||||
mod validation;
|
||||
|
||||
pub use completions::NuCompleter;
|
||||
pub use errors::report_error;
|
||||
pub use errors::CliError;
|
||||
pub use prompt::NushellPrompt;
|
||||
pub use syntax_highlight::NuHighlighter;
|
||||
pub use validation::NuValidator;
|
||||
|
27
src/main.rs
27
src/main.rs
@ -6,7 +6,7 @@ use dialoguer::{
|
||||
Select,
|
||||
};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use nu_cli::{report_error, NuCompleter, NuHighlighter, NuValidator, NushellPrompt};
|
||||
use nu_cli::{CliError, NuCompleter, NuHighlighter, NuValidator, NushellPrompt};
|
||||
use nu_command::create_default_context;
|
||||
use nu_engine::eval_block;
|
||||
use nu_parser::parse;
|
||||
@ -457,12 +457,6 @@ fn eval_source(
|
||||
|
||||
report_error(&working_set, &err);
|
||||
|
||||
// reset vt processing, aka ansi because illbehaved externals can break it
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _ = enable_vt_processing();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -477,11 +471,6 @@ fn eval_source(
|
||||
|
||||
report_error(&working_set, &err);
|
||||
|
||||
// reset vt processing, aka ansi because illbehaved externals can break it
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _ = enable_vt_processing();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -490,7 +479,7 @@ fn eval_source(
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn enable_vt_processing() -> Result<(), ShellError> {
|
||||
pub fn enable_vt_processing() -> Result<(), ShellError> {
|
||||
pub const ENABLE_PROCESSED_OUTPUT: u32 = 0x0001;
|
||||
pub const ENABLE_VIRTUAL_TERMINAL_PROCESSING: u32 = 0x0004;
|
||||
// let mask = ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
@ -509,3 +498,15 @@ fn enable_vt_processing() -> Result<(), ShellError> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn report_error(
|
||||
working_set: &StateWorkingSet,
|
||||
error: &(dyn miette::Diagnostic + Send + Sync + 'static),
|
||||
) {
|
||||
eprintln!("Error: {:?}", CliError(error, working_set));
|
||||
// reset vt processing, aka ansi because illbehaved externals can break it
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _ = enable_vt_processing();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user