ansi256

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: Apache-2.0 Imports: 4 Imported by: 4

README

ansi256

PkgGoDev Coverage Status

Small library and tools to calibrate and use an ANSI 256 color terminal.

For pixel emulation, it uses block codes ▒ and ░ to approximate a RGB color using two colors, one foreground and one background.

  • cmd/output256 prints all the 256 colors.
  • cmd/calibrate256 takes a PNG screenshot as input and generates a new table.
  • cmd/genpng256 takes the table and generate a new PNG, to ensure the table looks good.

For calibration, make sure your terminal is not semi-transparent before taking a screenshot.

Documentation

Overview

Package ansi256 enables calibrating the ANSI color in a terminal.

Index

Constants

This section is empty.

Variables

View Source
var Default = &Term256

Default is the default palette to use. It is selected based on the OS.

View Source
var Term256 = Palette{}/* 256 elements not displayed */

Term256 is the default look up table for ANSI color codes according to xterm-256.

View Source
var TermGnome = Palette{}/* 256 elements not displayed */

TermGnome is the colors as displayed on gnome-terminal.

This table was generated via a screenshot generated by ./cmd/output256 sent to ./cmd/calibrate256 using the Pro theme.

View Source
var TermOSX = Palette{}/* 256 elements not displayed */

TermOSX is the colors as displayed on OSX.

This table was generated via a screenshot generated by ./cmd/output256 sent to ./cmd/calibrate256 using the Pro theme.

Functions

func Raw

func Raw(foreground bool, c color.NRGBA) string

Raw returns a string using expanded syntax.

Your terminal may not support it. In that case, fall back to the palette.

Types

type Palette

type Palette [256]color.NRGBA

Palette is the color palette to use. The alpha value is ignored.

func (*Palette) ANSI

func (p *Palette) ANSI(c color.NRGBA) int

ANSI pick the closest term-256 color.

The color is converted to alpha-multiplied RGBA so this is important that alpha is set to 255 for full color. The return value is between 0 and 255.

func (*Palette) Block

func (p *Palette) Block(c color.NRGBA) string

Block returns a character with ANSI code to represent the color as closely as possible using a shaded block and two colors. It is important to clear with "\033[0m" after when done.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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