Move global variables declaration to pertinent file

This commit is contained in:
ayntgl 2021-09-24 19:16:21 +04:00
parent d6c4fbb903
commit f84c232aab
4 changed files with 40 additions and 34 deletions

View file

@ -7,6 +7,8 @@ import (
"github.com/rivo/tview"
)
var conf *config
type keybindings struct {
GuildsTreeViewFocus string

View file

@ -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
View file

@ -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
View file

@ -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.