termui/style.go

66 lines
1.3 KiB
Go
Raw Normal View History

2019-01-23 21:12:10 -07:00
package termui
// Color is an integer from -1 to 255
2019-02-01 23:16:02 -07:00
// -1 = ColorClear
// 0-255 = Xterm colors
2019-01-23 21:12:10 -07:00
type Color int
2019-02-01 23:16:02 -07:00
// ColorClear clears the Fg or Bg color of a Style
const ColorClear Color = -1
2019-01-23 21:12:10 -07:00
// Basic terminal colors
const (
ColorBlack Color = 0
ColorRed Color = 1
ColorGreen Color = 2
ColorYellow Color = 3
ColorBlue Color = 4
ColorMagenta Color = 5
ColorCyan Color = 6
ColorWhite Color = 7
)
type Modifier uint
const (
2019-02-01 23:16:02 -07:00
// ModifierClear clears any modifiers
2019-01-23 21:12:10 -07:00
ModifierClear Modifier = 0
ModifierBold Modifier = 1 << 9
ModifierUnderline Modifier = 1 << 10
ModifierReverse Modifier = 1 << 11
)
2019-02-01 23:16:02 -07:00
// Style represents the style of one terminal cell
2019-01-23 21:12:10 -07:00
type Style struct {
Fg Color
Bg Color
Modifier Modifier
}
2019-02-01 23:16:02 -07:00
// StyleClear represents a default Style, with no colors or modifiers
2019-01-23 21:12:10 -07:00
var StyleClear = Style{
Fg: ColorClear,
Bg: ColorClear,
Modifier: ModifierClear,
}
2019-02-01 23:16:02 -07:00
// NewStyle takes 1 to 3 arguments
2019-01-23 21:12:10 -07:00
// 1st argument = Fg
// 2nd argument = optional Bg
// 3rd argument = optional Modifier
func NewStyle(fg Color, args ...interface{}) Style {
bg := ColorClear
modifier := ModifierClear
if len(args) >= 1 {
bg = args[0].(Color)
}
if len(args) == 2 {
modifier = args[1].(Modifier)
}
return Style{
fg,
bg,
modifier,
}
}