Merge branch 'master' into master

This commit is contained in:
David Peter 2024-02-23 21:35:21 +01:00 committed by GitHub
commit 0080b043c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 23 deletions

View File

@ -7,6 +7,8 @@
- Fix long file name wrapping in header, see #2835 (@FilipRazek) - Fix long file name wrapping in header, see #2835 (@FilipRazek)
- Fix `NO_COLOR` support, see #2767 (@acuteenvy) - Fix `NO_COLOR` support, see #2767 (@acuteenvy)
- Fix handling of inputs with OSC ANSI escape sequences, see #2541 and #2544 (@eth-p) - Fix handling of inputs with OSC ANSI escape sequences, see #2541 and #2544 (@eth-p)
- Fix handling of inputs with combined ANSI color and attribute sequences, see #2185 and #2856 (@eth-p)
- Fix panel width when line 10000 wraps, see #2854 (@eth-p)
## Other ## Other
@ -22,13 +24,14 @@
- Pull in fix for unsafe-libyaml security advisory, see #2812 (@dtolnay) - Pull in fix for unsafe-libyaml security advisory, see #2812 (@dtolnay)
- Update git-version dependency to use Syn v2, see #2816 (@dtolnay) - Update git-version dependency to use Syn v2, see #2816 (@dtolnay)
- Update git2 dependency to v0.18.2, see #2852 (@eth-p) - Update git2 dependency to v0.18.2, see #2852 (@eth-p)
- Added auto detect syntax for `.jsonc` #2795 (@mxaddict) - Apply clippy fixes #2864 (@cyqsimon)
- Added auto detect syntax for `.aws/{config,credentials}` #2795 (@mxaddict)
## Syntaxes ## Syntaxes
- `cmd-help`: scope subcommands followed by other terms, and other misc improvements, see #2819 (@victor-gp) - `cmd-help`: scope subcommands followed by other terms, and other misc improvements, see #2819 (@victor-gp)
- Upgrade JQ syntax, see #2820 (@dependabot[bot]) - Upgrade JQ syntax, see #2820 (@dependabot[bot])
- Added auto detect syntax for `.jsonc` #2795 (@mxaddict)
- Added auto detect syntax for `.aws/{config,credentials}` #2795 (@mxaddict)
## Themes ## Themes

View File

@ -46,7 +46,7 @@ impl Decoration for LineNumberDecoration {
_printer: &InteractivePrinter, _printer: &InteractivePrinter,
) -> DecorationText { ) -> DecorationText {
if continuation { if continuation {
if line_number > self.cached_wrap_invalid_at { if line_number >= self.cached_wrap_invalid_at {
let new_width = self.cached_wrap.width + 1; let new_width = self.cached_wrap.width + 1;
return DecorationText { return DecorationText {
text: self.color.paint(" ".repeat(new_width)).to_string(), text: self.color.paint(" ".repeat(new_width)).to_string(),

View File

@ -24,9 +24,9 @@ impl AnsiStyle {
} }
} }
pub fn to_reset_sequence(&mut self) -> String { pub fn to_reset_sequence(&self) -> String {
match &mut self.attributes { match self.attributes {
Some(a) => a.to_reset_sequence(), Some(ref a) => a.to_reset_sequence(),
None => String::new(), None => String::new(),
} }
} }
@ -169,10 +169,10 @@ impl Attributes {
while let Some(p) = iter.next() { while let Some(p) = iter.next() {
match p { match p {
0 => self.sgr_reset(), 0 => self.sgr_reset(),
1 => self.bold = format!("\x1B[{}m", parameters), 1 => self.bold = "\x1B[1m".to_owned(),
2 => self.dim = format!("\x1B[{}m", parameters), 2 => self.dim = "\x1B[2m".to_owned(),
3 => self.italic = format!("\x1B[{}m", parameters), 3 => self.italic = "\x1B[3m".to_owned(),
4 => self.underline = format!("\x1B[{}m", parameters), 4 => self.underline = "\x1B[4m".to_owned(),
23 => self.italic.clear(), 23 => self.italic.clear(),
24 => self.underline.clear(), 24 => self.underline.clear(),
22 => { 22 => {
@ -183,7 +183,7 @@ impl Attributes {
40..=49 => self.background = Self::parse_color(p, &mut iter), 40..=49 => self.background = Self::parse_color(p, &mut iter),
58..=59 => self.underlined = Self::parse_color(p, &mut iter), 58..=59 => self.underlined = Self::parse_color(p, &mut iter),
90..=97 => self.foreground = Self::parse_color(p, &mut iter), 90..=97 => self.foreground = Self::parse_color(p, &mut iter),
100..=107 => self.foreground = Self::parse_color(p, &mut iter), 100..=107 => self.background = Self::parse_color(p, &mut iter),
_ => { _ => {
// Unsupported SGR sequence. // Unsupported SGR sequence.
// Be compatible and pretend one just wasn't was provided. // Be compatible and pretend one just wasn't was provided.
@ -294,12 +294,14 @@ enum EscapeSequenceOffsets {
start: usize, start: usize,
end: usize, end: usize,
}, },
#[allow(clippy::upper_case_acronyms)]
NF { NF {
// https://en.wikipedia.org/wiki/ANSI_escape_code#nF_Escape_sequences // https://en.wikipedia.org/wiki/ANSI_escape_code#nF_Escape_sequences
start_sequence: usize, start_sequence: usize,
start: usize, start: usize,
end: usize, end: usize,
}, },
#[allow(clippy::upper_case_acronyms)]
OSC { OSC {
// https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences // https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences
start_sequence: usize, start_sequence: usize,
@ -307,6 +309,7 @@ enum EscapeSequenceOffsets {
start_terminator: usize, start_terminator: usize,
end: usize, end: usize,
}, },
#[allow(clippy::upper_case_acronyms)]
CSI { CSI {
// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences // https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences
start_sequence: usize, start_sequence: usize,
@ -340,9 +343,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
/// Takes values from the iterator while the predicate returns true. /// Takes values from the iterator while the predicate returns true.
/// If the predicate returns false, that value is left. /// If the predicate returns false, that value is left.
fn chars_take_while(&mut self, pred: impl Fn(char) -> bool) -> Option<(usize, usize)> { fn chars_take_while(&mut self, pred: impl Fn(char) -> bool) -> Option<(usize, usize)> {
if self.chars.peek().is_none() { self.chars.peek()?;
return None;
}
let start = self.chars.peek().unwrap().0; let start = self.chars.peek().unwrap().0;
let mut end: usize = start; let mut end: usize = start;
@ -359,10 +360,8 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
} }
fn next_text(&mut self) -> Option<EscapeSequenceOffsets> { fn next_text(&mut self) -> Option<EscapeSequenceOffsets> {
match self.chars_take_while(|c| c != '\x1B') { self.chars_take_while(|c| c != '\x1B')
None => None, .map(|(start, end)| EscapeSequenceOffsets::Text { start, end })
Some((start, end)) => Some(EscapeSequenceOffsets::Text { start, end }),
}
} }
fn next_sequence(&mut self) -> Option<EscapeSequenceOffsets> { fn next_sequence(&mut self) -> Option<EscapeSequenceOffsets> {
@ -444,7 +443,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
Some(EscapeSequenceOffsets::OSC { Some(EscapeSequenceOffsets::OSC {
start_sequence, start_sequence,
start_command: osc_open_index + osc_open_char.len_utf8(), start_command: osc_open_index + osc_open_char.len_utf8(),
start_terminator: start_terminator, start_terminator,
end: end_sequence, end: end_sequence,
}) })
} }
@ -502,9 +501,8 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
} }
// Get the final byte. // Get the final byte.
match self.chars.next() { if let Some((i, c)) = self.chars.next() {
Some((i, c)) => end = i + c.len_utf8(), end = i + c.len_utf8()
None => {}
} }
Some(EscapeSequenceOffsets::NF { Some(EscapeSequenceOffsets::NF {
@ -593,15 +591,18 @@ impl<'a> Iterator for EscapeSequenceIterator<'a> {
pub enum EscapeSequence<'a> { pub enum EscapeSequence<'a> {
Text(&'a str), Text(&'a str),
Unknown(&'a str), Unknown(&'a str),
#[allow(clippy::upper_case_acronyms)]
NF { NF {
raw_sequence: &'a str, raw_sequence: &'a str,
nf_sequence: &'a str, nf_sequence: &'a str,
}, },
#[allow(clippy::upper_case_acronyms)]
OSC { OSC {
raw_sequence: &'a str, raw_sequence: &'a str,
command: &'a str, command: &'a str,
terminator: &'a str, terminator: &'a str,
}, },
#[allow(clippy::upper_case_acronyms)]
CSI { CSI {
raw_sequence: &'a str, raw_sequence: &'a str,
parameters: &'a str, parameters: &'a str,
@ -890,4 +891,37 @@ mod tests {
); );
assert_eq!(iter.next(), None); assert_eq!(iter.next(), None);
} }
#[test]
fn test_sgr_attributes_do_not_leak_into_wrong_field() {
let mut attrs = crate::vscreen::Attributes::new();
// Bold, Dim, Italic, Underline, Foreground, Background
attrs.update(EscapeSequence::CSI {
raw_sequence: "\x1B[1;2;3;4;31;41m",
parameters: "1;2;3;4;31;41",
intermediates: "",
final_byte: "m",
});
assert_eq!(attrs.bold, "\x1B[1m");
assert_eq!(attrs.dim, "\x1B[2m");
assert_eq!(attrs.italic, "\x1B[3m");
assert_eq!(attrs.underline, "\x1B[4m");
assert_eq!(attrs.foreground, "\x1B[31m");
assert_eq!(attrs.background, "\x1B[41m");
// Bold, Bright Foreground, Bright Background
attrs.sgr_reset();
attrs.update(EscapeSequence::CSI {
raw_sequence: "\x1B[1;94;103m",
parameters: "1;94;103",
intermediates: "",
final_byte: "m",
});
assert_eq!(attrs.bold, "\x1B[1m");
assert_eq!(attrs.foreground, "\x1B[94m");
assert_eq!(attrs.background, "\x1B[103m");
}
} }

View File

@ -22,7 +22,7 @@ impl BatTester {
pub fn test_snapshot(&self, name: &str, style: &str) { pub fn test_snapshot(&self, name: &str, style: &str) {
let output = Command::new(&self.exe) let output = Command::new(&self.exe)
.current_dir(self.temp_dir.path()) .current_dir(self.temp_dir.path())
.args(&[ .args([
"sample.rs", "sample.rs",
"--no-config", "--no-config",
"--paging=never", "--paging=never",