mirror of
https://github.com/nushell/nushell.git
synced 2025-01-23 14:50:09 +01:00
Only trim prompt (#876)
* Only trim the output for prompts * Only remove the last newline
This commit is contained in:
parent
4c029d2545
commit
e91d8655c6
@ -124,7 +124,6 @@ impl Command for Open {
|
|||||||
RawStream::new(
|
RawStream::new(
|
||||||
Box::new(BufferedReader { input: buf_reader }),
|
Box::new(BufferedReader { input: buf_reader }),
|
||||||
ctrlc,
|
ctrlc,
|
||||||
false,
|
|
||||||
call_span,
|
call_span,
|
||||||
),
|
),
|
||||||
call_span,
|
call_span,
|
||||||
|
@ -362,7 +362,6 @@ fn response_to_buffer(
|
|||||||
input: buffered_input,
|
input: buffered_input,
|
||||||
}),
|
}),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.ctrlc.clone(),
|
||||||
false,
|
|
||||||
span,
|
span,
|
||||||
),
|
),
|
||||||
span,
|
span,
|
||||||
|
@ -243,7 +243,7 @@ impl ExternalCommand {
|
|||||||
let receiver = ChannelReceiver::new(rx);
|
let receiver = ChannelReceiver::new(rx);
|
||||||
|
|
||||||
Ok(PipelineData::RawStream(
|
Ok(PipelineData::RawStream(
|
||||||
RawStream::new(Box::new(receiver), output_ctrlc, true, head),
|
RawStream::new(Box::new(receiver), output_ctrlc, head),
|
||||||
head,
|
head,
|
||||||
None,
|
None,
|
||||||
))
|
))
|
||||||
|
@ -72,7 +72,6 @@ impl Command for Table {
|
|||||||
.into_iter(),
|
.into_iter(),
|
||||||
),
|
),
|
||||||
ctrlc,
|
ctrlc,
|
||||||
false,
|
|
||||||
head,
|
head,
|
||||||
),
|
),
|
||||||
head,
|
head,
|
||||||
@ -189,7 +188,6 @@ impl Command for Table {
|
|||||||
stream,
|
stream,
|
||||||
}),
|
}),
|
||||||
ctrlc,
|
ctrlc,
|
||||||
false,
|
|
||||||
head,
|
head,
|
||||||
),
|
),
|
||||||
head,
|
head,
|
||||||
|
@ -150,8 +150,6 @@ impl PipelineData {
|
|||||||
PipelineData::RawStream(s, ..) => {
|
PipelineData::RawStream(s, ..) => {
|
||||||
let mut items = vec![];
|
let mut items = vec![];
|
||||||
|
|
||||||
let trim_end = s.trim_end;
|
|
||||||
|
|
||||||
for val in s {
|
for val in s {
|
||||||
match val {
|
match val {
|
||||||
Ok(val) => {
|
Ok(val) => {
|
||||||
@ -173,10 +171,6 @@ impl PipelineData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if trim_end {
|
|
||||||
output = output.trim_end().to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ pub struct RawStream {
|
|||||||
pub leftover: Vec<u8>,
|
pub leftover: Vec<u8>,
|
||||||
pub ctrlc: Option<Arc<AtomicBool>>,
|
pub ctrlc: Option<Arc<AtomicBool>>,
|
||||||
pub is_binary: bool,
|
pub is_binary: bool,
|
||||||
pub trim_end: bool,
|
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +19,6 @@ impl RawStream {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
stream: Box<dyn Iterator<Item = Result<Vec<u8>, ShellError>> + Send + 'static>,
|
stream: Box<dyn Iterator<Item = Result<Vec<u8>, ShellError>> + Send + 'static>,
|
||||||
ctrlc: Option<Arc<AtomicBool>>,
|
ctrlc: Option<Arc<AtomicBool>>,
|
||||||
trim_end: bool,
|
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -28,7 +26,6 @@ impl RawStream {
|
|||||||
leftover: vec![],
|
leftover: vec![],
|
||||||
ctrlc,
|
ctrlc,
|
||||||
is_binary: false,
|
is_binary: false,
|
||||||
trim_end,
|
|
||||||
span,
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,16 +43,10 @@ impl RawStream {
|
|||||||
pub fn into_string(self) -> Result<String, ShellError> {
|
pub fn into_string(self) -> Result<String, ShellError> {
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
let trim_end = self.trim_end;
|
|
||||||
|
|
||||||
for item in self {
|
for item in self {
|
||||||
output.push_str(&item?.as_string()?);
|
output.push_str(&item?.as_string()?);
|
||||||
}
|
}
|
||||||
|
|
||||||
if trim_end {
|
|
||||||
output = output.trim_end().to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,6 @@ fn main() -> Result<()> {
|
|||||||
RawStream::new(
|
RawStream::new(
|
||||||
Box::new(BufferedReader::new(buf_reader)),
|
Box::new(BufferedReader::new(buf_reader)),
|
||||||
Some(ctrlc),
|
Some(ctrlc),
|
||||||
true,
|
|
||||||
redirect_stdin.span,
|
redirect_stdin.span,
|
||||||
),
|
),
|
||||||
redirect_stdin.span,
|
redirect_stdin.span,
|
||||||
|
@ -59,6 +59,7 @@ fn get_prompt_string(
|
|||||||
.and_then(|v| match v {
|
.and_then(|v| match v {
|
||||||
Value::Block { val: block_id, .. } => {
|
Value::Block { val: block_id, .. } => {
|
||||||
let block = engine_state.get_block(block_id);
|
let block = engine_state.get_block(block_id);
|
||||||
|
// Use eval_subexpression to force a redirection of output, so we can use everything in prompt
|
||||||
eval_subexpression(
|
eval_subexpression(
|
||||||
engine_state,
|
engine_state,
|
||||||
stack,
|
stack,
|
||||||
@ -70,6 +71,7 @@ fn get_prompt_string(
|
|||||||
Value::String { val: source, .. } => {
|
Value::String { val: source, .. } => {
|
||||||
let mut working_set = StateWorkingSet::new(engine_state);
|
let mut working_set = StateWorkingSet::new(engine_state);
|
||||||
let (block, _) = parse(&mut working_set, None, source.as_bytes(), true);
|
let (block, _) = parse(&mut working_set, None, source.as_bytes(), true);
|
||||||
|
// Use eval_subexpression to force a redirection of output, so we can use everything in prompt
|
||||||
eval_subexpression(
|
eval_subexpression(
|
||||||
engine_state,
|
engine_state,
|
||||||
stack,
|
stack,
|
||||||
@ -80,7 +82,24 @@ fn get_prompt_string(
|
|||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.and_then(|pipeline_data| pipeline_data.collect_string("", config).ok())
|
.and_then(|pipeline_data| {
|
||||||
|
let output = pipeline_data.collect_string("", config).ok();
|
||||||
|
|
||||||
|
match output {
|
||||||
|
Some(mut x) => {
|
||||||
|
// Just remove the very last newline.
|
||||||
|
if x.ends_with('\n') {
|
||||||
|
x.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if x.ends_with('\r') {
|
||||||
|
x.pop();
|
||||||
|
}
|
||||||
|
Some(x)
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_prompt<'prompt>(
|
pub(crate) fn update_prompt<'prompt>(
|
||||||
|
Loading…
Reference in New Issue
Block a user