lotabout / skim

Fuzzy Finder in rust!
MIT License
5.1k stars 183 forks source link

ansi parser: fix dim / half-bright #563

Open hellux opened 6 months ago

hellux commented 6 months ago

\x1b[2m seems to be parsed as DIM | UNDERLINE | BLINK | REVERSE instead of just DIM.

Not sure why the current implementation does this, the message for the commit that added it just mentions implementing multiple parameters, but not specifically why !BOLD was added:

commit d902d65fae1294d7dea5f3dcd90ad31b5b55d1f9
Author: Jinzhou Zhang <lotabout@gmail.com>
Date:   Sat Jul 13 23:41:28 2019 +0800

    fix #194: color not working with ag

    It's because ag uses multiple attributes in SGR parameters.
    e.g. `\e[1;31m` which means set the attribute to BOLD and forground
    color to yellow.

    Previously skim's CSI parsing logic will take only the first parameter.

diff --git a/src/ansi.rs b/src/ansi.rs
index 8495d82..583d19b 100644
--- a/src/ansi.rs
+++ b/src/ansi.rs
@@ -69,60 +70,88 @@ impl Perform for ANSIParser {
         }
:
                 0 => attr = Attr::default(),
                 1 => attr.effect |= Effect::BOLD,
+                2 => attr.effect |= !Effect::BOLD,
                 4 => attr.effect |= Effect::UNDERLINE,
                 5 => attr.effect |= Effect::BLINK,
:

None of the tests added in this commit use DIM either, they still pass after my change, so I'm assuming this change was accidental.