-
Notifications
You must be signed in to change notification settings - Fork 2
/
ui.go
56 lines (49 loc) · 1.11 KB
/
ui.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
package main
import (
"io"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
var (
app *tview.Application
textView *tview.TextView
setupDone = make(chan struct{})
uiDone = make(chan struct{})
)
func uiSetup(title string, w *io.Writer) {
*argHuman = true
app = tview.NewApplication()
textView = tview.NewTextView().SetDynamicColors(true)
textView.SetWrap(false).SetBorder(true).SetTitle(title)
textView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Rune() == 'q' || event.Rune() == 'Q' {
app.Stop()
return nil
}
return event
})
*w = tview.ANSIWriter(textView)
go func() {
if err := app.SetRoot(textView, true).Run(); err != nil {
panic(err)
}
close(uiDone)
}()
close(setupDone)
}
func uiRun() {
<-setupDone
textView.ScrollToBeginning()
app.Draw()
<-uiDone
setupDone = make(chan struct{})
uiDone = make(chan struct{})
}
func uiWrapProcessFile(process func(_ io.Writer, path string)) func(io.Writer, string) {
return func(_ io.Writer, path string) {
var outWriter io.Writer
uiSetup(path, &outWriter)
process(outWriter, path)
uiRun()
}
}