greasepaint

package module
v0.0.0-...-1511a87 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 4 Imported by: 0

README

License Contributors Stars Issues Pull requests


greasepaint

💅 Go library for convenient CLI styling 🤡

Documentation · View Demo . Report Bug · Request Feature


Table of contents

Introduction

A convenient CLI output styling library for Go which also handles omitting ansi sequences when redirected to a file for sane output.

Demo

Usage

Add this package to your project

$ go get github.com/LordOfTrident/greasepaint

And import it

package main

import (
	"fmt"

	gp "github.com/LordOfTrident/greasepaint"
)

func main() {
	fmt.Println(gp.Center("Hello, world!"))
}

Example

You can find examples in the examples folder.

Documentation

Coming soon.

Bugs

If you find any bugs, please, create an issue and report them.



Go ansi-go

Made with ❤️ love

(Back to top)

Documentation

Index

Constants

View Source
const (
	AutoWidth = 0
	NoBorder  = rune(0)
)
View Source
const (
	TargetStdout = Target(iota)
	TargetStderr
	TargetTTY
	TargetOther
)
View Source
const (
	AlignLeft = Align(iota)
	AlignRight
	AlignCenter
)

Variables

View Source
var (
	Black   = NewColor256(ansi.Black)
	Red     = NewColor256(ansi.Red)
	Green   = NewColor256(ansi.Green)
	Yellow  = NewColor256(ansi.Yellow)
	Blue    = NewColor256(ansi.Blue)
	Magenta = NewColor256(ansi.Magenta)
	Cyan    = NewColor256(ansi.Cyan)
	White   = NewColor256(ansi.White)

	LightBlack   = NewColor256(ansi.LightBlack)
	LightRed     = NewColor256(ansi.LightRed)
	LightGreen   = NewColor256(ansi.LightGreen)
	LightYellow  = NewColor256(ansi.LightYellow)
	LightBlue    = NewColor256(ansi.LightBlue)
	LightMagenta = NewColor256(ansi.LightMagenta)
	LightCyan    = NewColor256(ansi.LightCyan)
	LightWhite   = NewColor256(ansi.LightWhite)
)
View Source
var (
	Bold      = NewStyle().Bold(true).Apply
	Dim       = NewStyle().Dim(true).Apply
	Italic    = NewStyle().Italic(true).Apply
	Underline = NewStyle().Underline(true).Apply
	Blink     = NewStyle().Blink(true).Apply
	Reverse   = NewStyle().Reverse(true).Apply
	Invisible = NewStyle().Invisible(true).Apply
	Crossout  = NewStyle().Crossout(true).Apply

	BlackFg   = NewStyle().Fg(Black).Apply
	RedFg     = NewStyle().Fg(Red).Apply
	GreenFg   = NewStyle().Fg(Green).Apply
	YellowFg  = NewStyle().Fg(Yellow).Apply
	BlueFg    = NewStyle().Fg(Blue).Apply
	MagentaFg = NewStyle().Fg(Magenta).Apply
	CyanFg    = NewStyle().Fg(Cyan).Apply
	WhiteFg   = NewStyle().Fg(White).Apply

	BlackBg   = NewStyle().Bg(Black).Apply
	RedBg     = NewStyle().Bg(Red).Apply
	GreenBg   = NewStyle().Bg(Green).Apply
	YellowBg  = NewStyle().Bg(Yellow).Apply
	BlueBg    = NewStyle().Bg(Blue).Apply
	MagentaBg = NewStyle().Bg(Magenta).Apply
	CyanBg    = NewStyle().Bg(Cyan).Apply
	WhiteBg   = NewStyle().Bg(White).Apply

	LightBlackFg   = NewStyle().Fg(LightBlack).Apply
	LightRedFg     = NewStyle().Fg(LightRed).Apply
	LightGreenFg   = NewStyle().Fg(LightGreen).Apply
	LightYellowFg  = NewStyle().Fg(LightYellow).Apply
	LightBlueFg    = NewStyle().Fg(LightBlue).Apply
	LightMagentaFg = NewStyle().Fg(LightMagenta).Apply
	LightCyanFg    = NewStyle().Fg(LightCyan).Apply
	LightWhiteFg   = NewStyle().Fg(LightWhite).Apply

	LightBlackBg   = NewStyle().Bg(LightBlack).Apply
	LightRedBg     = NewStyle().Bg(LightRed).Apply
	LightGreenBg   = NewStyle().Bg(LightGreen).Apply
	LightYellowBg  = NewStyle().Bg(LightYellow).Apply
	LightBlueBg    = NewStyle().Bg(LightBlue).Apply
	LightMagentaBg = NewStyle().Bg(LightMagenta).Apply
	LightCyanBg    = NewStyle().Bg(LightCyan).Apply
	LightWhiteBg   = NewStyle().Bg(LightWhite).Apply

	Center = NewStyle().Width(-1).Align(AlignCenter).Apply
	Left   = NewStyle().Width(-1).Align(AlignLeft).Apply
	Right  = NewStyle().Width(-1).Align(AlignRight).Apply
)

Functions

func Gap

func Gap(size int) string

func Length

func Length(text string) int

func Line

func Line(text string, length int) string

func Size

func Size(text string) int

func TerminalHeight

func TerminalHeight() int

func TerminalSize

func TerminalSize() (int, int)

func TerminalWidth

func TerminalWidth() int

Types

type Align

type Align int

type Applier

type Applier func(...string) string

func Chain

func Chain(fns ...Applier) Applier

type Attributes

type Attributes map[string]bool
func (a Attributes) Blink() bool

func (Attributes) Bold

func (a Attributes) Bold() bool

func (Attributes) Crossout

func (a Attributes) Crossout() bool

func (Attributes) Dim

func (a Attributes) Dim() bool

func (Attributes) Invisible

func (a Attributes) Invisible() bool

func (Attributes) Italic

func (a Attributes) Italic() bool

func (Attributes) Reverse

func (a Attributes) Reverse() bool

func (Attributes) Underline

func (a Attributes) Underline() bool

type Border

type Border [2]rune

type Color

type Color interface {
	AnsiFg() string
	AnsiBg() string
}

type Color256

type Color256 struct{ Value uint8 }

func NewColor256

func NewColor256(value uint8) Color256

func (Color256) AnsiBg

func (c Color256) AnsiBg() string

func (Color256) AnsiFg

func (c Color256) AnsiFg() string

type ColorDefault

type ColorDefault struct{}

func (ColorDefault) AnsiBg

func (c ColorDefault) AnsiBg() string

func (ColorDefault) AnsiFg

func (c ColorDefault) AnsiFg() string

type ColorHex

type ColorHex struct{ Value string }

func NewColorHex

func NewColorHex(value string) ColorHex

func (ColorHex) AnsiBg

func (c ColorHex) AnsiBg() string

func (ColorHex) AnsiFg

func (c ColorHex) AnsiFg() string

type ColorRGB

type ColorRGB struct{ R, G, B uint8 }

func NewColorRGB

func NewColorRGB(r, g, b uint8) ColorRGB

func (ColorRGB) AnsiBg

func (c ColorRGB) AnsiBg() string

func (ColorRGB) AnsiFg

func (c ColorRGB) AnsiFg() string

type Padding

type Padding [2]int

type Style

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

func NewStyle

func NewStyle() Style

func (Style) Align

func (s Style) Align(align Align) Style

func (Style) Apply

func (s Style) Apply(args ...string) (output string)

func (Style) Bg

func (s Style) Bg(color Color) Style

func (Style) Bg256

func (s Style) Bg256(value uint8) Style

func (Style) BgHex

func (s Style) BgHex(value string) Style

func (Style) BgRGB

func (s Style) BgRGB(r, g, b uint8) Style
func (s Style) Blink(enable bool) Style

func (Style) Bold

func (s Style) Bold(enable bool) Style

Attributes

func (Style) Border

func (s Style) Border(border rune) Style

func (Style) BorderLeft

func (s Style) BorderLeft(border rune) Style

func (Style) BorderRight

func (s Style) BorderRight(border rune) Style

func (Style) Crossout

func (s Style) Crossout(enable bool) Style

func (Style) DefaultBg

func (s Style) DefaultBg() Style

func (Style) DefaultFg

func (s Style) DefaultFg() Style

Colors

func (Style) Dim

func (s Style) Dim(enable bool) Style

func (Style) Fg

func (s Style) Fg(color Color) Style

func (Style) Fg256

func (s Style) Fg256(value uint8) Style

func (Style) FgHex

func (s Style) FgHex(value string) Style

func (Style) FgRGB

func (s Style) FgRGB(r, g, b uint8) Style

func (Style) GetAlign

func (s Style) GetAlign() Align

func (Style) GetAttributes

func (s Style) GetAttributes() map[string]bool

func (Style) GetBg

func (s Style) GetBg() Color

func (Style) GetBorder

func (s Style) GetBorder() Border

func (Style) GetFg

func (s Style) GetFg() Color

func (Style) GetGridGap

func (s Style) GetGridGap() int

func (Style) GetMargin

func (s Style) GetMargin() Padding

func (Style) GetPadding

func (s Style) GetPadding() Padding

func (Style) GetTarget

func (s Style) GetTarget() Target

func (Style) GetWidth

func (s Style) GetWidth() int

func (Style) GridGap

func (s Style) GridGap(gridGap int) Style

func (Style) Invisible

func (s Style) Invisible(enable bool) Style

func (Style) Italic

func (s Style) Italic(enable bool) Style

func (Style) Margin

func (s Style) Margin(size int) Style

Margin

func (Style) MarginLeft

func (s Style) MarginLeft(size int) Style

func (Style) MarginRight

func (s Style) MarginRight(size int) Style

func (Style) Padding

func (s Style) Padding(size int) Style

Padding

func (Style) PaddingLeft

func (s Style) PaddingLeft(size int) Style

func (Style) PaddingRight

func (s Style) PaddingRight(size int) Style

func (Style) Reverse

func (s Style) Reverse(enable bool) Style

func (Style) Target

func (s Style) Target(target Target) Style

func (Style) Underline

func (s Style) Underline(enable bool) Style

func (Style) Width

func (s Style) Width(w int) Style

type Target

type Target int

func (Target) IsTTY

func (t Target) IsTTY() bool

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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