Skip to content

AdaptiveColor not working #172

@blob42

Description

@blob42

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

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

Additional context

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions