-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumgen.go
533 lines (474 loc) · 13.2 KB
/
enumgen.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
// Code generated by "goki generate"; DO NOT EDIT.
package texteditor
import (
"errors"
"strconv"
"strings"
"sync/atomic"
"goki.dev/enums"
"goki.dev/gi/v2/gi"
)
var _BufSignalsValues = []BufSignals{0, 1, 2, 3, 4, 5, 6}
// BufSignalsN is the highest valid value
// for type BufSignals, plus one.
const BufSignalsN BufSignals = 7
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the enumgen command to generate them again.
func _BufSignalsNoOp() {
var x [1]struct{}
_ = x[BufDone-(0)]
_ = x[BufNew-(1)]
_ = x[BufMods-(2)]
_ = x[BufInsert-(3)]
_ = x[BufDelete-(4)]
_ = x[BufMarkUpdt-(5)]
_ = x[BufClosed-(6)]
}
var _BufSignalsNameToValueMap = map[string]BufSignals{
`BufDone`: 0,
`bufdone`: 0,
`BufNew`: 1,
`bufnew`: 1,
`BufMods`: 2,
`bufmods`: 2,
`BufInsert`: 3,
`bufinsert`: 3,
`BufDelete`: 4,
`bufdelete`: 4,
`BufMarkUpdt`: 5,
`bufmarkupdt`: 5,
`BufClosed`: 6,
`bufclosed`: 6,
}
var _BufSignalsDescMap = map[BufSignals]string{
0: `BufDone means that editing was completed and applied to Txt field -- data is Txt bytes`,
1: `BufNew signals that entirely new text is present. All views should do full layout update.`,
2: `BufMods signals that potentially diffuse modifications have been made. Views should do a Layout and Render.`,
3: `BufInsert signals that some text was inserted. data is textbuf.Edit describing change. The Buf always reflects the current state *after* the edit.`,
4: `BufDelete signals that some text was deleted. data is textbuf.Edit describing change. The Buf always reflects the current state *after* the edit.`,
5: `BufMarkUpdt signals that the Markup text has been updated This signal is typically sent from a separate goroutine, so should be used with a mutex`,
6: `BufClosed signals that the textbuf was closed.`,
}
var _BufSignalsMap = map[BufSignals]string{
0: `BufDone`,
1: `BufNew`,
2: `BufMods`,
3: `BufInsert`,
4: `BufDelete`,
5: `BufMarkUpdt`,
6: `BufClosed`,
}
// String returns the string representation
// of this BufSignals value.
func (i BufSignals) String() string {
if str, ok := _BufSignalsMap[i]; ok {
return str
}
return strconv.FormatInt(int64(i), 10)
}
// SetString sets the BufSignals value from its
// string representation, and returns an
// error if the string is invalid.
func (i *BufSignals) SetString(s string) error {
if val, ok := _BufSignalsNameToValueMap[s]; ok {
*i = val
return nil
}
if val, ok := _BufSignalsNameToValueMap[strings.ToLower(s)]; ok {
*i = val
return nil
}
return errors.New(s + " is not a valid value for type BufSignals")
}
// Int64 returns the BufSignals value as an int64.
func (i BufSignals) Int64() int64 {
return int64(i)
}
// SetInt64 sets the BufSignals value from an int64.
func (i *BufSignals) SetInt64(in int64) {
*i = BufSignals(in)
}
// Desc returns the description of the BufSignals value.
func (i BufSignals) Desc() string {
if str, ok := _BufSignalsDescMap[i]; ok {
return str
}
return i.String()
}
// BufSignalsValues returns all possible values
// for the type BufSignals.
func BufSignalsValues() []BufSignals {
return _BufSignalsValues
}
// Values returns all possible values
// for the type BufSignals.
func (i BufSignals) Values() []enums.Enum {
res := make([]enums.Enum, len(_BufSignalsValues))
for i, d := range _BufSignalsValues {
res[i] = d
}
return res
}
// IsValid returns whether the value is a
// valid option for type BufSignals.
func (i BufSignals) IsValid() bool {
_, ok := _BufSignalsMap[i]
return ok
}
// MarshalText implements the [encoding.TextMarshaler] interface.
func (i BufSignals) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (i *BufSignals) UnmarshalText(text []byte) error {
return i.SetString(string(text))
}
var _BufFlagsValues = []BufFlags{9, 10, 11, 12}
// BufFlagsN is the highest valid value
// for type BufFlags, plus one.
const BufFlagsN BufFlags = 13
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the enumgen command to generate them again.
func _BufFlagsNoOp() {
var x [1]struct{}
_ = x[BufAutoSaving-(9)]
_ = x[BufMarkingUp-(10)]
_ = x[BufChanged-(11)]
_ = x[BufFileModOk-(12)]
}
var _BufFlagsNameToValueMap = map[string]BufFlags{
`AutoSaving`: 9,
`autosaving`: 9,
`MarkingUp`: 10,
`markingup`: 10,
`Changed`: 11,
`changed`: 11,
`FileModOk`: 12,
`filemodok`: 12,
}
var _BufFlagsDescMap = map[BufFlags]string{
9: `BufAutoSaving is used in atomically safe way to protect autosaving`,
10: `BufMarkingUp indicates current markup operation in progress -- don't redo`,
11: `BufChanged indicates if the text has been changed (edited) relative to the original, since last save`,
12: `BufFileModOk have already asked about fact that file has changed since being opened, user is ok`,
}
var _BufFlagsMap = map[BufFlags]string{
9: `AutoSaving`,
10: `MarkingUp`,
11: `Changed`,
12: `FileModOk`,
}
// String returns the string representation
// of this BufFlags value.
func (i BufFlags) String() string {
str := ""
for _, ie := range gi.WidgetFlagsValues() {
if i.HasFlag(ie) {
ies := ie.BitIndexString()
if str == "" {
str = ies
} else {
str += "|" + ies
}
}
}
for _, ie := range _BufFlagsValues {
if i.HasFlag(ie) {
ies := ie.BitIndexString()
if str == "" {
str = ies
} else {
str += "|" + ies
}
}
}
return str
}
// BitIndexString returns the string
// representation of this BufFlags value
// if it is a bit index value
// (typically an enum constant), and
// not an actual bit flag value.
func (i BufFlags) BitIndexString() string {
if str, ok := _BufFlagsMap[i]; ok {
return str
}
return gi.WidgetFlags(i).BitIndexString()
}
// SetString sets the BufFlags value from its
// string representation, and returns an
// error if the string is invalid.
func (i *BufFlags) SetString(s string) error {
*i = 0
return i.SetStringOr(s)
}
// SetStringOr sets the BufFlags value from its
// string representation while preserving any
// bit flags already set, and returns an
// error if the string is invalid.
func (i *BufFlags) SetStringOr(s string) error {
flgs := strings.Split(s, "|")
for _, flg := range flgs {
if val, ok := _BufFlagsNameToValueMap[flg]; ok {
i.SetFlag(true, &val)
} else if val, ok := _BufFlagsNameToValueMap[strings.ToLower(flg)]; ok {
i.SetFlag(true, &val)
} else {
err := (*gi.WidgetFlags)(i).SetStringOr(flg)
if err != nil {
return err
}
}
}
return nil
}
// Int64 returns the BufFlags value as an int64.
func (i BufFlags) Int64() int64 {
return int64(i)
}
// SetInt64 sets the BufFlags value from an int64.
func (i *BufFlags) SetInt64(in int64) {
*i = BufFlags(in)
}
// Desc returns the description of the BufFlags value.
func (i BufFlags) Desc() string {
if str, ok := _BufFlagsDescMap[i]; ok {
return str
}
return gi.WidgetFlags(i).Desc()
}
// BufFlagsValues returns all possible values
// for the type BufFlags.
func BufFlagsValues() []BufFlags {
es := gi.WidgetFlagsValues()
res := make([]BufFlags, len(es))
for i, e := range es {
res[i] = BufFlags(e)
}
res = append(res, _BufFlagsValues...)
return res
}
// Values returns all possible values
// for the type BufFlags.
func (i BufFlags) Values() []enums.Enum {
es := gi.WidgetFlagsValues()
les := len(es)
res := make([]enums.Enum, les+len(_BufFlagsValues))
for i, d := range es {
res[i] = d
}
for i, d := range _BufFlagsValues {
res[i+les] = d
}
return res
}
// IsValid returns whether the value is a
// valid option for type BufFlags.
func (i BufFlags) IsValid() bool {
_, ok := _BufFlagsMap[i]
if !ok {
return gi.WidgetFlags(i).IsValid()
}
return ok
}
// HasFlag returns whether these
// bit flags have the given bit flag set.
func (i BufFlags) HasFlag(f enums.BitFlag) bool {
return atomic.LoadInt64((*int64)(&i))&(1<<uint32(f.Int64())) != 0
}
// SetFlag sets the value of the given
// flags in these flags to the given value.
func (i *BufFlags) SetFlag(on bool, f ...enums.BitFlag) {
var mask int64
for _, v := range f {
mask |= 1 << v.Int64()
}
in := int64(*i)
if on {
in |= mask
atomic.StoreInt64((*int64)(i), in)
} else {
in &^= mask
atomic.StoreInt64((*int64)(i), in)
}
}
// MarshalText implements the [encoding.TextMarshaler] interface.
func (i BufFlags) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (i *BufFlags) UnmarshalText(text []byte) error {
return i.SetString(string(text))
}
var _EditorFlagsValues = []EditorFlags{9, 10, 11}
// EditorFlagsN is the highest valid value
// for type EditorFlags, plus one.
const EditorFlagsN EditorFlags = 12
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the enumgen command to generate them again.
func _EditorFlagsNoOp() {
var x [1]struct{}
_ = x[EditorHasLineNos-(9)]
_ = x[EditorLastWasTabAI-(10)]
_ = x[EditorLastWasUndo-(11)]
}
var _EditorFlagsNameToValueMap = map[string]EditorFlags{
`EditorHasLineNos`: 9,
`editorhaslinenos`: 9,
`EditorLastWasTabAI`: 10,
`editorlastwastabai`: 10,
`EditorLastWasUndo`: 11,
`editorlastwasundo`: 11,
}
var _EditorFlagsDescMap = map[EditorFlags]string{
9: `EditorHasLineNos indicates that this editor has line numbers (per Buf option)`,
10: `EditorLastWasTabAI indicates that last key was a Tab auto-indent`,
11: `EditorLastWasUndo indicates that last key was an undo`,
}
var _EditorFlagsMap = map[EditorFlags]string{
9: `EditorHasLineNos`,
10: `EditorLastWasTabAI`,
11: `EditorLastWasUndo`,
}
// String returns the string representation
// of this EditorFlags value.
func (i EditorFlags) String() string {
str := ""
for _, ie := range gi.WidgetFlagsValues() {
if i.HasFlag(ie) {
ies := ie.BitIndexString()
if str == "" {
str = ies
} else {
str += "|" + ies
}
}
}
for _, ie := range _EditorFlagsValues {
if i.HasFlag(ie) {
ies := ie.BitIndexString()
if str == "" {
str = ies
} else {
str += "|" + ies
}
}
}
return str
}
// BitIndexString returns the string
// representation of this EditorFlags value
// if it is a bit index value
// (typically an enum constant), and
// not an actual bit flag value.
func (i EditorFlags) BitIndexString() string {
if str, ok := _EditorFlagsMap[i]; ok {
return str
}
return gi.WidgetFlags(i).BitIndexString()
}
// SetString sets the EditorFlags value from its
// string representation, and returns an
// error if the string is invalid.
func (i *EditorFlags) SetString(s string) error {
*i = 0
return i.SetStringOr(s)
}
// SetStringOr sets the EditorFlags value from its
// string representation while preserving any
// bit flags already set, and returns an
// error if the string is invalid.
func (i *EditorFlags) SetStringOr(s string) error {
flgs := strings.Split(s, "|")
for _, flg := range flgs {
if val, ok := _EditorFlagsNameToValueMap[flg]; ok {
i.SetFlag(true, &val)
} else if val, ok := _EditorFlagsNameToValueMap[strings.ToLower(flg)]; ok {
i.SetFlag(true, &val)
} else {
err := (*gi.WidgetFlags)(i).SetStringOr(flg)
if err != nil {
return err
}
}
}
return nil
}
// Int64 returns the EditorFlags value as an int64.
func (i EditorFlags) Int64() int64 {
return int64(i)
}
// SetInt64 sets the EditorFlags value from an int64.
func (i *EditorFlags) SetInt64(in int64) {
*i = EditorFlags(in)
}
// Desc returns the description of the EditorFlags value.
func (i EditorFlags) Desc() string {
if str, ok := _EditorFlagsDescMap[i]; ok {
return str
}
return gi.WidgetFlags(i).Desc()
}
// EditorFlagsValues returns all possible values
// for the type EditorFlags.
func EditorFlagsValues() []EditorFlags {
es := gi.WidgetFlagsValues()
res := make([]EditorFlags, len(es))
for i, e := range es {
res[i] = EditorFlags(e)
}
res = append(res, _EditorFlagsValues...)
return res
}
// Values returns all possible values
// for the type EditorFlags.
func (i EditorFlags) Values() []enums.Enum {
es := gi.WidgetFlagsValues()
les := len(es)
res := make([]enums.Enum, les+len(_EditorFlagsValues))
for i, d := range es {
res[i] = d
}
for i, d := range _EditorFlagsValues {
res[i+les] = d
}
return res
}
// IsValid returns whether the value is a
// valid option for type EditorFlags.
func (i EditorFlags) IsValid() bool {
_, ok := _EditorFlagsMap[i]
if !ok {
return gi.WidgetFlags(i).IsValid()
}
return ok
}
// HasFlag returns whether these
// bit flags have the given bit flag set.
func (i EditorFlags) HasFlag(f enums.BitFlag) bool {
return atomic.LoadInt64((*int64)(&i))&(1<<uint32(f.Int64())) != 0
}
// SetFlag sets the value of the given
// flags in these flags to the given value.
func (i *EditorFlags) SetFlag(on bool, f ...enums.BitFlag) {
var mask int64
for _, v := range f {
mask |= 1 << v.Int64()
}
in := int64(*i)
if on {
in |= mask
atomic.StoreInt64((*int64)(i), in)
} else {
in &^= mask
atomic.StoreInt64((*int64)(i), in)
}
}
// MarshalText implements the [encoding.TextMarshaler] interface.
func (i EditorFlags) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (i *EditorFlags) UnmarshalText(text []byte) error {
return i.SetString(string(text))
}