forked from extern/nushell
Refactor ansi stripping into nu-utils
functions (#6966)
Allows use of slightly optimized variants that check if they have to use the heavier vte parser. Tries to avoid unnnecessary allocations. Initial performance characteristics proven out in #4378. Also reduces boilerplate with right-ward drift.
This commit is contained in:
committed by
GitHub
parent
b9195c2668
commit
2c4048eb43
@ -67,10 +67,7 @@ impl Command for Cd {
|
||||
let path_val = {
|
||||
if let Some(path) = path_val {
|
||||
Some(Spanned {
|
||||
item: match strip_ansi_escapes::strip(&path.item) {
|
||||
Ok(item) => String::from_utf8(item).unwrap_or(path.item),
|
||||
Err(_) => path.item,
|
||||
},
|
||||
item: nu_utils::strip_ansi_string_unlikely(path.item),
|
||||
span: path.span,
|
||||
})
|
||||
} else {
|
||||
|
@ -73,10 +73,7 @@ impl Command for Cp {
|
||||
let src: Spanned<String> = call.req(engine_state, stack, 0)?;
|
||||
let src = {
|
||||
Spanned {
|
||||
item: match strip_ansi_escapes::strip(&src.item) {
|
||||
Ok(item) => String::from_utf8(item).unwrap_or(src.item),
|
||||
Err(_) => src.item,
|
||||
},
|
||||
item: nu_utils::strip_ansi_string_unlikely(src.item),
|
||||
span: src.span,
|
||||
}
|
||||
};
|
||||
|
@ -86,10 +86,7 @@ impl Command for Ls {
|
||||
let pattern_arg = {
|
||||
if let Some(path) = pattern_arg {
|
||||
Some(Spanned {
|
||||
item: match strip_ansi_escapes::strip(&path.item) {
|
||||
Ok(item) => String::from_utf8(item).unwrap_or(path.item),
|
||||
Err(_) => path.item,
|
||||
},
|
||||
item: nu_utils::strip_ansi_string_unlikely(path.item),
|
||||
span: path.span,
|
||||
})
|
||||
} else {
|
||||
|
@ -66,10 +66,7 @@ impl Command for Mv {
|
||||
let spanned_source: Spanned<String> = call.req(engine_state, stack, 0)?;
|
||||
let spanned_source = {
|
||||
Spanned {
|
||||
item: match strip_ansi_escapes::strip(&spanned_source.item) {
|
||||
Ok(item) => String::from_utf8(item).unwrap_or(spanned_source.item),
|
||||
Err(_) => spanned_source.item,
|
||||
},
|
||||
item: nu_utils::strip_ansi_string_unlikely(spanned_source.item),
|
||||
span: spanned_source.span,
|
||||
}
|
||||
};
|
||||
|
@ -53,10 +53,7 @@ impl Command for Open {
|
||||
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,
|
||||
},
|
||||
item: nu_utils::strip_ansi_string_unlikely(path_val.item),
|
||||
span: path_val.span,
|
||||
})
|
||||
} else {
|
||||
|
@ -143,10 +143,7 @@ fn rm(
|
||||
|
||||
for (idx, path) in targets.clone().into_iter().enumerate() {
|
||||
let corrected_path = Spanned {
|
||||
item: match strip_ansi_escapes::strip(&path.item) {
|
||||
Ok(item) => String::from_utf8(item).unwrap_or(path.item),
|
||||
Err(_) => path.item,
|
||||
},
|
||||
item: nu_utils::strip_ansi_string_unlikely(path.item),
|
||||
span: path.span,
|
||||
};
|
||||
let _ = std::mem::replace(&mut targets[idx], corrected_path);
|
||||
|
Reference in New Issue
Block a user