refactor: move config.go to util pkg
This commit is contained in:
parent
0dbc7d3fd5
commit
9eede1a547
2 changed files with 34 additions and 33 deletions
5
main.go
5
main.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/ayntgl/discordgo"
|
||||
"github.com/ayntgl/discordo/util"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/zalando/go-keyring"
|
||||
|
|
@ -17,12 +18,12 @@ var (
|
|||
messageInputField *tview.InputField
|
||||
mainFlex *tview.Flex
|
||||
|
||||
conf *config
|
||||
conf *util.Config
|
||||
session *discordgo.Session
|
||||
)
|
||||
|
||||
func main() {
|
||||
conf = loadConfig()
|
||||
conf = util.LoadConfig()
|
||||
|
||||
tview.Borders = conf.Borders
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
|
@ -58,7 +58,7 @@ type borders struct {
|
|||
BottomRightFocus rune
|
||||
}
|
||||
|
||||
type config struct {
|
||||
type Config struct {
|
||||
Token string `toml:"token"`
|
||||
UserAgent string `toml:"user_agent"`
|
||||
Mouse bool `toml:"mouse"`
|
||||
|
|
@ -70,15 +70,14 @@ type config struct {
|
|||
Borders borders `toml:"borders"`
|
||||
}
|
||||
|
||||
func loadConfig() *config {
|
||||
func LoadConfig() *Config {
|
||||
configPath, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configPath += "/discordo.toml"
|
||||
|
||||
var c config
|
||||
var c Config
|
||||
if _, err = os.Stat(configPath); os.IsNotExist(err) {
|
||||
f, err := os.Create(configPath)
|
||||
if err != nil {
|
||||
|
|
@ -86,34 +85,35 @@ func loadConfig() *config {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
c.Mouse = true
|
||||
c.Notifications = true
|
||||
c.UserAgent = userAgent
|
||||
c.GetMessagesLimit = 50
|
||||
c.Theme = theme{
|
||||
Background: "black",
|
||||
c = Config{
|
||||
Mouse: true,
|
||||
Notifications: true,
|
||||
UserAgent: userAgent,
|
||||
GetMessagesLimit: 50,
|
||||
Borders: tview.Borders,
|
||||
Theme: theme{
|
||||
Background: "black",
|
||||
|
||||
Border: "white",
|
||||
Title: "white",
|
||||
Graphics: "white",
|
||||
Text: "white",
|
||||
Border: "white",
|
||||
Title: "white",
|
||||
Graphics: "white",
|
||||
Text: "white",
|
||||
},
|
||||
Keybindings: keybindings{
|
||||
FocusChannelsTree: "Alt+Left",
|
||||
FocusMessagesView: "Alt+Right",
|
||||
FocusMessageInputField: "Alt+Down",
|
||||
|
||||
SelectPreviousMessage: "Up",
|
||||
SelectNextMessage: "Down",
|
||||
SelectFirstMessage: "Home",
|
||||
SelectLastMessage: "End",
|
||||
ReplySelectedMessage: "Rune[r]",
|
||||
MentionReplySelectedMessage: "Rune[R]",
|
||||
CopySelectedMessage: "Rune[c]",
|
||||
SelectMessageReference: "Rune[m]",
|
||||
},
|
||||
}
|
||||
c.Keybindings = keybindings{
|
||||
FocusChannelsTree: "Alt+Left",
|
||||
FocusMessagesView: "Alt+Right",
|
||||
FocusMessageInputField: "Alt+Down",
|
||||
|
||||
SelectPreviousMessage: "Up",
|
||||
SelectNextMessage: "Down",
|
||||
SelectFirstMessage: "Home",
|
||||
SelectLastMessage: "End",
|
||||
ReplySelectedMessage: "Rune[r]",
|
||||
MentionReplySelectedMessage: "Rune[R]",
|
||||
CopySelectedMessage: "Rune[c]",
|
||||
SelectMessageReference: "Rune[m]",
|
||||
}
|
||||
c.Borders = tview.Borders
|
||||
|
||||
err = toml.NewEncoder(f).Encode(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
Loading…
Add table
Reference in a new issue