This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
style.go
76 lines (67 loc) · 2.58 KB
/
style.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2015 The Tops'l Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use 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.
package topsl
// Attribute represents a single color, or additional attributes such as
// bold, reverse, underline. For the moment, we are not supporting the entire
// 256 color palette. We should explore that later.
type Attribute uint16
// Style incorporates the various elements of a style, both foreground and
// background. Logically the foreground occupies the upper 16 bits, and the
// background the lower 16, but applications must not depend on that.
type Style uint32
func (s Style) Fg() Attribute {
return Attribute(uint32(s) >> 16)
}
func (s Style) Bg() Attribute {
return Attribute(uint32(s) & 0xffff)
}
func (s Style) Normal() Style {
fg := s.Fg()
bg := s.Bg()
fg &= ^(AttrReverse | AttrBold | AttrUnderline)
bg &= ^(AttrReverse | AttrBold | AttrUnderline)
return NewStyle(fg, bg)
}
func (s Style) Bold() Style {
return NewStyle(s.Fg()|AttrBold, s.Bg())
}
func (s Style) Blink() Style {
return NewStyle(s.Fg(), s.Bg()|AttrBold)
}
func (s Style) Underline() Style {
return NewStyle(s.Fg()|AttrUnderline, s.Bg()|AttrUnderline)
}
func (s Style) Reverse() Style {
return NewStyle(s.Fg()|AttrReverse, s.Bg()|AttrReverse)
}
func NewStyle(fg, bg Attribute) Style {
return Style((uint32(fg) << 16) | uint32(bg))
}
// Some stock styles
var (
StyleDefault = NewStyle(ColorWhite, ColorBlack)
StyleText = NewStyle(ColorWhite, ColorBlack)
StyleTextBar = NewStyle(ColorBlack, ColorWhite)
StyleTitle = NewStyle(ColorBlack, ColorWhite)
StyleGood = NewStyle(ColorGreen, ColorBlack)
StyleError = NewStyle(ColorRed, ColorBlack)
StyleWarn = NewStyle(ColorYellow, ColorBlack)
StyleStatus = NewStyle(ColorBlack, ColorWhite)
StyleStatusError = NewStyle(ColorWhite|AttrBold, ColorRed)
StyleStatusGood = NewStyle(ColorWhite|AttrBold, ColorGreen)
StyleStatusWarn = NewStyle(ColorWhite|AttrBold, ColorYellow)
StyleStatusDim = NewStyle(ColorWhite|AttrBold, ColorWhite)
StyleKey = NewStyle(ColorBlack, ColorWhite)
StyleKeyHot = NewStyle(ColorBlue|AttrBold, ColorWhite)
)