Skip to content

Commit 44e4c96

Browse files
committed
GUI log box keyboard navigation
1 parent 85c8510 commit 44e4c96

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

gui.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var txtStdout *tview.TextView
1919
var txtStderr *tview.TextView
2020
var UIselectedConfigPath string
2121
var UItmpConfigPath string
22+
var currentSelector int = 1
2223

2324
func InitUI() {
2425
UIapp = tview.NewApplication()
@@ -37,6 +38,14 @@ func MainWindow() {
3738
SetText(RenderFastfinderVersion()).
3839
SetTextAlign(tview.AlignCenter)
3940

41+
/*
42+
* TEXTVIEW : selection box helper
43+
*/
44+
txtInfoTitle := tview.NewTextView().
45+
SetDynamicColors(true).
46+
SetText("Press tab to navigate between log box | Up and Down arrow to scroll").
47+
SetTextAlign(tview.AlignCenter)
48+
4049
/*
4150
* TEXTVIEW : File matchs
4251
*/
@@ -59,9 +68,9 @@ func MainWindow() {
5968
UIapp.Draw()
6069
})
6170

62-
/*
63-
* TEXTVIEW : execution errors
64-
*/
71+
/*
72+
* TEXTVIEW : execution errors
73+
*/
6574
txtStderr.
6675
SetDynamicColors(true).
6776
SetText("[red]Access and scan errors:\n").
@@ -73,11 +82,33 @@ func MainWindow() {
7382
/*
7483
* Building window
7584
*/
76-
grid := tview.NewGrid().SetRows(1, -5, -2).SetColumns(0, 0).SetBorders(true)
85+
grid := tview.NewGrid().SetRows(1, -5, -2, 1).SetColumns(0, 0).SetBorders(true)
7786
grid.AddItem(txtAppTitle, 0, 0, 1, 2, 0, 0, false)
7887
grid.AddItem(txtMatchs, 1, 1, 1, 1, 0, 0, false)
7988
grid.AddItem(txtStderr, 1, 0, 1, 1, 0, 0, false)
8089
grid.AddItem(txtStdout, 2, 0, 1, 2, 0, 0, false)
90+
grid.AddItem(txtInfoTitle, 3, 0, 1, 2, 0, 0, false)
91+
92+
grid.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
93+
if event.Key() == tcell.KeyTab {
94+
switch currentSelector {
95+
case 1:
96+
currentSelector++
97+
UIapp.SetFocus(txtStdout)
98+
txtInfoTitle.SetText("Selected box: Informations messages")
99+
case 2:
100+
currentSelector++
101+
UIapp.SetFocus(txtStderr)
102+
txtInfoTitle.SetText("Selected box: Error messages")
103+
case 3:
104+
currentSelector = 1
105+
UIapp.SetFocus(txtMatchs)
106+
txtInfoTitle.SetText("Selected box: Matchs messages")
107+
}
108+
return nil
109+
}
110+
return event
111+
})
81112

82113
AppStarted = true
83114
if err := UIapp.SetRoot(grid, true).SetFocus(txtMatchs).Run(); err != nil {

0 commit comments

Comments
 (0)