col

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: GPL-3.0 Imports: 2 Imported by: 2

README

col

col is a terminal colours library for Go.

Installation

go get crdx.org/col

Usage

import (
    "fmt"
    "crdx.org/col"
)

func main() {
    col.Init()
    fmt.Println(col.Green("Hello world"))
}

Heuristics

If Init or InitUnless is called, the following heuristics are used to figure out whether colour support should be disabled.

  • The NO_COLOR environment variable is set.
  • The terminal is not interactive.

To disable use of these heuristics, simply don't call Init or InitUnless.

General methods

Enable()

Enable colour support (default).

Disable()

Disable colour support.

Init()

Initialise colour support using various heuristics.

InitUnless(disable bool)

Like Init(), but optionally override heuristics and force colours to be disabled if disable is set to true.

For example, this may be used in the sitation where a --no-color command line flag has been passed and colour support should be disabled if it is true:

col.InitUnless(opts.NoColor)

Colour methods

Foreground
func Green(fmt any, args ...any) string
func Blue(fmt any, args ...any) string
func Red(fmt any, args ...any) string
func Yellow(fmt any, args ...any) string
func Magenta(fmt any, args ...any) string
func White(fmt any, args ...any) string
func Black(fmt any, args ...any) string
func Cyan(fmt any, args ...any) string
Background
func BgGreen(fmt any, args ...any) string
func BgBlue(fmt any, args ...any) string
func BgRed(fmt any, args ...any) string
func BgYellow(fmt any, args ...any) string
func BgMagenta(fmt any, args ...any) string
func BgWhite(fmt any, args ...any) string
func BgBlack(fmt any, args ...any) string
func BgCyan(fmt any, args ...any) string
Styling
func Underline(fmt any, args ...any) string
func Bold(fmt any, args ...any) string
func Italic(fmt any, args ...any) string

Contributions

Open an issue or send a pull request.

Licence

GPLv3.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BgBlack

func BgBlack(fmt any, args ...any) string

BgBlack sets the background colour to black.

func BgBlue

func BgBlue(fmt any, args ...any) string

BgBlue sets the background colour to blue.

func BgCyan

func BgCyan(fmt any, args ...any) string

BgCyan sets the background colour to cyan.

func BgGreen

func BgGreen(fmt any, args ...any) string

BgGreen sets the background colour to green.

func BgMagenta

func BgMagenta(fmt any, args ...any) string

BgMagenta sets the background colour to magenta.

func BgRed

func BgRed(fmt any, args ...any) string

BgRed sets the background colour to red.

func BgWhite

func BgWhite(fmt any, args ...any) string

BgWhite sets the background colour to white.

func BgYellow

func BgYellow(fmt any, args ...any) string

BgYellow sets the background colour to yellow.

func Black

func Black(fmt any, args ...any) string

Black sets the foreground colour to black.

func Blue

func Blue(fmt any, args ...any) string

Blue sets the foreground colour to blue.

func Bold

func Bold(fmt any, args ...any) string

Bold sets the styling to bold.

func Cyan

func Cyan(fmt any, args ...any) string

Cyan sets the foreground colour to cyan.

func Disable

func Disable()

Disable disables colours.

func Enable

func Enable()

Enable enables colours.

func Green

func Green(fmt any, args ...any) string

Green sets the foreground colour to green.

func Init

func Init()

Init initialises colours based on heuristics.

The following heuristics are used to figure out whether colour support should be disabled.

  • The NO_COLOR environment variable is set.
  • The terminal is not interactive.

func InitUnless

func InitUnless(disable bool)

InitUnless initialises colours based on heuristics unless overridden.

Like Init, but optionally override the heuristics and force colours to be disabled if disable is set to true.

func Italic

func Italic(fmt any, args ...any) string

Italic sets the styling to italic.

func Magenta

func Magenta(fmt any, args ...any) string

Magenta sets the foreground colour to magenta.

func Red

func Red(fmt any, args ...any) string

Red sets the foreground colour to red.

func Underline

func Underline(fmt any, args ...any) string

Underline sets the styling to underlined.

func White

func White(fmt any, args ...any) string

White sets the foreground colour to white.

func Yellow

func Yellow(fmt any, args ...any) string

Yellow sets the foreground colour to yellow.

Types

This section is empty.

Jump to

Keyboard shortcuts

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