textoutput

package module
v1.16.3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: BSD-3-Clause Imports: 7 Imported by: 17

README

TextOutput

GoDoc License Go Report Card

Package for controlling text output, with or without colors, using VT100 terminal codes.

example use

Requirements

  • Go 1.17 or later

General info

Documentation

Overview

Package textoutput offers a simple way to use vt100 and output colored text

Index

Constants

This section is empty.

Variables

View Source
var EnvNoColor = env.Bool("NO_COLOR")

Respect the NO_COLOR environment variable

Functions

This section is empty.

Types

type CharAttribute added in v1.8.0

type CharAttribute struct {
	A vt100.AttributeColor
	R rune
}

CharAttribute is a rune and a color attribute

type TextOutput

type TextOutput struct {
	// contains filtered or unexported fields
}

TextOutput keeps state about verbosity and if colors are enabled

func New

func New() *TextOutput

New creates a new TextOutput struct, which is enabled by default and with colors turned on. If the NO_COLOR environment variable is set, colors are disabled.

func NewTextOutput added in v1.2.0

func NewTextOutput(color, enabled bool) *TextOutput

NewTextOutput can initialize a new TextOutput struct, which can have colors turned on or off and where the output can be enabled (verbose) or disabled (silent). If NO_COLOR is set, colors are disabled, regardless.

func (*TextOutput) ColorOff added in v1.4.0

func (o *TextOutput) ColorOff() string

Change the color state in the terminal emulator

func (*TextOutput) ColorOn added in v1.4.0

func (o *TextOutput) ColorOn(attribute1, attribute2 int) string

Change the color state in the terminal emulator

func (*TextOutput) DarkBlue

func (o *TextOutput) DarkBlue(s string) string

func (*TextOutput) DarkCyan

func (o *TextOutput) DarkCyan(s string) string

func (*TextOutput) DarkGray

func (o *TextOutput) DarkGray(s string) string

func (*TextOutput) DarkGreen

func (o *TextOutput) DarkGreen(s string) string

func (*TextOutput) DarkPurple

func (o *TextOutput) DarkPurple(s string) string

func (*TextOutput) DarkRed

func (o *TextOutput) DarkRed(s string) string

func (*TextOutput) DarkTags added in v1.5.0

func (o *TextOutput) DarkTags(colors ...string) string

Replace <blue> with starting a light blue color attribute and <off> with using the default attributes. </blue> can also be used for using the default attributes.

func (*TextOutput) DarkYellow

func (o *TextOutput) DarkYellow(s string) string

func (*TextOutput) Disable added in v1.5.0

func (o *TextOutput) Disable()

func (*TextOutput) DisableColors added in v1.5.0

func (o *TextOutput) DisableColors()

func (*TextOutput) Disabled added in v1.11.0

func (o *TextOutput) Disabled() bool

Disabled returns true if all output is disabled

func (*TextOutput) Enable added in v1.5.0

func (o *TextOutput) Enable()

func (*TextOutput) EnableColors added in v1.5.0

func (o *TextOutput) EnableColors()

func (*TextOutput) Enabled added in v1.11.0

func (o *TextOutput) Enabled() bool

Enabled returns true if any output is enabled

func (*TextOutput) Err

func (o *TextOutput) Err(msg string)

Write an error message in red to stderr if output is enabled

func (*TextOutput) ErrExit

func (o *TextOutput) ErrExit(msg string)

Write an error message to stderr and quit with exit code 1

func (*TextOutput) Extract added in v1.8.0

func (o *TextOutput) Extract(s string) []CharAttribute

Extract iterates over an ANSI encoded string, parsing out color codes and creating a slice of CharAttribute structures. Each CharAttribute in the slice represents a character in the input string and its corresponding color attributes. This function handles escaping sequences and converts ANSI color codes to vt100.AttributeColor structs.

func (*TextOutput) Fprint added in v1.12.7

func (o *TextOutput) Fprint(w io.Writer, msg ...interface{})

Write a message to the given io.Writer if output is enabled

func (*TextOutput) Fprintf added in v1.12.7

func (o *TextOutput) Fprintf(w io.Writer, msg ...interface{})

Write a message to the given io.Writer if output is enabled

func (*TextOutput) Fprintln added in v1.12.7

func (o *TextOutput) Fprintln(w io.Writer, msg ...interface{})

Write a message to the given io.Writer if output is enabled

func (*TextOutput) InterfaceTags added in v1.11.0

func (o *TextOutput) InterfaceTags(colors ...interface{}) string

InterfaceTags is the same as LightTags, but with interfaces

func (*TextOutput) IsEnabled

func (o *TextOutput) IsEnabled() bool

Deprectated

func (*TextOutput) LightBlue

func (o *TextOutput) LightBlue(s string) string

func (*TextOutput) LightCyan

func (o *TextOutput) LightCyan(s string) string

func (*TextOutput) LightGreen

func (o *TextOutput) LightGreen(s string) string

func (*TextOutput) LightPurple

func (o *TextOutput) LightPurple(s string) string

func (*TextOutput) LightRed

func (o *TextOutput) LightRed(s string) string

func (*TextOutput) LightTags added in v1.5.0

func (o *TextOutput) LightTags(colors ...string) string

Replace <blue> with starting a light blue color attribute and <off> with using the default attributes. </blue> can also be used for using the default attributes.

func (*TextOutput) LightYellow

func (o *TextOutput) LightYellow(s string) string

func (*TextOutput) OutputTags added in v1.7.0

func (o *TextOutput) OutputTags(colors ...string)

OutputTags will output text that may have tags like "<blue>", "</blue>" or "<off>" for enabling or disabling color attributes. Respects the color/enabled settings of this TextOutput.

func (*TextOutput) OutputWords added in v1.7.0

func (o *TextOutput) OutputWords(line string, colors ...string)

Given a line with words and several color strings, color the words in the order of the colors. The last color will color the rest of the words.

func (*TextOutput) Print added in v1.11.0

func (o *TextOutput) Print(msg ...interface{})

Write a message to stdout if output is enabled

func (*TextOutput) Printf added in v1.11.0

func (o *TextOutput) Printf(msg ...interface{})

Write a message to stdout if output is enabled

func (*TextOutput) Println

func (o *TextOutput) Println(msg ...interface{})

Write a message to stdout if output is enabled

func (*TextOutput) Tags added in v1.5.0

func (o *TextOutput) Tags(colors ...string) string

Same as LightTags

func (*TextOutput) White

func (o *TextOutput) White(s string) string

func (*TextOutput) Words added in v1.3.0

func (o *TextOutput) Words(line string, colors ...string) string

Given a line with words and several color strings, color the words in the order of the colors. The last color will color the rest of the words.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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