Help us shape the future of Go! Take the 2026 Go Developer Survey

customo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2019 License: MIT Imports: 2 Imported by: 0

README

customo

GoDoc
customo helps when creating strings using ANSI escape codes attributes, such as italic, bold and custom foreground and background colors.

Installation

go get github.com/efreitasn/customo

Examples

Bold, underlined string with white foreground and green background 4 bit colors.
package main

import (
	"fmt"

	"github.com/efreitasn/customo"
)

func main() {
	str := customo.Format(
		"Custom string",
		customo.AttrBold,
		customo.AttrUnderline,
		customo.AttrBgColor4BitsGreen,
		customo.AttrFgColor4BitsWhite,
	)

	fmt.Println(str)
}
Bold string with gray foreground and white background 8 bit colors.
package main

import (
	"fmt"

	"github.com/efreitasn/customo"
)

func main() {
	str := customo.Format(
		"Custom string",
		customo.AttrBold,
		customo.AttrFgColor8Bits(236),
		customo.AttrBgColor8Bits(255),
	)

	fmt.Println(str)
}
Italic string with blue foreground and red background 24 bit colors.
package main

import (
	"fmt"

	"github.com/efreitasn/customo"
)

func main() {
	str := customo.Format(
		"Custom string",
		customo.AttrBold,
		customo.AttrUnderline,
		customo.AttrFgColor24Bits(0, 0, 255),
		customo.AttrBgColor24Bits(255, 0, 0),
	)

	fmt.Println(str)
}

Documentation

Overview

Package customo helps when creating strings using ANSI escape codes attributes, such as italic, bold and custom foreground and background colors.

Index

Examples

Constants

View Source
const (
	AttrBold                      = SimpleAttr(1)
	AttrItalic                    = SimpleAttr(3)
	AttrUnderline                 = SimpleAttr(4)
	AttrBlink                     = SimpleAttr(5)
	AttrStrikethrough             = SimpleAttr(9)
	AttrFgColor4BitsBlack         = SimpleAttr(30)
	AttrFgColor4BitsRed           = SimpleAttr(31)
	AttrFgColor4BitsGreen         = SimpleAttr(32)
	AttrFgColor4BitsYellow        = SimpleAttr(33)
	AttrFgColor4BitsBlue          = SimpleAttr(34)
	AttrFgColor4BitsMagenta       = SimpleAttr(35)
	AttrFgColor4BitsCyan          = SimpleAttr(36)
	AttrFgColor4BitsWhite         = SimpleAttr(37)
	AttrBgColor4BitsBlack         = SimpleAttr(40)
	AttrBgColor4BitsRed           = SimpleAttr(41)
	AttrBgColor4BitsGreen         = SimpleAttr(42)
	AttrBgColor4BitsYellow        = SimpleAttr(43)
	AttrBgColor4BitsBlue          = SimpleAttr(44)
	AttrBgColor4BitsMagenta       = SimpleAttr(45)
	AttrBgColor4BitsCyan          = SimpleAttr(46)
	AttrBgColor4BitsWhite         = SimpleAttr(47)
	AttrOverline                  = SimpleAttr(53)
	AttrFgColor4BitsBrightBlack   = SimpleAttr(90)
	AttrFgColor4BitsBrightRed     = SimpleAttr(91)
	AttrFgColor4BitsBrightGreen   = SimpleAttr(92)
	AttrFgColor4BitsBrightYellow  = SimpleAttr(93)
	AttrFgColor4BitsBrightBlue    = SimpleAttr(94)
	AttrFgColor4BitsBrightMagenta = SimpleAttr(95)
	AttrFgColor4BitsBrightCyan    = SimpleAttr(96)
	AttrFgColor4BitsBrightWhite   = SimpleAttr(97)
	AttrBgColor4BitsBrightBlack   = SimpleAttr(100)
	AttrBgColor4BitsBrightRed     = SimpleAttr(101)
	AttrBgColor4BitsBrightGreen   = SimpleAttr(102)
	AttrBgColor4BitsBrightYellow  = SimpleAttr(103)
	AttrBgColor4BitsBrightBlue    = SimpleAttr(104)
	AttrBgColor4BitsBrightMagenta = SimpleAttr(105)
	AttrBgColor4BitsBrightCyan    = SimpleAttr(106)
	AttrBgColor4BitsBrightWhite   = SimpleAttr(107)
)

Attributes.

Variables

This section is empty.

Functions

func Format

func Format(str string, attrs ...Attr) string

Format formats str using attrs.

Example (Colors24Bits)
package main

import (
	"fmt"

	"github.com/efreitasn/customo"
)

func main() {
	str := customo.Format(
		"Custom string",
		customo.AttrBold,
		customo.AttrStrikethrough,
		customo.AttrFgColor24Bits(0, 255, 0),
		customo.AttrBgColor24Bits(255, 0, 0),
	)

	fmt.Println(str)
}
Example (Colors4Bits)
package main

import (
	"fmt"

	"github.com/efreitasn/customo"
)

func main() {
	str := customo.Format(
		"Custom string",
		customo.AttrBold,
		customo.AttrStrikethrough,
		customo.AttrFgColor4BitsBlack,
		customo.AttrBgColor4BitsBrightCyan,
	)

	fmt.Println(str)
}
Example (Colors8Bits)
package main

import (
	"fmt"

	"github.com/efreitasn/customo"
)

func main() {
	str := customo.Format(
		"Custom string",
		customo.AttrBold,
		customo.AttrStrikethrough,
		customo.AttrFgColor8Bits(232),
		customo.AttrBgColor8Bits(255),
	)

	fmt.Println(str)
}

Types

type Attr

type Attr interface {
	ANSI() string
}

Attr represents an ANSI escape codes attribute.

type BgColor8Bits

type BgColor8Bits int

BgColor8Bits is an 8 bit background color attribute.

func AttrBgColor8Bits

func AttrBgColor8Bits(bg8BitsColor int) BgColor8Bits

AttrBgColor8Bits returns a new 8 bit background color attribute.

func (BgColor8Bits) ANSI

func (c BgColor8Bits) ANSI() string

ANSI returns a representation to be used as an ANSI escape code.

type BgColor24Bits

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

BgColor24Bits is a 24 bit background color attribute.

func AttrBgColor24Bits

func AttrBgColor24Bits(red, green, blue int) *BgColor24Bits

AttrBgColor24Bits returns a new 24 bit background color attribute.

func (*BgColor24Bits) ANSI

func (c *BgColor24Bits) ANSI() string

ANSI returns a representation to be used as an ANSI escape code.

type FgColor8Bits

type FgColor8Bits int

FgColor8Bits is an 8 bit foreground color attribute.

func AttrFgColor8Bits

func AttrFgColor8Bits(color int) FgColor8Bits

AttrFgColor8Bits returns a new 8 bit foreground color attribute.

func (FgColor8Bits) ANSI

func (c FgColor8Bits) ANSI() string

ANSI returns a representation to be used as an ANSI escape code.

type FgColor24Bits

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

FgColor24Bits is a 24 bit foreground color attribute.

func AttrFgColor24Bits

func AttrFgColor24Bits(red, green, blue int) *FgColor24Bits

AttrFgColor24Bits returns a new 24 bit foreground color attribute.

func (*FgColor24Bits) ANSI

func (c *FgColor24Bits) ANSI() string

ANSI returns a representation to be used as an ANSI escape code.

type SimpleAttr

type SimpleAttr int

SimpleAttr is a simple attribute.

func (SimpleAttr) ANSI

func (s SimpleAttr) ANSI() string

ANSI returns a representation to be used as an ANSI escape code.

Jump to

Keyboard shortcuts

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