Skip to content

Commit

Permalink
Be more precise about which keypresses are accepted
Browse files Browse the repository at this point in the history
This already works in practice but could be tricked into activating with
a tcell key input that does not represent a legitimate keypress.
  • Loading branch information
gcla committed Oct 30, 2020
1 parent 822445d commit 308da69
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,8 @@ func cycleView(app gowid.IApp, forward bool, tabMap map[gowid.IWidget]gowid.IWid
func mainKeyPress(evk *tcell.EventKey, app gowid.IApp) bool {
handled := true

isrune := evk.Key() == tcell.KeyRune

if evk.Key() == tcell.KeyCtrlC && Loader.State()&pcap.LoadingPsml != 0 {
PcapScheduler.RequestStopLoadStage1(NoHandlers{}) // iface and psml
} else if evk.Key() == tcell.KeyTAB || evk.Key() == tcell.KeyBacktab {
Expand All @@ -1694,7 +1696,7 @@ func mainKeyPress(evk *tcell.EventKey, app gowid.IApp) bool {

cycleView(app, isTab, tabMap)

} else if evk.Rune() == '|' {
} else if isrune && evk.Rune() == '|' {
if mainViewNoKeys.SubWidget() == mainview {
mainViewNoKeys.SetSubWidget(altview1, app)
termshark.SetConf("main.layout", "altview1")
Expand All @@ -1705,7 +1707,7 @@ func mainKeyPress(evk *tcell.EventKey, app gowid.IApp) bool {
mainViewNoKeys.SetSubWidget(mainview, app)
termshark.SetConf("main.layout", "mainview")
}
} else if evk.Rune() == '\\' {
} else if isrune && evk.Rune() == '\\' {
w := mainViewNoKeys.SubWidget()
fp := gowid.FocusPath(w)
if w == viewOnlyPacketList || w == viewOnlyPacketStructure || w == viewOnlyPacketHex {
Expand Down Expand Up @@ -1733,7 +1735,7 @@ func mainKeyPress(evk *tcell.EventKey, app gowid.IApp) bool {
gowid.SetFocusPath(viewOnlyPacketList, maxViewPath, app)
}
}
} else if evk.Rune() == '/' {
} else if isrune && evk.Rune() == '/' {
setFocusOnDisplayFilter(app)
} else {
handled = false
Expand All @@ -1745,13 +1747,15 @@ func mainKeyPress(evk *tcell.EventKey, app gowid.IApp) bool {
func appKeyPress(evk *tcell.EventKey, app gowid.IApp) bool {
handled := true
// gcla later todo - check for rune!
isrune := evk.Key() == tcell.KeyRune

if evk.Key() == tcell.KeyCtrlC {
reallyQuit(app)
} else if evk.Key() == tcell.KeyCtrlL {
app.Sync()
} else if evk.Rune() == 'q' || evk.Rune() == 'Q' {
} else if isrune && (evk.Rune() == 'q' || evk.Rune() == 'Q') {
reallyQuit(app)
} else if evk.Rune() == ':' {
} else if isrune && evk.Rune() == ':' {
lastLineMode(app)
} else if evk.Key() == tcell.KeyEscape {
gowid.SetFocusPath(mainview, menuPathMain, app)
Expand All @@ -1762,21 +1766,21 @@ func appKeyPress(evk *tcell.EventKey, app gowid.IApp) bool {
gowid.SetFocusPath(viewOnlyPacketHex, menuPathMax, app)

generalMenu.Open(openMenuSite, app)
} else if evk.Rune() == '?' {
} else if isrune && evk.Rune() == '?' {
OpenTemplatedDialog(appView, "UIHelp", app)
} else if evk.Key() == tcell.KeyRune && evk.Rune() == 'Z' && keyState.PartialZCmd {
} else if isrune && evk.Rune() == 'Z' && keyState.PartialZCmd {
RequestQuit()
} else if evk.Rune() == 'Z' {
} else if isrune && evk.Rune() == 'Z' {
keyState.PartialZCmd = true
} else if evk.Rune() == 'm' {
} else if isrune && evk.Rune() == 'm' {
keyState.PartialmCmd = true
} else if evk.Rune() == '\'' {
} else if isrune && evk.Rune() == '\'' {
keyState.PartialQuoteCmd = true
} else if evk.Rune() == 'g' {
} else if isrune && evk.Rune() == 'g' {
keyState.PartialgCmd = true
} else if evk.Key() == tcell.KeyCtrlW {
keyState.PartialCtrlWCmd = true
} else if evk.Rune() >= '0' && evk.Rune() <= '9' {
} else if isrune && evk.Rune() >= '0' && evk.Rune() <= '9' {
if keyState.NumberPrefix == -1 {
keyState.NumberPrefix = int(evk.Rune() - '0')
} else {
Expand Down

0 comments on commit 308da69

Please sign in to comment.