summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOliver Looney <88001922+Oliver-Looney@users.noreply.github.com>2024-02-12 09:34:01 +0000
committerGitHub <noreply@github.com>2024-02-12 09:34:01 +0000
commit1f628203e5091da967d920ddc2f201d068f31be1 (patch)
treea5ff81284fb4f6d70be9bf32fef3963b0260ee4a /src
parentc3f2ddf5092e9f81052e3183fdbf5ae68147a8af (diff)
parent1b9fc1d5afcbf743cb26ee50c62834cfa777f15c (diff)
Merge branch 'master' into 2783-setting-terminal-title
Diffstat (limited to 'src')
-rw-r--r--src/decorations.rs2
-rw-r--r--src/vscreen.rs43
2 files changed, 39 insertions, 6 deletions
diff --git a/src/decorations.rs b/src/decorations.rs
index d3ed9b34..85d8103a 100644
--- a/src/decorations.rs
+++ b/src/decorations.rs
@@ -46,7 +46,7 @@ impl Decoration for LineNumberDecoration {
_printer: &InteractivePrinter,
) -> DecorationText {
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;
return DecorationText {
text: self.color.paint(" ".repeat(new_width)).to_string(),
diff --git a/src/vscreen.rs b/src/vscreen.rs
index c902d42b..78f6ad4e 100644
--- a/src/vscreen.rs
+++ b/src/vscreen.rs
@@ -169,10 +169,10 @@ impl Attributes {
while let Some(p) = iter.next() {
match p {
0 => self.sgr_reset(),
- 1 => self.bold = format!("\x1B[{}m", parameters),
- 2 => self.dim = format!("\x1B[{}m", parameters),
- 3 => self.italic = format!("\x1B[{}m", parameters),
- 4 => self.underline = format!("\x1B[{}m", parameters),
+ 1 => self.bold = "\x1B[1m".to_owned(),
+ 2 => self.dim = "\x1B[2m".to_owned(),
+ 3 => self.italic = "\x1B[3m".to_owned(),
+ 4 => self.underline = "\x1B[4m".to_owned(),
23 => self.italic.clear(),
24 => self.underline.clear(),
22 => {
@@ -183,7 +183,7 @@ impl Attributes {
40..=49 => self.background = 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),
- 100..=107 => self.foreground = Self::parse_color(p, &mut iter),
+ 100..=107 => self.background = Self::parse_color(p, &mut iter),
_ => {
// Unsupported SGR sequence.
// Be compatible and pretend one just wasn't was provided.
@@ -890,4 +890,37 @@ mod tests {
);
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");
+ }
}