mirror of
https://github.com/nushell/nushell.git
synced 2024-11-21 16:03:19 +01:00
fix ansi bleed over on right prompt (#14357)
# Description In certain situations, we had ansi bleed on the right prompt. This PR fixes that by prefixing the right prompt with an ansi reset `\x1b[0m`. This PR also adds some --log-level warn logging so we can see the ansi escapes that form the prompts. Closes https://github.com/nushell/nushell/issues/14268
This commit is contained in:
parent
ea6493c041
commit
029c586717
@ -1,5 +1,5 @@
|
|||||||
use crate::NushellPrompt;
|
use crate::NushellPrompt;
|
||||||
use log::trace;
|
use log::{trace, warn};
|
||||||
use nu_engine::ClosureEvalOnce;
|
use nu_engine::ClosureEvalOnce;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
@ -80,8 +80,13 @@ fn get_prompt_string(
|
|||||||
})
|
})
|
||||||
.and_then(|pipeline_data| {
|
.and_then(|pipeline_data| {
|
||||||
let output = pipeline_data.collect_string("", config).ok();
|
let output = pipeline_data.collect_string("", config).ok();
|
||||||
|
let ansi_output = output.map(|mut x| {
|
||||||
|
// Always reset the color at the start of the right prompt
|
||||||
|
// to ensure there is no ansi bleed over
|
||||||
|
if x.is_empty() && prompt == PROMPT_COMMAND_RIGHT {
|
||||||
|
x.insert_str(0, "\x1b[0m")
|
||||||
|
};
|
||||||
|
|
||||||
output.map(|mut x| {
|
|
||||||
// Just remove the very last newline.
|
// Just remove the very last newline.
|
||||||
if x.ends_with('\n') {
|
if x.ends_with('\n') {
|
||||||
x.pop();
|
x.pop();
|
||||||
@ -91,7 +96,11 @@ fn get_prompt_string(
|
|||||||
x.pop();
|
x.pop();
|
||||||
}
|
}
|
||||||
x
|
x
|
||||||
})
|
});
|
||||||
|
// Let's keep this for debugging purposes with nu --log-level warn
|
||||||
|
warn!("{}:{}:{} {:?}", file!(), line!(), column!(), ansi_output);
|
||||||
|
|
||||||
|
ansi_output
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user