compat

package
v2.0.0-beta1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 4 Imported by: 6

Documentation

Overview

Package compat is a compatibility layer for Lip Gloss that provides a way to deal with the hassle of setting up a writer. It's impure because it uses global variables, is not thread-safe, and only works with the default standard I/O streams.

In case you want os.Stderr to be used as the default writer, you can set both [Writer] and HasDarkBackground to use os.Stderr with the following code:

import (
	"os"

	"github.com/charmbracelet/colorprofile"
	"github.com/charmbracelet/lipgloss/v2/impure"
)

func init() {
	impure.Writer = colorprofile.NewWriter(os.Stderr, os.Environ())
	impure.HasDarkBackground, _ = lipgloss.HasDarkBackground(os.Stdin, os.Stderr)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// HasDarkBackground is true if the terminal has a dark background.
	HasDarkBackground = lipgloss.HasDarkBackground(os.Stdin, os.Stdout)

	// Profile is the color profile of the terminal.
	Profile = colorprofile.Detect(os.Stdout, os.Environ())
)

Functions

This section is empty.

Types

type AdaptiveColor

type AdaptiveColor struct {
	Light color.Color
	Dark  color.Color
}

AdaptiveColor provides color options for light and dark backgrounds. The appropriate color will be returned at runtime based on the darkness of the terminal background color.

Example usage:

color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"}

func (AdaptiveColor) RGBA

func (c AdaptiveColor) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns the RGBA value of this color. This satisfies the Go Color interface.

type CompleteAdaptiveColor

type CompleteAdaptiveColor struct {
	Light CompleteColor
	Dark  CompleteColor
}

CompleteAdaptiveColor specifies exact values for truecolor, ANSI256, and ANSI color profiles, with separate options for light and dark backgrounds. Automatic color degradation will not be performed.

func (CompleteAdaptiveColor) RGBA

RGBA returns the RGBA value of this color. This satisfies the Go Color interface.

type CompleteColor

type CompleteColor struct {
	TrueColor color.Color
	ANSI256   color.Color
	ANSI      color.Color
}

CompleteColor specifies exact values for truecolor, ANSI256, and ANSI color profiles. Automatic color degradation will not be performed.

func (CompleteColor) RGBA

func (c CompleteColor) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns the RGBA value of this color. This satisfies the Go Color interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL