Skip to content

feat: add more info about colors in sgr sequences#40

Merged
caarlos0 merged 1 commit intocharmbracelet:mainfrom
mkotowski:feat/more_precise_color_explanation
Dec 2, 2024
Merged

feat: add more info about colors in sgr sequences#40
caarlos0 merged 1 commit intocharmbracelet:mainfrom
mkotowski:feat/more_precise_color_explanation

Conversation

@mkotowski
Copy link
Copy Markdown
Contributor

Implement changes based on issue #16 and fix SGR 59.

  • fix unhandled runtime error in SGR 59
  • replace unformatted RGB values for truecolor with hex values
  • add matching hex values for ANSI256 colors
  • add info about type of color being used (ANSI, ANSI256, 24-bit RGB)
  • adjust test data

SGR 59 was not handled correctly:
Screenshot_20241129_223833

Example of output after changes:

λ printf '\x1b[34m\x1b[30m\x1b[39m\x1b[38:2:45:134:211m\x1b[38:5:34m\x1b[59m\x1b[58:5:34m\x1b[58:5:2m\x1b[58:2:43:56:233m\x1b[107m\x1b[58:5:2m\x1b[48:5:12m' | ./sequin
 CSI 34m: ANSI foreground color: Blue
 CSI 30m: ANSI foreground color: Black
 CSI 39m: Default foreground color
 CSI 38:2:45:134:211m: 24-bit RGB foreground color: #2D86D3
 CSI 38:5:34m: ANSI256 foreground color: 34 (#00AF00)
 CSI 59m: Default underline color
 CSI 58:5:34m: ANSI256 underline color: 34 (#00AF00)
 CSI 58:5:2m: ANSI256 underline color: 2 (Green)
 CSI 58:2:43:56:233m: 24-bit RGB underline color: #2B38E9
 CSI 107m: Bright ANSI background color: White
 CSI 58:5:2m: ANSI256 underline color: 2 (Green)
 CSI 48:5:12m: ANSI256 background color: 12 (Bright blue)

Screenshot_20241129_232302

Note
Using hex strings has an added bonus for emulators like Konsole, which can have a color preview built-in:

Screenshot_20241129_232551

@coveralls
Copy link
Copy Markdown

coveralls commented Nov 29, 2024

Pull Request Test Coverage Report for Build 12091316136

Details

  • 34 of 42 (80.95%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.5%) to 87.389%

Changes Missing Coverage Covered Lines Changed/Added Lines %
sgr.go 34 42 80.95%
Totals Coverage Status
Change from base Build 12042365908: -0.5%
Covered Lines: 686
Relevant Lines: 785

💛 - Coveralls

Implement changes based on issue charmbracelet#16 and fix SGR 59.

  - fix unhandled runtime error in SGR 59
  - replace unformatted RGB values for truecolor with hex values
  - add matching hex values for ANSI256 colors
  - add info about type of color being used (ANSI, ANSI256, 24-bit RGB)
  - adjust test data

Signed-off-by: Michał Kotowski <dev@mkotowski.dev>
@mkotowski mkotowski force-pushed the feat/more_precise_color_explanation branch from 7e30d00 to 46f1409 Compare November 29, 2024 22:42
str += "Default underline color"
case 90, 91, 92, 93, 94, 95, 96, 97:
str += fmt.Sprintf("Bright foreground color: %s", basicColors[param.Param(0)-90])
str += fmt.Sprintf("Bright ANSI foreground color: %s", basicColors[param.Param(0)-90])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would maybe change this

Suggested change
str += fmt.Sprintf("Bright ANSI foreground color: %s", basicColors[param.Param(0)-90])
str += fmt.Sprintf("ANSI foreground color: Bright %s", basicColors[param.Param(0)-90])

str += fmt.Sprintf("Bright ANSI foreground color: %s", basicColors[param.Param(0)-90])
case 100, 101, 102, 103, 104, 105, 106, 107:
str += fmt.Sprintf("Bright background color: %s", basicColors[param.Param(0)-100])
str += fmt.Sprintf("Bright ANSI background color: %s", basicColors[param.Param(0)-100])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
str += fmt.Sprintf("Bright ANSI background color: %s", basicColors[param.Param(0)-100])
str += fmt.Sprintf("ANSI background color: Bright %s", basicColors[param.Param(0)-100])

@caarlos0 caarlos0 merged commit 791c04a into charmbracelet:main Dec 2, 2024
@caarlos0
Copy link
Copy Markdown
Contributor

caarlos0 commented Dec 2, 2024

done the bright thing on main.

@meowgorithm
Copy link
Copy Markdown
Member

This is such great revision. Thanks, @mkotowski!!

@caarlos0
Copy link
Copy Markdown
Contributor

caarlos0 commented Dec 2, 2024

True that! Thanks so much @mkotowski !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants