mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 17:05:03 +02:00
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
@ -3,7 +3,6 @@ use nu_protocol::{
|
||||
ast::Call, ast::CellPath, engine::Command, engine::EngineState, engine::Stack, Category,
|
||||
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||
};
|
||||
use strip_ansi_escapes::strip;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SubCommand;
|
||||
@ -79,15 +78,7 @@ fn operate(
|
||||
fn action(input: &Value, command_span: &Span) -> Value {
|
||||
match input {
|
||||
Value::String { val, span } => {
|
||||
let stripped_string = {
|
||||
if let Ok(bytes) = strip(&val) {
|
||||
String::from_utf8_lossy(&bytes).to_string()
|
||||
} else {
|
||||
val.to_string()
|
||||
}
|
||||
};
|
||||
|
||||
Value::string(stripped_string, *span)
|
||||
Value::string(nu_utils::strip_ansi_likely(val).to_string(), *span)
|
||||
}
|
||||
other => {
|
||||
let got = format!("value is {}, not string", other.get_type());
|
||||
|
Reference in New Issue
Block a user