refactor: remove new* UI functions

This commit is contained in:
ayntgl 2021-11-29 20:17:14 +04:00
parent 4ac65d3cd7
commit 88600de318
2 changed files with 26 additions and 47 deletions

34
main.go
View file

@ -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).

39
ui.go
View file

@ -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: