palette

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package palette provides mapping for 24-bit colors to the 8-bit ANSI SGR palette.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Palette is the 256-color lookup table defined by ANSI for use with
	// SGR escape codes.
	Palette = [0x100]RGB{
		{0, 0, 0},
		{192, 0, 0},
		{0, 192, 0},
		{192, 192, 0},
		{0, 0, 192},
		{192, 0, 192},
		{0, 192, 192},
		{192, 192, 192},
		{128, 128, 128},
		{255, 0, 0},
		{0, 255, 0},
		{255, 255, 0},
		{0, 0, 255},
		{255, 0, 255},
		{0, 255, 255},
		{255, 255, 255},
	}
)

Functions

func FindPaletteColor

func FindPaletteColor(r, g, b uint8) int

FindPaletteColor matches the r, g, b, color to the closest color in the 8-bit palette. The first 16 colors are not used, as the exact color for those entries are terminal dependent, and matching cannot be guarantted.

func FindSimpleColor

func FindSimpleColor(r, g, b uint8) int

FindSimpleColor matches the r, g, b, color to one of the first 16 entries. The first 16 entries match the colors available in the 4-bit palette.

Types

type RGB

type RGB struct {
	R, G, B uint8
}

RGB represents a traditional 24-bit color, having 8 bits for each of red, green, and blue.

func (RGB) RGBA

func (c RGB) RGBA() (r, g, b, a uint32)

func (RGB) String

func (c RGB) String() string

Jump to

Keyboard shortcuts

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