From 3be7497ea54284d3364129f0b3e14c71d8b44ffa Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Wed, 21 Jul 2021 19:56:16 +0400 Subject: [PATCH] Improve default colors --- discordo.go | 14 ++++---------- ui/app.go | 9 +++------ ui/dropdowns.go | 12 ++++-------- ui/flex.go | 6 +++--- ui/forms.go | 10 +++------- ui/inputfields.go | 14 +++++--------- ui/lists.go | 14 +++++++------- ui/modals.go | 10 ++++++---- ui/textviews.go | 12 ++++-------- util/discord.go | 4 ++-- util/keyring.go | 4 ++-- 11 files changed, 43 insertions(+), 66 deletions(-) diff --git a/discordo.go b/discordo.go index 48915d9..b8a58a3 100644 --- a/discordo.go +++ b/discordo.go @@ -27,12 +27,14 @@ var currentGuild gateway.GuildCreateEvent var currentChannel discord.Channel func main() { + tview.Styles.PrimitiveBackgroundColor = tcell.GetColor("#1C1E26") + loginModal = ui.NewLoginModal(onLoginModalDone) guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected) channelsList = ui.NewChannelsList(onChannelsListSelected) messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged) mainFlex = ui.NewMainFlex(guildsDropDown, channelsList, messagesTextView) - app = ui.NewApplication(onApplicationInputCapture) + app = ui.NewApplication() token := util.GetPassword("token") if token != "" { @@ -45,7 +47,7 @@ func main() { app.SetRoot(loginModal, true) } - if err := app.Run(); err != nil { + if err := app.EnableMouse(true).Run(); err != nil { panic(err) } } @@ -54,14 +56,6 @@ func onLoginFormQuitButtonSelected() { app.Stop() } -func onApplicationInputCapture(event *tcell.EventKey) *tcell.EventKey { - if event.Key() == tcell.KeyCtrlR { - app.Sync() - } - - return event -} - func onMessagesTextViewChanged() { app.Draw() } diff --git a/ui/app.go b/ui/app.go index a936fb6..5ae112a 100644 --- a/ui/app.go +++ b/ui/app.go @@ -1,14 +1,11 @@ package ui import ( - "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) -func NewApplication(onApplicationInputCapture func(event *tcell.EventKey) *tcell.EventKey) *tview.Application { - app := tview.NewApplication(). - EnableMouse(true). - SetInputCapture(onApplicationInputCapture) +func NewApplication() (app *tview.Application) { + app = tview.NewApplication() - return app + return } diff --git a/ui/dropdowns.go b/ui/dropdowns.go index f67fb53..f42a052 100644 --- a/ui/dropdowns.go +++ b/ui/dropdowns.go @@ -1,21 +1,17 @@ package ui import ( - "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) -var guildsDropDownBackgroundColor = tcell.GetColor("#1C1E26") - -func NewGuildsDropDown(onGuildsDropDownSelected func(text string, index int)) *tview.DropDown { - guildsDropDown := tview.NewDropDown(). +func NewGuildsDropDown(onGuildsDropDownSelected func(text string, index int)) (guildsDropDown *tview.DropDown) { + guildsDropDown = tview.NewDropDown(). SetLabel("Guild: "). SetSelectedFunc(onGuildsDropDownSelected) guildsDropDown. - SetFieldBackgroundColor(guildsDropDownBackgroundColor). - SetBackgroundColor(guildsDropDownBackgroundColor). + SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor). SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return guildsDropDown + return } diff --git a/ui/flex.go b/ui/flex.go index 367df9b..bcabfad 100644 --- a/ui/flex.go +++ b/ui/flex.go @@ -4,8 +4,8 @@ import ( "github.com/rivo/tview" ) -func NewMainFlex(guildsDropDown *tview.DropDown, channelsList *tview.List, messagesTextView *tview.TextView) *tview.Flex { - mainFlex := tview.NewFlex(). +func NewMainFlex(guildsDropDown *tview.DropDown, channelsList *tview.List, messagesTextView *tview.TextView) (mainFlex *tview.Flex) { + mainFlex = tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(guildsDropDown, 3, 1, false). AddItem( @@ -17,5 +17,5 @@ func NewMainFlex(guildsDropDown *tview.DropDown, channelsList *tview.List, messa false, ) - return mainFlex + return } diff --git a/ui/forms.go b/ui/forms.go index af3afe2..24855d0 100644 --- a/ui/forms.go +++ b/ui/forms.go @@ -5,16 +5,12 @@ import ( "github.com/rivo/tview" ) -var loginFormBackgroundColor = tcell.GetColor("#1C1E26") -var loginFormButtonBackgroundColor = tcell.GetColor("#5865F2") - -func NewLoginForm(via string, onLoginFormLoginButtonSelected func(), onLoginFormQuitButtonSelected func()) *tview.Form { - loginForm := tview.NewForm(). +func NewLoginForm(via string, onLoginFormLoginButtonSelected func(), onLoginFormQuitButtonSelected func()) (loginForm *tview.Form) { + loginForm = tview.NewForm(). AddButton("Login", onLoginFormLoginButtonSelected). AddButton("Quit", onLoginFormQuitButtonSelected) loginForm. - SetButtonBackgroundColor(loginFormButtonBackgroundColor). - SetBackgroundColor(loginFormBackgroundColor). + SetButtonBackgroundColor(tcell.GetColor("#5865F2")). SetBorder(true). SetBorderPadding(0, 0, 1, 1) diff --git a/ui/inputfields.go b/ui/inputfields.go index de05452..91a51a5 100644 --- a/ui/inputfields.go +++ b/ui/inputfields.go @@ -5,20 +5,16 @@ import ( "github.com/rivo/tview" ) -var messageInputFieldBackgroundColor = tcell.GetColor("#1C1E26") -var messageInputFieldPlaceholderTextColor = tcell.ColorWhite - -func NewMessageInputField(onMessageInputFieldDone func(key tcell.Key)) *tview.InputField { - messageInputField := tview.NewInputField(). +func NewMessageInputField(onMessageInputFieldDone func(key tcell.Key)) (messageInputField *tview.InputField) { + messageInputField = tview.NewInputField(). SetPlaceholder("Message..."). SetFieldWidth(0). SetDoneFunc(onMessageInputFieldDone) messageInputField. - SetFieldBackgroundColor(messageInputFieldBackgroundColor). - SetPlaceholderTextColor(messageInputFieldPlaceholderTextColor). - SetBackgroundColor(messageInputFieldBackgroundColor). + SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor). + SetPlaceholderTextColor(tcell.ColorDarkGray). SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return messageInputField + return } diff --git a/ui/lists.go b/ui/lists.go index f90a7e2..3b1148d 100644 --- a/ui/lists.go +++ b/ui/lists.go @@ -5,17 +5,17 @@ import ( "github.com/rivo/tview" ) -var channelsListBackgroundColor = tcell.GetColor("#1C1E26") - -func NewChannelsList(onChannelsListSelected func(i int, mainText string, secondaryText string, _ rune)) *tview.List { - channelsList := tview.NewList(). +func NewChannelsList(onChannelsListSelected func(i int, mainText string, secondaryText string, _ rune)) (channelsList *tview.List) { + channelsList = tview.NewList(). ShowSecondaryText(false). + SetMainTextColor(tcell.ColorDarkGray). + SetSelectedTextColor(tcell.ColorWhite). + SetSelectedBackgroundColor(tview.Styles.PrimitiveBackgroundColor). SetSelectedFunc(onChannelsListSelected) channelsList. SetBorder(true). SetBorderPadding(0, 0, 1, 1). - SetTitle("Channels"). - SetBackgroundColor(channelsListBackgroundColor) + SetTitle("Channels") - return channelsList + return } diff --git a/ui/modals.go b/ui/modals.go index 06dd785..485a216 100644 --- a/ui/modals.go +++ b/ui/modals.go @@ -1,12 +1,14 @@ package ui -import "github.com/rivo/tview" +import ( + "github.com/rivo/tview" +) var LoginViaTokenLoginModalButton = "Login via token" var LoginViaEmailPasswordLoginModalButton = "Login via email and password" -func NewLoginModal(onLoginModalDone func(buttonIndex int, buttonLabel string)) *tview.Modal { - loginModal := tview.NewModal(). +func NewLoginModal(onLoginModalDone func(buttonIndex int, buttonLabel string)) (loginModal *tview.Modal) { + loginModal = tview.NewModal(). SetText("Choose a login method:"). AddButtons([]string{LoginViaTokenLoginModalButton, LoginViaEmailPasswordLoginModalButton}). SetDoneFunc(onLoginModalDone) @@ -14,5 +16,5 @@ func NewLoginModal(onLoginModalDone func(buttonIndex int, buttonLabel string)) * SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return loginModal + return } diff --git a/ui/textviews.go b/ui/textviews.go index be60e92..d58b67b 100644 --- a/ui/textviews.go +++ b/ui/textviews.go @@ -1,14 +1,11 @@ package ui import ( - "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) -var messagesTextViewBackgroundColor = tcell.GetColor("#1C1E26") - -func NewMessagesTextView(onMessagesTextViewChanged func()) *tview.TextView { - messagesTextView := tview.NewTextView(). +func NewMessagesTextView(onMessagesTextViewChanged func()) (messagesTextView *tview.TextView) { + messagesTextView = tview.NewTextView(). SetDynamicColors(true). SetWrap(true). SetWordWrap(true). @@ -17,8 +14,7 @@ func NewMessagesTextView(onMessagesTextViewChanged func()) *tview.TextView { SetChangedFunc(onMessagesTextViewChanged) messagesTextView. SetBorder(true). - SetBorderPadding(0, 0, 1, 1). - SetBackgroundColor(messagesTextViewBackgroundColor) + SetBorderPadding(0, 0, 1, 1) - return messagesTextView + return } diff --git a/util/discord.go b/util/discord.go index aa1c1f8..e3fe5ad 100644 --- a/util/discord.go +++ b/util/discord.go @@ -47,11 +47,11 @@ func SendMessage(session *session.Session, channelID discord.ChannelID, content } } -func GetMessages(session *session.Session, channelID discord.ChannelID, limit uint) []discord.Message { +func GetMessages(session *session.Session, channelID discord.ChannelID, limit uint) (messages []discord.Message) { messages, err := session.Messages(channelID, limit) if err != nil { panic(err) } - return messages + return } diff --git a/util/keyring.go b/util/keyring.go index 78f1fb2..1e57613 100644 --- a/util/keyring.go +++ b/util/keyring.go @@ -6,13 +6,13 @@ import ( const Service string = "discordo" -func GetPassword(user string) string { +func GetPassword(user string) (password string) { password, err := keyring.Get(Service, user) if err == keyring.ErrNotFound { return "" } - return password + return } func SetPassword(user string, password string) {