allow find to respect ls_colors (#834)

This commit is contained in:
Darren Schroeder 2022-01-23 19:23:03 -06:00 committed by GitHub
parent f82e2fbac6
commit d4fb95a98c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View file

@ -2,7 +2,8 @@ use nu_engine::{eval_block, CallExt};
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{CaptureBlock, Command, EngineState, Stack}, engine::{CaptureBlock, Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span,
SyntaxShape, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -87,9 +88,9 @@ impl Command for Find {
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let span = call.head; let span = call.head;
let ctrlc = engine_state.ctrlc.clone(); let ctrlc = engine_state.ctrlc.clone();
let engine_state = engine_state.clone(); let engine_state = engine_state.clone();
let metadata = input.metadata();
match call.get_flag::<CaptureBlock>(&engine_state, stack, "predicate")? { match call.get_flag::<CaptureBlock>(&engine_state, stack, "predicate")? {
Some(predicate) => { Some(predicate) => {
@ -114,7 +115,12 @@ impl Command for Find {
stack.add_var(var_id, value.clone()); stack.add_var(var_id, value.clone());
} }
eval_block(&engine_state, &mut stack, &block, PipelineData::new(span)) eval_block(
&engine_state,
&mut stack,
&block,
PipelineData::new_with_metadata(metadata.clone(), span),
)
.map_or(false, |pipeline_data| { .map_or(false, |pipeline_data| {
pipeline_data.into_value(span).is_true() pipeline_data.into_value(span).is_true()
}) })
@ -124,7 +130,7 @@ impl Command for Find {
} }
None => { None => {
let terms = call.rest::<Value>(&engine_state, stack, 0)?; let terms = call.rest::<Value>(&engine_state, stack, 0)?;
input.filter( let pipe = input.filter(
move |value| { move |value| {
terms.iter().any(|term| match value { terms.iter().any(|term| match value {
Value::Bool { .. } Value::Bool { .. }
@ -152,7 +158,13 @@ impl Command for Find {
}) })
}, },
ctrlc, ctrlc,
) )?;
match metadata {
Some(m) => {
Ok(pipe.into_pipeline_data_with_metadata(m, engine_state.ctrlc.clone()))
}
None => Ok(pipe),
}
} }
} }
} }

View file

@ -56,6 +56,10 @@ impl PipelineData {
PipelineData::Value(Value::Nothing { span }, None) PipelineData::Value(Value::Nothing { span }, None)
} }
pub fn new_with_metadata(metadata: Option<PipelineMetadata>, span: Span) -> PipelineData {
PipelineData::Value(Value::Nothing { span }, metadata)
}
pub fn metadata(&self) -> Option<PipelineMetadata> { pub fn metadata(&self) -> Option<PipelineMetadata> {
match self { match self {
PipelineData::ListStream(_, x) => x.clone(), PipelineData::ListStream(_, x) => x.clone(),