compat

package
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 3 Imported by: 1

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 = func() bool {
		hdb, _ := lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
		return hdb
	}()

	// 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 any
	Dark  any
}

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 any
	ANSI256   any
	ANSI      any
}

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