flair

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: Apache-2.0 Imports: 2 Imported by: 2

README

flair

Simple console formatting library for Go

Go Reference Go Report Card license

Motivation

There are definitely a bunch of other libraries like this, but I wanted one I knew would be maintained and properly versioned. I might also have a strong preference about how clean the code that I'm importing is.

Goals

Usage

The main package exposes helper functions for formatting text:

package main

import (
    "github.com/DataDrake/flair"
)

func main() {
    println(flair.Bold("This is Bolded Text"))
    println(flair.Green("This is Green Text"))
    println(flair.RedBG("This is Text with a Red background"))
}

Formatting Example

You can pretty easily create custom colors and functions:

package main

import (
    "github.com/DataDrake/flair/color"
    "github.com/DataDrake/flair/escape"
)

func main() {
    Purple   := color.Color(56)
    purple   := escape.Combine(Purple.FG(), color.DefaultFG.Swap()).Func()
    purpleBG := escape.Combine(Purple.BG(), color.DefaultBG.Swap()).Func()

    println(purple("This is Purple Text"))
    println(purpleBG("This is Text with a Purple background"))
}

Colors Example

And you can easily combine multiple formatting directives into one:

package main

import (
    "fmt"
    "github.com/DataDrake/flair/color"
    "github.com/DataDrake/flair/escape"
)

func main() {
    label := escape.Combine(escape.Bold, color.White.FG(), color.Red.FG(), escape.Reset.Swap()).Func()
    println(label(" Bold Red Label ") + " Default Text")

    // Or with a formatting string
    msgFmt := label(" %s ") + " %s\n"
    fmt.Printf(msgFmt, "Like", "So")
}

Combined Format Example

License

Copyright 2021 Bryan T. Meyers root@datadrake.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Defaults
	DefaultFG = color.DefaultFG.String()
	DefaultBG = color.DefaultBG.String()

	// Normal Colors (8 color mode)
	Black       = escape.Combine(color.Black.FG(), color.DefaultFG.Swap()).Func()
	BlackBG     = escape.Combine(color.Black.BG(), color.DefaultBG.Swap()).Func()
	Red         = escape.Combine(color.Red.FG(), color.DefaultFG.Swap()).Func()
	RedBG       = escape.Combine(color.Red.BG(), color.DefaultBG.Swap()).Func()
	Green       = escape.Combine(color.Green.FG(), color.DefaultFG.Swap()).Func()
	GreenBG     = escape.Combine(color.Green.BG(), color.DefaultBG.Swap()).Func()
	Yellow      = escape.Combine(color.Yellow.FG(), color.DefaultFG.Swap()).Func()
	YellowBG    = escape.Combine(color.Yellow.BG(), color.DefaultBG.Swap()).Func()
	Blue        = escape.Combine(color.Blue.FG(), color.DefaultFG.Swap()).Func()
	BlueBG      = escape.Combine(color.Blue.BG(), color.DefaultBG.Swap()).Func()
	Magenta     = escape.Combine(color.Magenta.FG(), color.DefaultFG.Swap()).Func()
	MagentaBG   = escape.Combine(color.Magenta.BG(), color.DefaultBG.Swap()).Func()
	Cyan        = escape.Combine(color.Cyan.FG(), color.DefaultFG.Swap()).Func()
	CyanBG      = escape.Combine(color.Cyan.BG(), color.DefaultBG.Swap()).Func()
	LightGray   = escape.Combine(color.LightGray.FG(), color.DefaultFG.Swap()).Func()
	LightGrayBG = escape.Combine(color.LightGray.BG(), color.DefaultBG.Swap()).Func()

	// Extended Colors (16 color mode)
	DarkGray       = escape.Combine(color.DarkGray.FG(), color.DefaultFG.Swap()).Func()
	DarkGrayBG     = escape.Combine(color.DarkGray.BG(), color.DefaultBG.Swap()).Func()
	LightRed       = escape.Combine(color.LightRed.FG(), color.DefaultFG.Swap()).Func()
	LightRedBG     = escape.Combine(color.LightRed.BG(), color.DefaultBG.Swap()).Func()
	LightGreen     = escape.Combine(color.LightGreen.FG(), color.DefaultFG.Swap()).Func()
	LightGreenBG   = escape.Combine(color.LightGreen.BG(), color.DefaultBG.Swap()).Func()
	LightYellow    = escape.Combine(color.LightYellow.FG(), color.DefaultFG.Swap()).Func()
	LightYellowBG  = escape.Combine(color.LightYellow.BG(), color.DefaultBG.Swap()).Func()
	LightBlue      = escape.Combine(color.LightBlue.FG(), color.DefaultFG.Swap()).Func()
	LightBlueBG    = escape.Combine(color.LightBlue.BG(), color.DefaultBG.Swap()).Func()
	LightMagenta   = escape.Combine(color.LightMagenta.FG(), color.DefaultFG.Swap()).Func()
	LightMagentaBG = escape.Combine(color.LightMagenta.BG(), color.DefaultBG.Swap()).Func()
	LightCyan      = escape.Combine(color.LightCyan.FG(), color.DefaultFG.Swap()).Func()
	LightCyanBG    = escape.Combine(color.LightCyan.BG(), color.DefaultBG.Swap()).Func()
	White          = escape.Combine(color.White.FG(), color.DefaultFG.Swap()).Func()
	WhiteBG        = escape.Combine(color.White.BG(), color.DefaultBG.Swap()).Func()
)

CSI Character Attributes (SGR) Helper functions for changing colors

View Source
var (
	Bold      = escape.Combine(escape.Bold, escape.ResetBold.Swap()).Func()
	Dim       = escape.Combine(escape.Dim, escape.ResetDim.Swap()).Func()
	Underline = escape.Combine(escape.Underline, escape.ResetUnderline.Swap()).Func()
	Blink     = escape.Combine(escape.Blink, escape.ResetBlink.Swap()).Func()
	Reverse   = escape.Combine(escape.Reverse, escape.ResetReverse.Swap()).Func()
	Hidden    = escape.Combine(escape.Hidden, escape.ResetHidden.Swap()).Func()
)

Helper functions for changing text styles (Auto-reset at string end)

View Source
var (
	Reset          = escape.Reset.String() // Reset clears all formatting, including colors
	ResetBold      = escape.ResetBold.String()
	ResetDim       = escape.ResetDim.String()
	ResetUnderline = escape.ResetUnderline.String()
	ResetBlink     = escape.ResetBlink.String()
	ResetReverse   = escape.ResetReverse.String()
	ResetHidden    = escape.ResetHidden.String()
)

Helper strings for clearing specific formatting

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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