Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support adaptive colors extension #6

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aymanbagabas
Copy link
Member

This will choose the color based on the HasLightBackground value of the writer. This is useful for supporting the adaptive colors extension in the terminal.

Extension specs:

SGR already defines 5 and 2 for 16 and 24-bit colors to be used with the 38, 48, and 58 parameters. This extension adds support for adaptive colors, which will choose the color based on the HasLightBackground value of the writer.

The 4 parameter is used to specify light-dark 24-bit colors.

printf '\x1b[38;4;255;0;0;0;255;0mHello, world!\x1b[0m\n'

Here the first three values are the light color and the last three values are the dark color.

The 10 parameter is used to specify light-dark 256 colors.

printf '\x1b[38;10;255;0mHello, world!\x1b[0m\n'

This will choose the color based on the `HasLightBackground` value
of the writer. This is useful for supporting the adaptive colors
extension in the terminal.

Extension specs:

SGR already defines 5 and 2 for 16 and 24-bit colors to be used with the
38, 48, and 58 parameters. This extension adds support for adaptive
colors, which will choose the color based on the HasLightBackground
value of the writer.

The 4 parameter is used to specify light-dark 24-bit colors.

```
printf '\x1b[38;4;255;0;0;0;255;0mHello, world!\x1b[0m\n'
```

Here the first three values are the light color and the last three
values are the dark color.

The 10 parameter is used to specify light-dark 256 colors.

```
printf '\x1b[38;10;255;0mHello, world!\x1b[0m\n'
```
@@ -170,6 +174,36 @@ func readColor(idxp *int, params []int) (c ansi.Color) {
}
c = ansi.ExtendedColor(ansi.Param(params[i+2])) //nolint:gosec
*idxp += 2
case 4: // lightDark(RGB)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should use a const value to get rid of magic numbers?

@bashbunni
Copy link
Member

Nice! :)

@aymanbagabas aymanbagabas marked this pull request as draft October 30, 2024 21:23
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.

2 participants