-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
thememode_gen.go
94 lines (81 loc) · 1.75 KB
/
thememode_gen.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Code generated from "enum.go.tmpl" - DO NOT EDIT.
/*
* Copyright ©2021-2023 by Richard A. Wilkes. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, version 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, version 2.0.
*/
package thememode
import (
"strings"
"github.com/richardwilkes/toolbox/i18n"
)
// Possible values.
const (
Auto Enum = iota
Dark
Light
)
// All possible values.
var All = []Enum{
Auto,
Dark,
Light,
}
// Enum holds the theme display mode.
type Enum byte
// EnsureValid ensures this is of a known value.
func (e Enum) EnsureValid() Enum {
if e <= Light {
return e
}
return Auto
}
// Key returns the key used in serialization.
func (e Enum) Key() string {
switch e {
case Auto:
return "auto"
case Dark:
return "dark"
case Light:
return "light"
default:
return Auto.Key()
}
}
// String implements fmt.Stringer.
func (e Enum) String() string {
switch e {
case Auto:
return i18n.Text("Automatic")
case Dark:
return i18n.Text("Dark")
case Light:
return i18n.Text("Light")
default:
return Auto.String()
}
}
// MarshalText implements the encoding.TextMarshaler interface.
func (e Enum) MarshalText() (text []byte, err error) {
return []byte(e.Key()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (e *Enum) UnmarshalText(text []byte) error {
*e = Extract(string(text))
return nil
}
// Extract the value from a string.
func Extract(str string) Enum {
for _, e := range All {
if strings.EqualFold(e.Key(), str) {
return e
}
}
return Auto
}