From 88600de3189f83487c5ca8a7ea375bb888efbfe8 Mon Sep 17 00:00:00 2001 From: ayntgl Date: Mon, 29 Nov 2021 20:17:14 +0400 Subject: [PATCH] refactor: remove new* UI functions --- main.go | 34 ++++++++++++++++++++++++++-------- ui.go | 39 --------------------------------------- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/main.go b/main.go index 6d38c30..d1ea376 100644 --- a/main.go +++ b/main.go @@ -55,18 +55,36 @@ func main() { EnableMouse(conf.Mouse). SetInputCapture(onAppInputCapture) - channelsTree = newChannelsTree() - channelsTree.SetSelectedFunc(onChannelsTreeSelected) + channelsTree = tview.NewTreeView() + channelsTree. + SetTopLevel(1). + SetRoot(tview.NewTreeNode("")). + SetSelectedFunc(onChannelsTreeSelected). + SetTitle("Channels"). + SetTitleAlign(tview.AlignLeft). + SetBorder(true). + SetBorderPadding(0, 0, 1, 0) - messagesView = newMessagesView() + messagesView = tview.NewTextView() messagesView. - SetChangedFunc(func() { - app.Draw() - }). + SetRegions(true). + SetDynamicColors(true). + SetWordWrap(true). + SetChangedFunc(func() { app.Draw() }). + SetBorder(true). + SetBorderPadding(0, 0, 1, 0). + SetTitleAlign(tview.AlignLeft). SetInputCapture(onMessagesViewInputCapture) - messageInputField = newMessageInputField() - messageInputField.SetInputCapture(onMessageInputFieldInputCapture) + messageInputField = tview.NewInputField() + messageInputField. + SetPlaceholder("Message..."). + SetPlaceholderTextColor(tcell.ColorWhite). + SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor). + SetBorder(true). + SetBorderPadding(0, 0, 1, 0). + SetTitleAlign(tview.AlignLeft). + SetInputCapture(onMessageInputFieldInputCapture) rightFlex := tview.NewFlex(). SetDirection(tview.FlexRow). diff --git a/ui.go b/ui.go index e417d08..9a46489 100644 --- a/ui.go +++ b/ui.go @@ -30,19 +30,6 @@ func onAppInputCapture(e *tcell.EventKey) *tcell.EventKey { return e } -func newChannelsTree() *tview.TreeView { - treeView := tview.NewTreeView() - treeView. - SetTopLevel(1). - SetRoot(tview.NewTreeNode("")). - SetTitle("Channels"). - SetTitleAlign(tview.AlignLeft). - SetBorder(true). - SetBorderPadding(0, 0, 1, 0) - - return treeView -} - func onChannelsTreeSelected(n *tview.TreeNode) { selectedChannel = nil selectedMessage = 0 @@ -193,19 +180,6 @@ func createSecondLevelChannelsNodes(treeView *tview.TreeView, s *discordgo.State } } -func newMessagesView() *tview.TextView { - textView := tview.NewTextView() - textView. - SetRegions(true). - SetDynamicColors(true). - SetWordWrap(true). - SetBorder(true). - SetBorderPadding(0, 0, 1, 0). - SetTitleAlign(tview.AlignLeft) - - return textView -} - func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey { if selectedChannel == nil { return nil @@ -309,19 +283,6 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey { return e } -func newMessageInputField() *tview.InputField { - inputField := tview.NewInputField() - inputField. - SetPlaceholder("Message..."). - SetPlaceholderTextColor(tcell.ColorWhite). - SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor). - SetBorder(true). - SetBorderPadding(0, 0, 1, 0). - SetTitleAlign(tview.AlignLeft) - - return inputField -} - func onMessageInputFieldInputCapture(e *tcell.EventKey) *tcell.EventKey { switch e.Key() { case tcell.KeyEnter: