Move global variables declaration to pertinent file
This commit is contained in:
parent
d6c4fbb903
commit
f84c232aab
4 changed files with 40 additions and 34 deletions
|
|
@ -7,6 +7,8 @@ import (
|
|||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
var conf *config
|
||||
|
||||
type keybindings struct {
|
||||
GuildsTreeViewFocus string
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ import (
|
|||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
var (
|
||||
session *discordgo.Session
|
||||
selectedChannel *discordgo.Channel
|
||||
selectedMessage *discordgo.Message
|
||||
)
|
||||
|
||||
func newSession() *discordgo.Session {
|
||||
s, err := discordgo.New()
|
||||
if err != nil {
|
||||
|
|
|
|||
35
main.go
35
main.go
|
|
@ -1,37 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/ayntgl/discordgo"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/zalando/go-keyring"
|
||||
)
|
||||
|
||||
const service = "discordo"
|
||||
|
||||
var (
|
||||
app *tview.Application
|
||||
loginForm *tview.Form
|
||||
guildsTreeView *tview.TreeView
|
||||
messagesTextView *tview.TextView
|
||||
messageInputField *tview.InputField
|
||||
mainFlex *tview.Flex
|
||||
|
||||
conf *config
|
||||
session *discordgo.Session
|
||||
selectedChannel *discordgo.Channel
|
||||
selectedMessage *discordgo.Message
|
||||
)
|
||||
|
||||
func main() {
|
||||
conf = loadConfig()
|
||||
tview.Styles = conf.Theme
|
||||
|
||||
app = tview.NewApplication()
|
||||
app.
|
||||
EnableMouse(conf.Mouse).
|
||||
SetInputCapture(onAppInputCapture)
|
||||
|
||||
app = newApplication()
|
||||
guildsTreeView = newGuildsTreeView()
|
||||
messagesTextView = newMessagesTextView()
|
||||
messageInputField = newMessageInputField()
|
||||
|
|
@ -70,19 +50,6 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func onAppInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
||||
switch e.Name() {
|
||||
case conf.Keybindings.GuildsTreeViewFocus:
|
||||
app.SetFocus(guildsTreeView)
|
||||
case conf.Keybindings.MessagesTextViewFocus:
|
||||
app.SetFocus(messagesTextView)
|
||||
case conf.Keybindings.MessageInputFieldFocus:
|
||||
app.SetFocus(messageInputField)
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func onLoginFormLoginButtonSelected() {
|
||||
email := loginForm.GetFormItem(0).(*tview.InputField).GetText()
|
||||
password := loginForm.GetFormItem(1).(*tview.InputField).GetText()
|
||||
|
|
|
|||
31
ui.go
31
ui.go
|
|
@ -10,6 +10,37 @@ import (
|
|||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
var (
|
||||
app *tview.Application
|
||||
loginForm *tview.Form
|
||||
guildsTreeView *tview.TreeView
|
||||
messagesTextView *tview.TextView
|
||||
messageInputField *tview.InputField
|
||||
mainFlex *tview.Flex
|
||||
)
|
||||
|
||||
func newApplication() *tview.Application {
|
||||
a := tview.NewApplication()
|
||||
a.
|
||||
EnableMouse(conf.Mouse).
|
||||
SetInputCapture(onAppInputCapture)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func onAppInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
||||
switch e.Name() {
|
||||
case conf.Keybindings.GuildsTreeViewFocus:
|
||||
app.SetFocus(guildsTreeView)
|
||||
case conf.Keybindings.MessagesTextViewFocus:
|
||||
app.SetFocus(messagesTextView)
|
||||
case conf.Keybindings.MessageInputFieldFocus:
|
||||
app.SetFocus(messageInputField)
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func newGuildsTreeView() *tview.TreeView {
|
||||
w := tview.NewTreeView()
|
||||
w.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue