Documentation ¶
Overview ¶
cterm
ColorTerm is a library designed to make cross platform colored console output simple.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetColors ¶
func SetColors(fg, bg Color)
SetColors sets the console foreground and background colors to the specified values.
Example ¶
SetColors(PINK, GRAY) fmt.Printf("Hello world!") SetColorsSTD()
Output: �[47m�[95mHello world!�[0m
func SetColorsSTD ¶
func SetColorsSTD()
SetColorsSTD sets the the console foreground and background colors to the platform default values.
Example ¶
SetColors(PINK, GRAY) fmt.Printf("Here the colors are set to non-default values") SetColorsSTD() fmt.Printf("\nThis text uses platform default colors...")
Output: �[47m�[95mHere the colors are set to non-default values�[0m This text uses platform default colors...
Types ¶
type Color ¶
type Color int
const ( // The following colors can be used to specify text or msg background color. BLACK Color = iota DBLUE Color = iota DGREEN Color = iota DCYAN Color = iota DRED Color = iota DPINK Color = iota DYELLOW Color = iota GRAY Color = iota DGRAY Color = iota BLUE Color = iota GREEN Color = iota CYAN Color = iota RED Color = iota PINK Color = iota YELLOW Color = iota WHITE Color = iota )
type Message ¶
This is the fundamental structure of this library. Each cterm.Message contains a string as well as the color information of both the background and foreground.
The implementation of the associated method Show() is platform specific.
func NewMessage ¶
Creates a new (potentailly colorful) message using a minimal amount of input.
At minimum, a message can be created by only specifying a the string contents of the Message. When this is done, the default foreground/text color and default background color will be used for the message.
Optionally, the forground/text color and the background color of a Message can be specified by supplying addtional arguments. The first addtional argument (if supplied) will be used as the forground/text color. Similarly, the second addtional argument (if supplied) will be used as the background color. If it is desired to only set the background color, then the color `cterm.STDFG` should be used for the first addtional argument.
Example ¶
msg1 := NewMessage("Text with default colors, ") msg2 := NewMessage("Text, fg color specified, ", BLUE) msg3 := NewMessage("Text, fg and bg color specified.", DBLUE, WHITE) fmt.Println(msg1) fmt.Println(msg2) fmt.Println(msg3)
Output: {7 -1 Text with default colors, } {9 -1 Text, fg color specified, } {1 15 Text, fg and bg color specified.}
type MessageBlock ¶
type MessageBlock struct {
Blocks []Message
}
This struct is simply an array of Messages. Using a message block might be preferable when constructing a complex set of messages. This struct also has the added advantage of providing a single `Show()` method which will print out all of the contained messages in the order they appear in the array.
func NewMessageBlock ¶
func NewMessageBlock(msgs []Message) MessageBlock
Example ¶
mb := NewMessageBlock([]Message{ NewMessage("msg one,"), NewMessage(" msg two [BLUE],", BLUE), NewMessage(" msg three [RED]", RED)}) mb.Show() fmt.Println()
Output: �[0mmsg one,�[40m�[94m msg two [BLUE],�[40m�[91m msg three [RED]�[0m
func (*MessageBlock) Append ¶
func (self *MessageBlock) Append(msg string, optColors ...Color)
Appends a new (potentailly colorful) message to the end of a MessageBlock using a minimal amount of input.
At minimum, a message can be created by only specifying a the string contents of the Message. When this is done, the default foreground/text color and default background color will be used for the message.
Optionally, the forground/text color and the background color of a Message can be specified by supplying addtional arguments. The first addtional argument (if supplied) will be used as the forground/text color. Similarly, the second addtional argument (if supplied) will be used as the background color. If it is desired to only set the background color, then the color `cterm.STDFG` should be used for the first addtional argument.
Example ¶
var mb MessageBlock mb.Append("Text with default colors\n") mb.Append("Text, fg color specified\n", RED) mb.Append("Text, fg and bg color specified\n", DBLUE, WHITE) fmt.Println(mb.Blocks[0]) fmt.Println(mb.Blocks[1]) fmt.Println(mb.Blocks[2])
Output: {7 -1 Text with default colors } {12 -1 Text, fg color specified } {1 15 Text, fg and bg color specified }
func (*MessageBlock) AppendBlock ¶
func (self *MessageBlock) AppendBlock(mb MessageBlock)
Appends one message block to the end of another
func (*MessageBlock) Show ¶
func (self *MessageBlock) Show()
The Show method prints out all of the contained messages of a MessageBlock in the order they appear in the internal array.
Example ¶
var mb MessageBlock mb.Append("Text with default colors\n") mb.Show()
Output: �[0mText with default colors