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

(v2) feat: add adaptive color package #359

Merged
merged 2 commits into from
Oct 18, 2024
Merged

(v2) feat: add adaptive color package #359

merged 2 commits into from
Oct 18, 2024

Conversation

aymanbagabas
Copy link
Member

@aymanbagabas aymanbagabas commented Aug 30, 2024

This introduces a helper type LightDark that takes a boolean to determine which Color(light, dark) to choose from. The adaptive package is a helper package that uses the lipgloss.LightDark along with querying the terminal when the module is imported to choose the appropriate light-dark color.

This will also make lipgloss.Color take any type and try to infer the color from either strings or integers.

Example:

var (
  light = "#0000ff"
  dark = "#ff0000"
)

colorToUse := adaptive.Color(light, dark) // the terminal is queried before choosing the color
fmt.Println(colorToUse)

This introduces a helper type `LightDark` that takes a boolean to
determine which `Color(light, dark)` to choose from. The `adaptive`
package is a helper package that uses the `lipgloss.LightDark` along
with querying the terminal when the module is imported to choose the
appropriate light-dark color.

Example:

```go
var (
  light = "#0000ff"
  dark = "#ff0000"
)

colorToUse := adaptive.Color(light, dark) // the terminal is queried before choosing the color
fmt.Println(colorToUse)
```
@aymanbagabas aymanbagabas changed the title feat: add adaptive color package (v2) feat: add adaptive color package Aug 30, 2024
@bashbunni bashbunni added this to the v2.0.0 milestone Sep 24, 2024
// dark := "#ff0000"
// colorToUse := useDark.Color(light, dark)
// fmt.Println(colorToUse)
type LightDark bool
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about naming this Adapt instead? Might feel more familiar.

Then it could be

adaptive := lipgloss.Adapt(true)
colors := adaptive.Color("#0000ff", "#ff0000")

I think that would make the purpose more clear

Copy link
Member

Choose a reason for hiding this comment

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

Totally: this is really nice.

Copy link
Member

Choose a reason for hiding this comment

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

I would also update the comment to show use with Bubble Tea, as well as standalone Lip Gloss (when we get there).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm thinking of dropping this type which is basically an ifelse; the adaptive sub-package should be enough imo

// dark := "#ff0000"
// colorToUse := useDark.Color(light, dark)
// fmt.Println(colorToUse)
type LightDark bool
Copy link
Member

Choose a reason for hiding this comment

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

I would also update the comment to show use with Bubble Tea, as well as standalone Lip Gloss (when we get there).

@meowgorithm meowgorithm merged commit dbc5538 into v2-exp Oct 18, 2024
5 of 10 checks passed
@meowgorithm meowgorithm deleted the v2-adaptive branch October 18, 2024 16:35
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.

3 participants