-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtristate.go
62 lines (52 loc) · 1.75 KB
/
tristate.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
/* -----------------------------------------------------------------
* L o r d O f S c r i p t s (tm)
* Copyright (C)2024 Dídimo Grimaldo T.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
*-----------------------------------------------------------------*/
package wipechromium
/* ----------------------------------------------------------------
* G l o b a l s
*-----------------------------------------------------------------*/
const (
Undecided TriState = iota
No
Yes
)
var (
TriStateDefaultLabels = []string{"Undecided", "No", "Yes"}
TriStateDingbatLabels = []string{"\u2753", "\u2718", "\u2714"} // ❓ ✘ ✔
TriStateSquarishLabels = []string{"\u2b1a", "\u2b1c", "\u2b1b"} // ⬚ ⬜ ⬛
TriStateSquareLabels = []string{"\u2610", "\u2612", "\u2611"} // ☐ ☒ ☑
)
/* ----------------------------------------------------------------
* I n t e r f a c e s
*-----------------------------------------------------------------*/
/* ----------------------------------------------------------------
* T y p e s
*-----------------------------------------------------------------*/
type TriState uint
/* ----------------------------------------------------------------
* M e t h o d s
*-----------------------------------------------------------------*/
func (t TriState) String() string {
return t.StringWith(TriStateDefaultLabels)
}
func (t TriState) StringWith(v []string) string {
if len(v) != 3 && len(v) != 4 {
panic("TriState.StringWith() must have 3 or 4 strings")
}
if t == Undecided {
return v[0]
} else if t == No {
return v[1]
} else if t == Yes {
return v[2]
} else {
if len(v) == 3 {
return "!!!Invalid"
} else {
return v[3] // user-defined invalid label
}
}
}