about summary refs log tree commit diff stats
path: root/029tools.cc
diff options
context:
space:
mode:
Diffstat (limited to '029tools.cc')
0 files changed, 0 insertions, 0 deletions
revious revision' href='/akspecs/aerc/blame/ui/render.go?h=0.1.1&id=db1b2cd53f5dc7bfbfb6ee54ad0bb0882ea2cc03'>^
4074445 ^

db1b2cd ^
db1b2cd ^




77a0f68 ^




db1b2cd ^






77a0f68 ^
55e8453 ^
77a0f68 ^
4074445 ^









77a0f68 ^

db1b2cd ^



55e8453 ^





77a0f68 ^










db1b2cd ^
77a0f68 ^








db1b2cd ^
4074445 ^

77a0f68 ^


db1b2cd ^

55e8453 ^


77a0f68 ^


55e8453 ^
77a0f68 ^



db1b2cd ^


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









                                                            
                                   
                                            
 

                                                        
         




                                                    




                                                        






                               
                                           
                            
                                            









                                                                     

 



                                             





                                                   










                                        
                                   








                                                       
                 

                                                   


                        

                                    


                                                           


                                                                  
                                                   



                                                            


                   
package ui

import (
	tb "github.com/nsf/termbox-go"

	"git.sr.ht/~sircmpwn/aerc2/config"
)

func Initialize(conf *config.AercConfig) (*UIState, error) {
	state := UIState{
		Config:       conf,
		InvalidPanes: InvalidateAll,

		tbEvents:     make(chan tb.Event, 10),
		workerEvents: make(chan wrappedMessage),
	}
	if err := tb.Init(); err != nil {
		return nil, err
	}
	tb.SetInputMode(tb.InputEsc | tb.InputMouse)
	tb.SetOutputMode(tb.Output256)
	go (func() {
		for !state.Exit {
			state.tbEvents <- tb.PollEvent()
		}
	})()
	return &state, nil
}

func (state *UIState) Close() {
	tb.Close()
}

func (state *UIState) AddTab(tab AercTab) {
	tab.SetParent(state)
	state.Tabs = append(state.Tabs, tab)
	if listener, ok := tab.(WorkerListener); ok {
		go (func() {
			for msg := range listener.GetChannel() {
				state.workerEvents <- wrappedMessage{
					msg:      msg,
					listener: listener,
				}
			}
		})()
	}
}

func (state *UIState) Invalidate(what uint) {
	state.InvalidPanes |= what
}

func (state *UIState) InvalidateFrom(tab AercTab) {
	if state.Tabs[state.SelectedTab] == tab {
		state.Invalidate(InvalidateTabView)
	}
}

func (state *UIState) calcGeometries() {
	width, height := tb.Size()
	// TODO: more
	state.Panes.TabView = Geometry{
		Row:    0,
		Col:    0,
		Width:  width,
		Height: height,
	}
}

func (state *UIState) Tick() bool {
	select {
	case event := <-state.tbEvents:
		switch event.Type {
		case tb.EventKey:
			if event.Key == tb.KeyEsc {
				state.Exit = true
			}
		case tb.EventResize:
			state.Invalidate(InvalidateAll)
		}
	case msg := <-state.workerEvents:
		msg.listener.HandleMessage(msg.msg)
	default:
		// no-op
		break
	}
	if state.InvalidPanes != 0 {
		invalid := state.InvalidPanes
		state.InvalidPanes = 0
		if invalid&InvalidateAll == InvalidateAll {
			tb.Clear(tb.ColorDefault, tb.ColorDefault)
			state.calcGeometries()
		}
		if invalid&InvalidateTabView != 0 {
			tab := state.Tabs[state.SelectedTab]
			tab.Render(state.Panes.TabView)
		}
		tb.Flush()
	}
	return true
}