README

TextOutput

Build Status GoDoc License Go Report Card

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

Example use

package main

import (
	"github.com/xyproto/textoutput"
)

func main() {
	// Prepare to output colored text, but respect the NO_COLOR environment variable
	o := textoutput.New()

	o.Print("<blue>hi</blue> ")
	o.Println("<yellow>there</yellow>")
	o.Printf("<green>%s: <red>%d<off>\n", "number", 42)
}

screenshot

General info

  • Version: 1.12.2
  • License: MIT
  • Author <xyproto@archlinux.org>
Expand ▾ Collapse ▴

Documentation

Overview

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

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type CharAttribute

    type CharAttribute struct {
    	R rune
    	A vt100.AttributeColor
    }

      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

          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

            func (o *TextOutput) ColorOff() string

              Change the color state in the terminal emulator

              func (*TextOutput) ColorOn

              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

                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

                  func (o *TextOutput) Disable()

                  func (*TextOutput) DisableColors

                  func (o *TextOutput) DisableColors()

                  func (*TextOutput) Disabled

                  func (o *TextOutput) Disabled() bool

                    Disabled returns true if all output is disabled

                    func (*TextOutput) Enable

                    func (o *TextOutput) Enable()

                    func (*TextOutput) EnableColors

                    func (o *TextOutput) EnableColors()

                    func (*TextOutput) Enabled

                    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

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

                            Pair takes a string with ANSI codes and returns a slice with two elements.

                            func (*TextOutput) InterfaceTags

                            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

                                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

                                  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

                                    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

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

                                        Write a message to stdout if output is enabled

                                        func (*TextOutput) Printf

                                        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

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

                                              Same as LightTags

                                              func (*TextOutput) White

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

                                              func (*TextOutput) Words

                                              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.

                                                Source Files

                                                Directories

                                                Path Synopsis
                                                cmd