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 ¶
- Constants
- func Black(text ...interface{}) string
- func Blue(text ...interface{}) string
- func BrightBlue(text ...interface{}) string
- func BrightCyan(text ...interface{}) string
- func BrightMagenta(text ...interface{}) string
- func BrightRed(text ...interface{}) string
- func BrightWhite(text ...interface{}) string
- func BrightYellow(text ...interface{}) string
- func Cyan(text ...interface{}) string
- func Gray(text ...interface{}) string
- func Green(text ...interface{}) string
- func Magenta(text ...interface{}) string
- func Red(text ...interface{}) string
- func White(text ...interface{}) string
- func Yellow(text ...interface{}) string
- type BgColor
- type CSS
- func (c *CSS) BgBlack() *CSS
- func (c *CSS) BgBlue() *CSS
- func (c *CSS) BgBrightBlue() *CSS
- func (c *CSS) BgBrightCyan() *CSS
- func (c *CSS) BgBrightGreen() *CSS
- func (c *CSS) BgBrightMagenta() *CSS
- func (c *CSS) BgBrightRed() *CSS
- func (c *CSS) BgBrightWhite() *CSS
- func (c *CSS) BgBrightYellow() *CSS
- func (c *CSS) BgCyan() *CSS
- func (c *CSS) BgGray() *CSS
- func (c *CSS) BgGreen() *CSS
- func (c *CSS) BgMagenta() *CSS
- func (c *CSS) BgRed() *CSS
- func (c *CSS) BgWhite() *CSS
- func (c *CSS) BgYellow() *CSS
- func (c *CSS) ColorBlack() *CSS
- func (c *CSS) ColorBrightBule() *CSS
- func (c *CSS) ColorBrightCyan() *CSS
- func (c *CSS) ColorBrightGreen() *CSS
- func (c *CSS) ColorBrightMagenta() *CSS
- func (c *CSS) ColorBrightRed() *CSS
- func (c *CSS) ColorBrightWhite() *CSS
- func (c *CSS) ColorBrightYellow() *CSS
- func (c *CSS) ColorBule() *CSS
- func (c *CSS) ColorCray() *CSS
- func (c *CSS) ColorCyan() *CSS
- func (c *CSS) ColorGreen() *CSS
- func (c *CSS) ColorMagenta() *CSS
- func (c *CSS) ColorRed() *CSS
- func (c *CSS) ColorWhite() *CSS
- func (c *CSS) ColorYellow() *CSS
- func (c *CSS) Printf(format string, text ...interface{})
- func (c *CSS) Println(text ...interface{})
- func (c *CSS) Sprint(text ...interface{}) string
- func (c *CSS) Sprintf(format string, text ...interface{}) string
- func (c *CSS) StyleBold() *CSS
- func (c *CSS) StyleDefault() *CSS
- func (c *CSS) StyleGrey() *CSS
- func (c *CSS) StyleHide() *CSS
- func (c *CSS) StyleItalic() *CSS
- func (c *CSS) StyleRapidBlink() *CSS
- func (c *CSS) StyleReverse() *CSS
- func (c *CSS) StyleSlowBlink() *CSS
- func (c *CSS) StyleStrikethrough() *CSS
- func (c *CSS) StyleUnderline() *CSS
- type Color
- type Style
Examples ¶
Constants ¶
View Source
const ( ANSI_SET = "\033[" // ANSI转义码,设置文本样式的开头 ANSI_END = "m" // 设置结束字符 ANSI_RESET = "\033[0m" // ANSI转义码,重置设置到常规 )
Variables ¶
This section is empty.
Functions ¶
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 BrightMagenta ¶
func BrightMagenta(text ...interface{}) string
生成亮品红的文本
Generate bright magenta text
func BrightYellow ¶
func BrightYellow(text ...interface{}) string
生成亮黄色的文本
Generate bright yellow text
Types ¶
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) ColorRed ¶
设置前景色为红色
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) Printf ¶
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) StyleBold ¶
设置字体样式为粗体
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) StyleItalic ¶
func (*CSS) StyleStrikethrough ¶
设置字体样式为删除线,可能不支持
Set font style to strikethrough,may not be supported
Click to show internal directories.
Click to hide internal directories.