Add commandwindow to focus cycle
MODIFY
ui/commandview.go
ui/commandview.go
@@ -48,35 +48,41 @@ func NewCommandView(onExecuteCommand func(command string)) *CommandView {
return cmdView
}
-func (cmdView *CommandView) handleInput(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModNone {
- if event.Key() == tcell.KeyPgUp {
- handler := cmdView.commandOutput.InputHandler()
- handler(tcell.NewEventKey(tcell.KeyPgUp, 0, tcell.ModNone), nil)
+// SetInputCaptureForInput defines the input capture for the input component of
+// the command view while priorizing the predefined handler before passing the
+// event to the externally specified handler.
+func (cmdView *CommandView) SetInputCaptureForInput(handler func(event *tcell.EventKey) *tcell.EventKey) {
+ cmdView.commandInput.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
+ passedEvent := cmdView.handleInput(event)
+
+ if passedEvent == nil {
return nil
}
- if event.Key() == tcell.KeyPgDn {
- handler := cmdView.commandOutput.InputHandler()
- handler(tcell.NewEventKey(tcell.KeyPgDn, 0, tcell.ModNone), nil)
- return nil
+ return handler(passedEvent)
+ })
}
+// SetInputCaptureForOutput defines the input capture for the output component
+// of the command view while priorizing the predefined handler before passing
+// the event to the externally specified handler.
+func (cmdView *CommandView) SetInputCaptureForOutput(handler func(event *tcell.EventKey) *tcell.EventKey) {
+ cmdView.commandOutput.SetInputCapture(handler)
}
- if event.Modifiers() == tcell.ModCtrl {
- if event.Key() == tcell.KeyUp {
+func (cmdView *CommandView) handleInput(event *tcell.EventKey) *tcell.EventKey {
+ if event.Modifiers() == tcell.ModNone {
+ if event.Key() == tcell.KeyPgUp {
handler := cmdView.commandOutput.InputHandler()
- handler(tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModNone), nil)
+ handler(tcell.NewEventKey(tcell.KeyPgUp, 0, tcell.ModNone), nil)
return nil
}
- if event.Key() == tcell.KeyDown {
+ if event.Key() == tcell.KeyPgDn {
handler := cmdView.commandOutput.InputHandler()
- handler(tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone), nil)
+ handler(tcell.NewEventKey(tcell.KeyPgDn, 0, tcell.ModNone), nil)
return nil
}
- }
if event.Key() == tcell.KeyEnter {
cmdView.commandHistoryIndex = -1
@@ -120,6 +126,21 @@ func (cmdView *CommandView) handleInput(event *tcell.EventKey) *tcell.EventKey {
cmdView.commandInput.SetText(cmdView.commandHistory[cmdView.commandHistoryIndex])
}
+ }
+
+ if event.Modifiers() == tcell.ModCtrl {
+ if event.Key() == tcell.KeyUp {
+ handler := cmdView.commandOutput.InputHandler()
+ handler(tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModNone), nil)
+ return nil
+ }
+
+ if event.Key() == tcell.KeyDown {
+ handler := cmdView.commandOutput.InputHandler()
+ handler(tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone), nil)
+ return nil
+ }
+ }
return event
}

MODIFY
ui/window.go
ui/window.go
@@ -375,11 +375,20 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
messageToSend := window.messageInput.GetText()
if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyUp || event.Key() == tcell.KeyDown {
+ if event.Key() == tcell.KeyUp {
window.app.SetFocus(window.chatView.internalTextView)
return nil
}
+ if event.Key() == tcell.KeyDown {
+ if window.commandMode {
+ window.app.SetFocus(window.commandView.commandOutput)
+ } else {
+ window.app.SetFocus(window.chatView.internalTextView)
+ }
+ return nil
+ }
+
if event.Key() == tcell.KeyRight {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
@@ -601,14 +610,22 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
if event.Key() == tcell.KeyLeft {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
+ } else {
+ if window.commandMode {
+ window.app.SetFocus(window.commandView.commandOutput)
} else {
window.app.SetFocus(window.messageInput.GetPrimitive())
}
+ }
return nil
}
if event.Key() == tcell.KeyRight {
+ if window.commandMode {
+ window.app.SetFocus(window.commandView.commandOutput)
+ } else {
window.app.SetFocus(window.messageInput.GetPrimitive())
+ }
return nil
}
}
@@ -633,11 +650,20 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
oldChatViewHandler := window.chatView.internalTextView.GetInputCapture()
newChatViewHandler := func(event *tcell.EventKey) *tcell.EventKey {
if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyDown || event.Key() == tcell.KeyUp {
+ if event.Key() == tcell.KeyDown {
window.app.SetFocus(window.messageInput.GetPrimitive())
return nil
}
+ if event.Key() == tcell.KeyUp {
+ if window.commandMode {
+ window.app.SetFocus(window.commandView.commandInput.internalTextView)
+ } else {
+ window.app.SetFocus(window.messageInput.GetPrimitive())
+ }
+ return nil
+ }
+
if event.Key() == tcell.KeyLeft {
if window.leftArea.GetCurrentPage() == guildPageName {
window.app.SetFocus(window.guildList)
@@ -751,6 +777,54 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
})
}
+ window.commandView.SetInputCaptureForInput(func(event *tcell.EventKey) *tcell.EventKey {
+ if event.Modifiers() == tcell.ModAlt {
+ if event.Key() == tcell.KeyUp {
+ window.app.SetFocus(window.commandView.commandOutput)
+ } else if event.Key() == tcell.KeyDown {
+ window.app.SetFocus(window.chatView.GetPrimitive())
+ } else if event.Key() == tcell.KeyRight {
+ if window.userList.internalTreeView.IsVisible() {
+ window.app.SetFocus(window.userList.internalTreeView)
+ } else {
+ window.app.SetFocus(window.channelTree.internalTreeView)
+ }
+ } else if event.Key() == tcell.KeyLeft {
+ window.app.SetFocus(window.channelTree.internalTreeView)
+ } else {
+ return event
+ }
+
+ return nil
+ }
+
+ return event
+ })
+
+ window.commandView.SetInputCaptureForOutput(func(event *tcell.EventKey) *tcell.EventKey {
+ if event.Modifiers() == tcell.ModAlt {
+ if event.Key() == tcell.KeyUp {
+ window.app.SetFocus(window.messageInput.GetPrimitive())
+ } else if event.Key() == tcell.KeyDown {
+ window.app.SetFocus(window.commandView.commandInput.GetPrimitive())
+ } else if event.Key() == tcell.KeyRight {
+ if window.userList.internalTreeView.IsVisible() {
+ window.app.SetFocus(window.userList.internalTreeView)
+ } else {
+ window.app.SetFocus(window.channelTree.internalTreeView)
+ }
+ } else if event.Key() == tcell.KeyLeft {
+ window.app.SetFocus(window.channelTree.internalTreeView)
+ } else {
+ return event
+ }
+
+ return nil
+ }
+
+ return event
+ })
+
window.middleContainer = tview.NewFlex().
SetDirection(tview.FlexColumn)

Add commandwindow to focus cycle