Rename cfg to config

This commit is contained in:
ayn2op 2023-01-09 20:21:58 +05:30
parent 5a0d5e2aa1
commit 3af0076bd1
8 changed files with 62 additions and 47 deletions

2
go.mod
View file

@ -19,6 +19,7 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/pkg/errors v0.9.1 // indirect
@ -27,4 +28,5 @@ require (
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

16
go.sum
View file

@ -2,6 +2,7 @@ github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVK
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
@ -22,6 +23,14 @@ github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlI
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
@ -35,6 +44,8 @@ github.com/rivo/tview v0.0.0-20230104153304-892d1a2eb0da/go.mod h1:lBUy/T5kyMudF
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
@ -80,8 +91,11 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -24,20 +24,20 @@ func newGuildsTree() *GuildsTree {
root: tview.NewTreeNode(""),
}
gt.SetGraphics(cfg.Theme.GuildsTree.Graphics)
gt.SetGraphics(config.Theme.GuildsTree.Graphics)
gt.SetRoot(gt.root)
gt.SetTopLevel(1)
gt.SetSelectedFunc(gt.onSelected)
gt.SetBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor))
gt.SetBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
gt.SetTitle("Guilds")
gt.SetTitleColor(tcell.GetColor(cfg.Theme.TitleColor))
gt.SetTitleColor(tcell.GetColor(config.Theme.TitleColor))
gt.SetTitleAlign(tview.AlignLeft)
p := cfg.Theme.BorderPadding
gt.SetBorder(cfg.Theme.Border)
gt.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
p := config.Theme.BorderPadding
gt.SetBorder(config.Theme.Border)
gt.SetBorderColor(tcell.GetColor(config.Theme.BorderColor))
gt.SetBorderPadding(p[0], p[1], p[2], p[3])
return gt
@ -150,7 +150,7 @@ func (gt *GuildsTree) onSelected(n *tview.TreeNode) {
gt.selectedChannel = c
messagesText.SetTitle(gt.channelToString(*c))
ms, err := discordState.Messages(ref, cfg.MessagesLimit)
ms, err := discordState.Messages(ref, config.MessagesLimit)
if err != nil {
log.Println(err)
return

View file

@ -24,11 +24,11 @@ func newLoginForm() *LoginForm {
lf.AddButton("Login", lf.onLoginButtonSelected)
lf.SetTitle("Login")
lf.SetTitleColor(tcell.GetColor(cfg.Theme.TitleColor))
lf.SetTitleColor(tcell.GetColor(config.Theme.TitleColor))
p := cfg.Theme.BorderPadding
lf.SetBorder(cfg.Theme.Border)
lf.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
p := config.Theme.BorderPadding
lf.SetBorder(config.Theme.Border)
lf.SetBorderColor(tcell.GetColor(config.Theme.BorderColor))
lf.SetBorderPadding(p[0], p[1], p[2], p[3])
return lf

13
main.go
View file

@ -14,12 +14,11 @@ import (
var (
token string
cfg *Config
config *Config
discordState *State
app = tview.NewApplication()
flex = tview.NewFlex()
app = tview.NewApplication()
flex = tview.NewFlex()
guildsTree *GuildsTree
messagesText *MessagesText
messageInput *MessageInput
@ -64,12 +63,12 @@ func main() {
}
}
cfg, err = newConfig()
config, err = newConfig()
if err != nil {
log.Fatal(err)
}
// Initialize UI
// UI must be initialized after the configuration has been loaded and before the plugins are loaded.
guildsTree = newGuildsTree()
messagesText = newMessagesText()
messageInput = newMessageInput()
@ -95,7 +94,7 @@ func main() {
app.SetRoot(flex, true)
}
app.EnableMouse(cfg.Mouse)
app.EnableMouse(config.Mouse)
err = app.Run()
if err != nil {
log.Fatal(err)

View file

@ -24,15 +24,15 @@ func newMessageInput() *MessageInput {
}
mi.SetInputCapture(mi.onInputCapture)
mi.SetBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor))
mi.SetFieldBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor))
mi.SetBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
mi.SetFieldBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
mi.SetTitleColor(tcell.GetColor(cfg.Theme.TitleColor))
mi.SetTitleColor(tcell.GetColor(config.Theme.TitleColor))
mi.SetTitleAlign(tview.AlignLeft)
p := cfg.Theme.BorderPadding
mi.SetBorder(cfg.Theme.Border)
mi.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
p := config.Theme.BorderPadding
mi.SetBorder(config.Theme.Border)
mi.SetBorderColor(tcell.GetColor(config.Theme.BorderColor))
mi.SetBorderPadding(p[0], p[1], p[2], p[3])
return mi
@ -45,16 +45,16 @@ func (mi *MessageInput) reset() {
func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
switch event.Name() {
case cfg.Keys.MessageInput.Send:
case config.Keys.MessageInput.Send:
mi.sendAction()
return nil
case cfg.Keys.MessageInput.Paste:
case config.Keys.MessageInput.Paste:
mi.pasteAction()
return nil
case cfg.Keys.MessageInput.LaunchEditor:
case config.Keys.MessageInput.LaunchEditor:
messageInput.launchEditorAction()
return nil
case cfg.Keys.Cancel:
case config.Keys.Cancel:
mi.reset()
return nil
}
@ -116,7 +116,7 @@ func (mi *MessageInput) pasteAction() {
}
func (mi *MessageInput) launchEditorAction() {
e := cfg.Editor
e := config.Editor
if e == "default" {
e = os.Getenv("EDITOR")
}

View file

@ -37,15 +37,15 @@ func newMessagesText() *MessagesText {
app.Draw()
})
mt.SetBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor))
mt.SetBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
mt.SetTitle("Messages")
mt.SetTitleColor(tcell.GetColor(cfg.Theme.TitleColor))
mt.SetTitleColor(tcell.GetColor(config.Theme.TitleColor))
mt.SetTitleAlign(tview.AlignLeft)
p := cfg.Theme.BorderPadding
mt.SetBorder(cfg.Theme.Border)
mt.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
p := config.Theme.BorderPadding
mt.SetBorder(config.Theme.Border)
mt.SetBorderColor(tcell.GetColor(config.Theme.BorderColor))
mt.SetBorderPadding(p[0], p[1], p[2], p[3])
return mt
@ -74,7 +74,7 @@ func (mt *MessagesText) createMessage(m *discord.Message) error {
mt.buf.WriteByte(' ')
mt.buf.WriteByte('[')
mt.buf.WriteString(cfg.Theme.MessagesText.AuthorColor)
mt.buf.WriteString(config.Theme.MessagesText.AuthorColor)
mt.buf.WriteByte(']')
mt.buf.WriteString(m.ReferencedMessage.Author.Username)
mt.buf.WriteString("[-] ")
@ -98,12 +98,12 @@ func (mt *MessagesText) createMessage(m *discord.Message) error {
func (mt *MessagesText) createHeader(m *discord.Message) {
mt.buf.WriteByte('[')
mt.buf.WriteString(cfg.Theme.MessagesText.AuthorColor)
mt.buf.WriteString(config.Theme.MessagesText.AuthorColor)
mt.buf.WriteByte(']')
mt.buf.WriteString(m.Author.Username)
mt.buf.WriteString("[-] ")
if cfg.Timestamps {
if config.Timestamps {
mt.buf.WriteString("[::d]")
mt.buf.WriteString(m.Timestamp.Format(time.Kitchen))
mt.buf.WriteString("[::-] ")
@ -127,31 +127,31 @@ func (mt *MessagesText) createFooter(m *discord.Message) {
func (mt *MessagesText) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
switch event.Name() {
case cfg.Keys.MessagesText.CopyContent:
case config.Keys.MessagesText.CopyContent:
mt.copyContentAction()
return nil
case cfg.Keys.MessagesText.Reply:
case config.Keys.MessagesText.Reply:
mt.replyAction(false)
return nil
case cfg.Keys.MessagesText.ReplyMention:
case config.Keys.MessagesText.ReplyMention:
mt.replyAction(true)
return nil
case cfg.Keys.MessagesText.SelectPrevious:
case config.Keys.MessagesText.SelectPrevious:
mt.selectPreviousAction()
return nil
case cfg.Keys.MessagesText.SelectNext:
case config.Keys.MessagesText.SelectNext:
mt.selectNextAction()
return nil
case cfg.Keys.MessagesText.SelectFirst:
case config.Keys.MessagesText.SelectFirst:
mt.selectFirstAction()
return nil
case cfg.Keys.MessagesText.SelectLast:
case config.Keys.MessagesText.SelectLast:
mt.selectLastAction()
return nil
case cfg.Keys.MessagesText.SelectReply:
case config.Keys.MessagesText.SelectReply:
mt.selectReplyAction()
return nil
case cfg.Keys.Cancel:
case config.Keys.Cancel:
guildsTree.selectedChannel = nil
messagesText.reset()

View file