colorstyle

package module
Version: v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: GPL-3.0 Imports: 4 Imported by: 0

README

colorStyle

ColorStyle is a library of styles for command-line text. Used to modify the style of text for standard output to the terminal interface, you can change the foreground colour of the text, the background colour, add underline and bold, etc.

ColorStyle 是一个用于命令行文本的样式库。 用于标准输出到终端界面的文本的样式修改,可以修改文本前景色,背景色,增加下划线和加粗显等。

Doc

See this document at GoDoc

Install

go get -u github.com/flylog/colorstyle@latest

Example

package main

import (
	"fmt"

	"github.com/flylog/colorstyle"
)

func main() {
	text := colorstyle.Green("green")
	fmt.Printf("a %s text\n", text)

	text = colorstyle.BrightBlue("BrightBlue")
	fmt.Printf("a %s text\n", text)

	text = colorstyle.New().ColorRed().Sprint("red")
	fmt.Println("a", text, "text")
	colorstyle.New().StyleItalic().ColorRed().BgYellow().Printf("a italic red bgYellow text: %s\n", "Hello 世界!")
	colorstyle.New().StyleBold().Printf("a bold text: %s\n", "Hello 世界!")
	colorstyle.New().StyleItalic().Printf("a italic text: %s\n", "Hello 世界!")
	colorstyle.New().ColorBrightMagenta().Printf("a magenta text: %s\n", "Hello 世界!")
	colorstyle.New().BgCyan().Printf("a bgCyan text: %s\n", "Hello 世界!")
	colorstyle.New().BgCyan().Println("a bgCyan text")

	css := colorstyle.New()
	css.StyleUnderline().Println("下划线文本")
	css.StyleReverse().Println("反显文本")

}

output:

Documentation

Overview

ColorStyle is a library of styles for command-line text. Used to modify the style of text for standard output to the terminal interface, you can change the foreground colour of the text, the background colour, add underline and bold, etc.

ColorStyle 是一个用于命令行文本的样式库。 用于标准输出到终端界面的文本的样式修改,可以修改文本前景色,背景色,增加下划线和加粗显等。

Example
package main

import (
	"fmt"

	"github.com/flylog/colorstyle"
)

func main() {
	text := colorstyle.Green("green")
	fmt.Printf("a %s text\n", text)

	text = colorstyle.Blue("Blue")
	fmt.Printf("a %s text\n", text)

	text = colorstyle.New().ColorRed().Sprint("red")
	fmt.Println("a", text, "text")

	colorstyle.New().StyleItalic().ColorRed().BgYellow().Printf("a italic red bgYellow text: %s\n", "Hello 世界!")
	colorstyle.New().StyleBold().Printf("a bold text: %s\n", "Hello 世界!")
	colorstyle.New().StyleItalic().Printf("a italic text: %s\n", "Hello 世界!")
	colorstyle.New().ColorMagenta().Printf("a magenta text: %s\n", "Hello 世界!")
	colorstyle.New().BgCyan().Printf("a  background color cyan text: %s\n", "Hello 世界!")
	colorstyle.New().BgCyan().Println("a background color cyan text")

	css := colorstyle.New()
	css.StyleStrikethrough().Println("删除线文本")
	css.StyleUnderline().Println("下划线文本")
	css.StyleReverse().Println("反显文本")
}
Output:

Index

Examples

Constants

View Source
const (
	ANSI_SET   = "\033["   // ANSI转义码,设置文本样式的开头
	ANSI_END   = "m"       // 设置结束字符
	ANSI_RESET = "\033[0m" // ANSI转义码,重置设置到常规
)

Variables

This section is empty.

Functions

func Black

func Black(text ...interface{}) string

生成黑色的文本

Generate black text

func Blue

func Blue(text ...interface{}) string

生成蓝色的文本

Generate blue text

Example
package main

import (
	"fmt"

	"github.com/flylog/colorstyle"
)

func main() {
	text := colorstyle.Blue("Blue")
	fmt.Printf("a %s text\n", text)
}
Output:

func BrightBlue

func BrightBlue(text ...interface{}) string

生成亮蓝的文本

Generate bright blue text

func BrightCyan

func BrightCyan(text ...interface{}) string

生成亮青色的文本

Generate bright cyan text

func BrightMagenta

func BrightMagenta(text ...interface{}) string

生成亮品红的文本

Generate bright magenta text

func BrightRed

func BrightRed(text ...interface{}) string

生成亮红色的文本

Generate bright red text

func BrightWhite

func BrightWhite(text ...interface{}) string

生成亮色的文本

Generate bright white text

func BrightYellow

func BrightYellow(text ...interface{}) string

生成亮黄色的文本

Generate bright yellow text

func Cyan

func Cyan(text ...interface{}) string

生成青色的文本

Generate cyan text

func Gray

func Gray(text ...interface{}) string

生成灰色的文本

Generate gray text

func Green

func Green(text ...interface{}) string

生成绿色的文本

Generate green text

Example
package main

import (
	"fmt"

	"github.com/flylog/colorstyle"
)

func main() {
	text := colorstyle.Green("green")
	fmt.Printf("a %s text\n", text)
}
Output:

func Magenta

func Magenta(text ...interface{}) string

生成品红色的文本

Generate magenta text

func Red

func Red(text ...interface{}) string

生成红色的文本

Generate red text

func White

func White(text ...interface{}) string

生成白色的文本

Generate white text

func Yellow

func Yellow(text ...interface{}) string

生成黄色的文本

Generate yellow text

Types

type BgColor

type BgColor int
const (
	BgBlack BgColor = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
	BgGray BgColor = iota + 92
	BgBrightRed
	BgBrightGreen
	BgBrightYellow
	BgBrightBlue
	BgBrightMagenta
	BgBrightCyan
	BgBrightWhite
)

type CSS

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

func New

func New() *CSS

新建一个文本样式对象

Create a new text style object

Example
package main

import (
	"github.com/flylog/colorstyle"
)

func main() {
	css := colorstyle.New()
	css.StyleItalic().ColorGreen().BgYellow()
	css.Printf("a italic green bgYellow text: %s\n", "Hello 世界!")
}
Output:

func (*CSS) BgBlack

func (c *CSS) BgBlack() *CSS

设置背景颜色为黑色

Set the background colour to black

func (*CSS) BgBlue

func (c *CSS) BgBlue() *CSS

设置背景颜色为 蓝色

Set the background colour to blue

func (*CSS) BgBrightBlue

func (c *CSS) BgBrightBlue() *CSS

设置背景颜色为亮蓝色

Set the background colour to bright blue

func (*CSS) BgBrightCyan

func (c *CSS) BgBrightCyan() *CSS

设置背景颜色为亮青色

Set the background colour to bright cyan

func (*CSS) BgBrightGreen

func (c *CSS) BgBrightGreen() *CSS

设置背景颜色为亮绿色

Set the background colour to bright green

func (*CSS) BgBrightMagenta

func (c *CSS) BgBrightMagenta() *CSS

设置背景颜色为亮品红色

Set the background colour to bright magenta

func (*CSS) BgBrightRed

func (c *CSS) BgBrightRed() *CSS

设置背景颜色为亮红色

Set the background colour to bright red

func (*CSS) BgBrightWhite

func (c *CSS) BgBrightWhite() *CSS

设置背景颜色为亮白色

Set the background colour to bright white

func (*CSS) BgBrightYellow

func (c *CSS) BgBrightYellow() *CSS

设置背景颜色为亮黄色

Set the background colour to bright yellow

func (*CSS) BgCyan

func (c *CSS) BgCyan() *CSS

设置背景颜色为青色

Set the background colour to cyan

func (*CSS) BgGray

func (c *CSS) BgGray() *CSS

设置背景颜色为灰色

Set the background colour to gray

func (*CSS) BgGreen

func (c *CSS) BgGreen() *CSS

设置背景颜色为绿色

Set the background colour to green

func (*CSS) BgMagenta

func (c *CSS) BgMagenta() *CSS

设置背景颜色为品红

Set the background colour to magenta

func (*CSS) BgRed

func (c *CSS) BgRed() *CSS

设置背景颜色为红色

Set the background colour to red

func (*CSS) BgWhite

func (c *CSS) BgWhite() *CSS

设置背景颜色为白色

Set the background colour to white

func (*CSS) BgYellow

func (c *CSS) BgYellow() *CSS

设置背景颜色为黄色

Set the background colour to yellow

func (*CSS) ColorBlack

func (c *CSS) ColorBlack() *CSS

设置前景色为黑色

Set foreground colour to black

func (*CSS) ColorBrightBule

func (c *CSS) ColorBrightBule() *CSS

设置前景色为亮蓝色

Set foreground colour to bright blue

func (*CSS) ColorBrightCyan

func (c *CSS) ColorBrightCyan() *CSS

设置前景亮青色

Set foreground colour to bright cyan

func (*CSS) ColorBrightGreen

func (c *CSS) ColorBrightGreen() *CSS

设置前景色为亮绿色

Set foreground colour to bright green

func (*CSS) ColorBrightMagenta

func (c *CSS) ColorBrightMagenta() *CSS

设置前景色为亮品红色

Set foreground colour to bright magenta

func (*CSS) ColorBrightRed

func (c *CSS) ColorBrightRed() *CSS

设置前景色为亮红色

Set foreground colour to bright red

func (*CSS) ColorBrightWhite

func (c *CSS) ColorBrightWhite() *CSS

设置前景色为亮白色

Set foreground colour to bright whilte

func (*CSS) ColorBrightYellow

func (c *CSS) ColorBrightYellow() *CSS

设置前景色为亮黄色

Set foreground colour to bright yellow

func (*CSS) ColorBule

func (c *CSS) ColorBule() *CSS

设置前景色为蓝色

Set foreground colour to blue

func (*CSS) ColorCray

func (c *CSS) ColorCray() *CSS

设置前景色为灰色

Set foreground colour to cray

func (*CSS) ColorCyan

func (c *CSS) ColorCyan() *CSS

设置前景青色

Set foreground colour to cyan

func (*CSS) ColorGreen

func (c *CSS) ColorGreen() *CSS

设置前景色为绿色

Set foreground colour to green

func (*CSS) ColorMagenta

func (c *CSS) ColorMagenta() *CSS

设置前景色为品红色

Set foreground colour to magenta

func (*CSS) ColorRed

func (c *CSS) ColorRed() *CSS

设置前景色为红色

Set foreground colour to red

Example
package main

import (
	"github.com/flylog/colorstyle"
)

func main() {
	colorstyle.New().ColorRed().Printf("a bold text: %s\n", "Hello 世界!")

}
Output:

func (*CSS) ColorWhite

func (c *CSS) ColorWhite() *CSS

设置前景色为白色

Set foreground colour to whilte

func (*CSS) ColorYellow

func (c *CSS) ColorYellow() *CSS

设置前景色为黄色

Set foreground colour to yellow

func (*CSS) Printf

func (c *CSS) Printf(format string, text ...interface{})

like fmt.Printf

Example
package main

import (
	"github.com/flylog/colorstyle"
)

func main() {
	colorstyle.New().ColorRed().Printf("a bold text: %s\n", "Hello 世界!")
}
Output:

func (*CSS) Println

func (c *CSS) Println(text ...interface{})

like fmt.Println

Example
package main

import (
	"github.com/flylog/colorstyle"
)

func main() {
	colorstyle.New().BgBlue().Println("a background color blue text")
}
Output:

func (*CSS) Sprint

func (c *CSS) Sprint(text ...interface{}) string

like fmt.Sprint

func (*CSS) Sprintf

func (c *CSS) Sprintf(format string, text ...interface{}) string

like fmt.Sprintf

func (*CSS) StyleBold

func (c *CSS) StyleBold() *CSS

设置字体样式为粗体

Set font style to bold

Example
package main

import (
	"github.com/flylog/colorstyle"
)

func main() {
	colorstyle.New().StyleBold().Printf("a bold text: %s\n", "Hello 世界!")
	// or
	css := colorstyle.New().StyleBold()
	css.Printf("a bold text: %s\n", "Hello 世界!")

}
Output:

func (*CSS) StyleDefault

func (c *CSS) StyleDefault() *CSS

设置字体样式为常规

Set font style to default

func (*CSS) StyleGrey

func (c *CSS) StyleGrey() *CSS

设置字体样式为灰显

Set font style to grey

func (*CSS) StyleHide

func (c *CSS) StyleHide() *CSS

设置字体样式为隐藏

Set font style to hide

func (*CSS) StyleItalic

func (c *CSS) StyleItalic() *CSS
func (c *CSS) StyleRapidBlink() *CSS

设置字体样式为缓慢闪烁

Set font style t0 rapid blink

func (*CSS) StyleReverse

func (c *CSS) StyleReverse() *CSS

设置字体样式为反显

Set font style to reverse

func (c *CSS) StyleSlowBlink() *CSS

设置字体样式为快速闪烁

Set font style t0 slow blink

func (*CSS) StyleStrikethrough

func (c *CSS) StyleStrikethrough() *CSS

设置字体样式为删除线,可能不支持

Set font style to strikethrough,may not be supported

func (*CSS) StyleUnderline

func (c *CSS) StyleUnderline() *CSS

设置字体样式为下划线

Set font style to underline

type Color

type Color int
const (
	FgBlack Color = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
	FgGray Color = iota + 82
	FgBrightRed
	FgBrightGreen
	FgBrightYellow
	FgBrightBlue
	FgBrightMagenta
	FgBrightCyan
	FgBrightWhite
)

type Style

type Style int
const (
	Normal        Style = iota // 默认值
	Bold                       // 加粗
	Grey                       // 灰显
	Italic                     // 斜体
	Underline                  // 下划线
	SlowBlink                  // 缓慢闪烁
	RapidBlink                 // 快速闪烁
	Reverse                    // 反显
	Hide                       // 隐藏
	Strikethrough              // 删除线
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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