Bläddra i källkod

Move global variables declaration to pertinent file

ayntgl 4 år sedan
förälder
incheckning
f84c232aab
4 ändrade filer med 40 tillägg och 34 borttagningar
  1. 2 0
      config.go
  2. 6 0
      discord.go
  3. 1 34
      main.go
  4. 31 0
      ui.go

+ 2 - 0
config.go

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

+ 6 - 0
discord.go

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

+ 1 - 34
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 - 0
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.