-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmodes.go
71 lines (59 loc) · 1.86 KB
/
modes.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
package ansi
// Modes represents the terminal modes that can be set or reset. By default,
// all modes are [ModeNotRecognized].
type Modes map[Mode]ModeSetting
// NewModes creates a new Modes map. By default, all modes are
// [ModeNotRecognized].
func NewModes() Modes {
return make(Modes)
}
// Get returns the setting of a terminal mode. If the mode is not set, it
// returns [ModeNotRecognized].
func (m Modes) Get(mode Mode) ModeSetting {
return m[mode]
}
// Delete deletes a terminal mode. This has the same effect as setting the mode
// to [ModeNotRecognized].
func (m Modes) Delete(mode Mode) {
delete(m, mode)
}
// Set sets a terminal mode to [ModeSet].
func (m Modes) Set(modes ...Mode) {
for _, mode := range modes {
m[mode] = ModeSet
}
}
// PermanentlySet sets a terminal mode to [ModePermanentlySet].
func (m Modes) PermanentlySet(modes ...Mode) {
for _, mode := range modes {
m[mode] = ModePermanentlySet
}
}
// Reset sets a terminal mode to [ModeReset].
func (m Modes) Reset(modes ...Mode) {
for _, mode := range modes {
m[mode] = ModeReset
}
}
// PermanentlyReset sets a terminal mode to [ModePermanentlyReset].
func (m Modes) PermanentlyReset(modes ...Mode) {
for _, mode := range modes {
m[mode] = ModePermanentlyReset
}
}
// IsSet returns true if the mode is set to [ModeSet] or [ModePermanentlySet].
func (m Modes) IsSet(mode Mode) bool {
return m[mode].IsSet()
}
// IsPermanentlySet returns true if the mode is set to [ModePermanentlySet].
func (m Modes) IsPermanentlySet(mode Mode) bool {
return m[mode].IsPermanentlySet()
}
// IsReset returns true if the mode is set to [ModeReset] or [ModePermanentlyReset].
func (m Modes) IsReset(mode Mode) bool {
return m[mode].IsReset()
}
// IsPermanentlyReset returns true if the mode is set to [ModePermanentlyReset].
func (m Modes) IsPermanentlyReset(mode Mode) bool {
return m[mode].IsPermanentlyReset()
}