From e4fbeb1c1154f59df50ca0436e1cb379ee626cd6 Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Mon, 2 Aug 2021 22:38:03 +0400 Subject: [PATCH] refactor(ui): explicitly return values --- discordo.go | 3 ++- ui/app.go | 6 +++--- ui/dropdowns.go | 6 +++--- ui/flex.go | 6 +++--- ui/forms.go | 4 ++-- ui/inputfields.go | 6 +++--- ui/modals.go | 6 +++--- ui/textviews.go | 6 +++--- ui/treeviews.go | 11 +++-------- 9 files changed, 25 insertions(+), 29 deletions(-) diff --git a/discordo.go b/discordo.go index 4eb93bf..b9d5d10 100644 --- a/discordo.go +++ b/discordo.go @@ -51,9 +51,10 @@ func main() { tview.Borders.BottomRight = ' ' config = util.NewConfig() + loginModal = ui.NewLoginModal(onLoginModalDone) guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected, config.Theme) - channelsTreeNode = ui.NewChannelsTreeNode() + channelsTreeNode = tview.NewTreeNode("") channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, config.Theme) messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged, config.Theme) mainFlex = ui.NewMainFlex(guildsDropDown, channelsTreeView, messagesTextView) diff --git a/ui/app.go b/ui/app.go index 8218a13..7289152 100644 --- a/ui/app.go +++ b/ui/app.go @@ -4,9 +4,9 @@ import ( "github.com/rivo/tview" ) -func NewApp() (app *tview.Application) { - app = tview.NewApplication(). +func NewApp() *tview.Application { + app := tview.NewApplication(). EnableMouse(true) - return + return app } diff --git a/ui/dropdowns.go b/ui/dropdowns.go index 0e07623..c71ae57 100644 --- a/ui/dropdowns.go +++ b/ui/dropdowns.go @@ -6,8 +6,8 @@ import ( "github.com/rivo/tview" ) -func NewGuildsDropDown(onGuildsDropDownSelected func(text string, index int), theme *util.Theme) (guildsDropDown *tview.DropDown) { - guildsDropDown = tview.NewDropDown() +func NewGuildsDropDown(onGuildsDropDownSelected func(text string, index int), theme *util.Theme) *tview.DropDown { + guildsDropDown := tview.NewDropDown() guildsDropDown. SetLabel("Guild: "). @@ -19,5 +19,5 @@ func NewGuildsDropDown(onGuildsDropDownSelected func(text string, index int), th SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return + return guildsDropDown } diff --git a/ui/flex.go b/ui/flex.go index 24c1e91..a7da247 100644 --- a/ui/flex.go +++ b/ui/flex.go @@ -4,14 +4,14 @@ import ( "github.com/rivo/tview" ) -func NewMainFlex(guildsDropDown *tview.DropDown, channelsTreeView *tview.TreeView, messagesTextView *tview.TextView) (mainFlex *tview.Flex) { +func NewMainFlex(guildsDropDown *tview.DropDown, channelsTreeView *tview.TreeView, messagesTextView *tview.TextView) *tview.Flex { midFlex := tview.NewFlex(). AddItem(channelsTreeView, 20, 1, false). AddItem(messagesTextView, 0, 3, false) - mainFlex = tview.NewFlex(). + mainFlex := tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(guildsDropDown, 3, 1, false). AddItem(midFlex, 0, 1, false) - return + return mainFlex } diff --git a/ui/forms.go b/ui/forms.go index 1747266..e42a3e1 100644 --- a/ui/forms.go +++ b/ui/forms.go @@ -5,8 +5,8 @@ import ( "github.com/rivo/tview" ) -func NewLoginForm(via string, onLoginFormLoginButtonSelected func()) (loginForm *tview.Form) { - loginForm = tview.NewForm() +func NewLoginForm(via string, onLoginFormLoginButtonSelected func()) *tview.Form { + loginForm := tview.NewForm() loginForm. AddButton("Login", onLoginFormLoginButtonSelected). diff --git a/ui/inputfields.go b/ui/inputfields.go index 52e9e6c..71c11f6 100644 --- a/ui/inputfields.go +++ b/ui/inputfields.go @@ -6,8 +6,8 @@ import ( "github.com/rivo/tview" ) -func NewMessageInputField(onMessageInputFieldDone func(key tcell.Key), theme *util.Theme) (messageInputField *tview.InputField) { - messageInputField = tview.NewInputField() +func NewMessageInputField(onMessageInputFieldDone func(key tcell.Key), theme *util.Theme) *tview.InputField { + messageInputField := tview.NewInputField() messageInputField. SetPlaceholder("Message..."). @@ -19,5 +19,5 @@ func NewMessageInputField(onMessageInputFieldDone func(key tcell.Key), theme *ut SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return + return messageInputField } diff --git a/ui/modals.go b/ui/modals.go index b77764f..5d825df 100644 --- a/ui/modals.go +++ b/ui/modals.go @@ -9,8 +9,8 @@ const ( LoginViaEmailPasswordLoginModalButton = "Login via email and password" ) -func NewLoginModal(onLoginModalDone func(buttonIndex int, buttonLabel string)) (loginModal *tview.Modal) { - loginModal = tview.NewModal() +func NewLoginModal(onLoginModalDone func(buttonIndex int, buttonLabel string)) *tview.Modal { + loginModal := tview.NewModal() loginModal. SetText("Choose a login method:"). @@ -19,5 +19,5 @@ func NewLoginModal(onLoginModalDone func(buttonIndex int, buttonLabel string)) ( SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return + return loginModal } diff --git a/ui/textviews.go b/ui/textviews.go index 5a470bc..6e5beb7 100644 --- a/ui/textviews.go +++ b/ui/textviews.go @@ -6,8 +6,8 @@ import ( "github.com/rivo/tview" ) -func NewMessagesTextView(onMessagesTextViewChanged func(), theme *util.Theme) (messagesTextView *tview.TextView) { - messagesTextView = tview.NewTextView() +func NewMessagesTextView(onMessagesTextViewChanged func(), theme *util.Theme) *tview.TextView { + messagesTextView := tview.NewTextView() messagesTextView. SetDynamicColors(true). @@ -19,5 +19,5 @@ func NewMessagesTextView(onMessagesTextViewChanged func(), theme *util.Theme) (m SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return + return messagesTextView } diff --git a/ui/treeviews.go b/ui/treeviews.go index 857ea35..e0eadf6 100644 --- a/ui/treeviews.go +++ b/ui/treeviews.go @@ -6,8 +6,8 @@ import ( "github.com/rivo/tview" ) -func NewChannelsTreeView(channelsTreeNode *tview.TreeNode, onChannelsTreeViewSelected func(node *tview.TreeNode), theme *util.Theme) (channelsTreeView *tview.TreeView) { - channelsTreeView = tview.NewTreeView() +func NewChannelsTreeView(channelsTreeNode *tview.TreeNode, onChannelsTreeViewSelected func(node *tview.TreeNode), theme *util.Theme) *tview.TreeView { + channelsTreeView := tview.NewTreeView() channelsTreeView. SetTopLevel(1). @@ -18,10 +18,5 @@ func NewChannelsTreeView(channelsTreeNode *tview.TreeNode, onChannelsTreeViewSel SetBorder(true). SetBorderPadding(0, 0, 1, 1) - return -} - -func NewChannelsTreeNode() (channelsTreeNode *tview.TreeNode) { - channelsTreeNode = tview.NewTreeNode("") - return + return channelsTreeView }