-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame.go
58 lines (54 loc) · 1.5 KB
/
frame.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
package ilse
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/tjmtmmnk/ilse/filter"
)
var (
frame *tview.Application
)
func initFrame() error {
if err := initPages(); err != nil {
return err
}
frame = tview.NewApplication().SetScreen(app.screen)
frame.SetRoot(pages, true).EnableMouse(true)
frame.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
currentPage, _ := pages.GetFrontPage()
if currentPage != mainPage {
return event
}
switch key := event.Key(); {
case key == tcell.KeyRune || key == tcell.KeyBackspace || key == tcell.KeyBackspace2:
frame.SetFocus(searchBar)
case key == tcell.KeyDown && searchBar.HasFocus():
frame.SetFocus(list)
case key == tcell.KeyCtrlW:
app.searchOption.Mode = filter.WordMatch
updateSearchBarHeader()
case key == tcell.KeyCtrlE:
app.searchOption.Mode = filter.HeadMatch
updateSearchBarHeader()
case key == tcell.KeyCtrlT:
app.searchOption.Case = !app.searchOption.Case
updateSearchBarHeader()
case key == tcell.KeyCtrlR:
app.searchOption.Mode = filter.Regex
updateSearchBarHeader()
case key == tcell.KeyCtrlG:
app.searchOption.Command = filter.RipGrep
updateSearchBarHeader()
case key == tcell.KeyCtrlF:
app.searchOption.Command = filter.FuzzySearch
updateSearchBarHeader()
case key == tcell.KeyCtrlD:
pages.SwitchToPage("tree")
case key == tcell.KeyCtrlN:
app.searchOption.TargetDir = ""
case key == tcell.KeyCtrlB:
clearAll()
}
return event
})
return nil
}