make cd, cp, ls, mv, open and rm automatically strip ansi codes (#6220)

* make `cd`, `cp`, `ls`, `mv`, `open` and `rm` automatically strip ansi escape code

* fix nu-cli test

* fix nu-cli test 2

* fix nu-cli test 3

* remove `include-ansi` arg

* fix test
This commit is contained in:
pwygab
2022-08-04 19:59:20 +08:00
committed by GitHub
parent 7c49a42b68
commit 3b809b38e8
11 changed files with 151 additions and 1 deletions

View File

@ -50,6 +50,20 @@ impl Command for Open {
let ctrlc = engine_state.ctrlc.clone();
let path = call.opt::<Spanned<String>>(engine_state, stack, 0)?;
let path = {
if let Some(path_val) = path {
Some(Spanned {
item: match strip_ansi_escapes::strip(&path_val.item) {
Ok(item) => String::from_utf8(item).unwrap_or(path_val.item),
Err(_) => path_val.item,
},
span: path_val.span,
})
} else {
path
}
};
let path = if let Some(path) = path {
path
} else {