charmbracelet / lipgloss

Style definitions for nice terminal layouts 👄
MIT License
8.22k stars 231 forks source link

(v2) feat: add adaptive color package #359

Closed aymanbagabas closed 1 month ago

aymanbagabas commented 2 months ago

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)