charmbracelet / charmbracelet/log

AdaptiveColor not working

Open
#172 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
3.4k
Forks
103
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

AdaptiveColor always returns the Dark color. Bug only occurs with the log library. Tea and other charm packages respect the adaptive rule.

In my TUI I use both bubbles and log and the log appears always with dark theme.

lipgloss v1.1.0
log v0.4.2 (same issue on v0.4.0)
bubbles v0.21.0
bubbletea v1.3.4
termenv v0.16.0

### Setup

- OS Arch
- Shell fish or bash
- Terminal Emulator: both Alacritty or Kitty
- Terminal Multiplexer With or without tmux

### To Reproduce

Using `log` library with tea does not respect lipgloss dark/light rule.

### Source Code

```go
var (
logTextStyle = lipgloss.NewStyle().Foreground(
lipgloss.AdaptiveColor{Light: "71", Dark: "196"},
)
)

// Sets the logging into TUI mode.
func SetTUI(output io.Writer) {
tuiLogStyles := log.DefaultStyles()
tuiLogStyles.Levels = logLevelStyles

tuiLogStyles.Prefix = lipgloss.NewStyle().
Foreground(lipgloss.Color("250"))

tuiLogStyles.Message = logTextStyle

tuiLogStyles.Key = lipgloss.NewStyle().
Foreground(lipgloss.Color("250"))

tuiLogStyles.Separator = lipgloss.NewStyle().
Foreground(lipgloss.Color("250"))

tuiLogStyles.Value = lipgloss.NewStyle().
Foreground(lipgloss.Color("252"))

for _, logger := range loggers {
logger.SetOutput(output)
//TODO: set custom theme
// see https://github.com/charmbracelet/log?tab=readme-ov-file#styles
logger.SetStyles(tuiLogStyles)
logger.SetColorProfile(termenv.ANSI256)
logger.SetReportCaller(false)
logger.SetReportTimestamp(false)
if logger.GetLevel() < log.InfoLevel {
logger.SetLevel(log.Level(log.InfoLevel))
}

}
}
```

### Expected behavior

- In this example code I set the dark foreground for the Message part to be in red.
- When I set the terminal (any of them) to a light background, log messages are only displayed in red color.
- **Expected :** Green foreground on white background

### Screenshots

![Image](https://github.com/user-attachments/assets/39107e97-2a06-4fb7-886f-933e3feef7a7)

### Additional context

I am using the log library within a bubbletea TUI. The TUI respects adaptive colors except the log lib

Contributor guide

Open the contributing guide

Research direction

Start by tracing how SetStyles and SetColorProfile interact with lipgloss.AdaptiveColor when the logger renders messages. Reproduce the issue with the versions and terminal setups listed, then compare log output with Bubble Tea's adaptive-color behavior. Done means light terminals use the green Light color while dark terminals use the red Dark color.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.