mode_toaster_fake_test.go RawHistoryFolder
1package ui
2
3import (
4 "github.com/bnema/puregotk/v4/glib"
5
6 "github.com/bnema/dumber/internal/ui/input"
7)
8
9// fakeModeToasterView records what the mode toaster asks its view to paint.
10type fakeModeToasterView struct {
11 header string
12 headers []string // every distinct header, in order
13 mode input.Mode
14 chevron chevronState
15 pillShown bool
16 interactive bool
17 bodyShown bool
18 lingering bool
19 animations bool
20 style string
21 groups []legendGroup
22 dimmed map[string]bool
23 flashed map[string]bool
24 flashable map[string]bool
25 rect func() (int, int, int, int, bool)
26 destroyed bool
27}
28
29func newFakeModeToasterView() *fakeModeToasterView {
30 return &fakeModeToasterView{dimmed: map[string]bool{}, flashed: map[string]bool{}, flashable: map[string]bool{}}
31}
32
33func (f *fakeModeToasterView) setHeader(text string) {
34 if text != f.header {
35 f.headers = append(f.headers, text)
36 }
37 f.header = text
38}
39func (f *fakeModeToasterView) setMode(mode input.Mode) { f.mode = mode }
40func (f *fakeModeToasterView) setChevron(c chevronState) { f.chevron = c }
41func (f *fakeModeToasterView) setPillVisible(v bool) { f.pillShown = v }
42func (f *fakeModeToasterView) setPillInteractive(v bool) { f.interactive = v }
43func (f *fakeModeToasterView) setStyle(style string) { f.style = style }
44func (f *fakeModeToasterView) setAnimations(v bool) { f.animations = v }
45func (f *fakeModeToasterView) setBodyVisible(v bool) { f.bodyShown = v }
46func (f *fakeModeToasterView) setBodyLingering(v bool) { f.lingering = v }
47func (f *fakeModeToasterView) setActionDimmed(a string, d bool) { f.dimmed[a] = d }
48func (f *fakeModeToasterView) clearFlash() { f.flashed = map[string]bool{} }
49func (f *fakeModeToasterView) destroy() { f.destroyed = true }
50func (f *fakeModeToasterView) setLegend(groups []legendGroup) {
51 f.groups = groups
52 f.dimmed = map[string]bool{} // new rows start undimmed
53 f.flashable = map[string]bool{}
54 for _, group := range groups {
55 for _, row := range group.Rows {
56 f.flashable[row.Action] = true
57 }
58 }
59}
60
61func (f *fakeModeToasterView) flashAction(action string) bool {
62 if !f.flashable[action] {
63 return false
64 }
65 f.flashed = map[string]bool{action: true}
66 return true
67}
68
69func (f *fakeModeToasterView) lingerRect() (int, int, int, int, bool) {
70 if f.rect == nil {
71 return 0, 0, 0, 0, false
72 }
73 return f.rect()
74}
75
76// newFakeModeToasterWindow returns a window whose mode toaster paints into a
77// fake view.
78func newFakeModeToasterWindow(id string) (*browserWindow, *fakeModeToasterView) {
79 view := newFakeModeToasterView()
80 return &browserWindow{id: id, modeToaster: newModeToasterWithView(view, nil)}, view
81}
82
83// pumpMainContext runs pending GLib sources (show delays, flash timers).
84func pumpMainContext() {
85 ctx := glib.MainContextDefault()
86 for ctx.Pending() {
87 ctx.Iteration(false)
88 }
89}