diff --git a/main.go b/main.go index 34c7429..d2b5827 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/ayntgl/discordgo" - "github.com/ayntgl/discordo/ui" "github.com/ayntgl/discordo/util" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" @@ -45,17 +44,17 @@ func main() { EnableMouse(conf.Mouse). SetInputCapture(onAppInputCapture) - channelsTree = ui.NewChannelsTree() + channelsTree = newChannelsTree() channelsTree.SetSelectedFunc(onChannelsTreeSelected) - messagesView = ui.NewMessagesView() + messagesView = newMessagesView() messagesView. SetChangedFunc(func() { app.Draw() }). SetInputCapture(onMessagesViewInputCapture) - messageInputField = ui.NewMessageInputField() + messageInputField = newMessageInputField() messageInputField.SetInputCapture(onMessageInputFieldInputCapture) rightFlex := tview.NewFlex(). @@ -83,7 +82,7 @@ func main() { panic(err) } } else { - loginForm = ui.NewLoginForm(onLoginFormLoginButtonSelected, false) + loginForm = newLoginForm(onLoginFormLoginButtonSelected, false) app.SetRoot(loginForm, true) } @@ -120,7 +119,7 @@ func onLoginFormLoginButtonSelected() { go keyring.Set(service, "token", lr.Token) } else if lr.MFA { // The account has MFA enabled, reattempt login with code and ticket. - loginForm = ui.NewLoginForm(func() { + loginForm = newLoginForm(func() { code := loginForm.GetFormItem(0).(*tview.InputField).GetText() if code == "" { return diff --git a/ui.go b/ui.go index 3bac39e..c3142ff 100644 --- a/ui.go +++ b/ui.go @@ -31,6 +31,19 @@ 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 @@ -128,6 +141,19 @@ func onChannelsTreeSelected(n *tview.TreeNode) { } } +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 @@ -231,6 +257,19 @@ 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: @@ -284,3 +323,22 @@ func onMessageInputFieldInputCapture(e *tcell.EventKey) *tcell.EventKey { return e } + +func newLoginForm(onLoginFormLoginButtonSelected func(), mfa bool) *tview.Form { + w := tview.NewForm() + w. + AddButton("Login", onLoginFormLoginButtonSelected). + SetButtonsAlign(tview.AlignCenter). + SetBorder(true). + SetBorderPadding(0, 0, 1, 0) + + if mfa { + w.AddPasswordField("Code", "", 0, 0, nil) + } else { + w. + AddInputField("Email", "", 0, nil, nil). + AddPasswordField("Password", "", 0, 0, nil) + } + + return w +} diff --git a/ui/channels_tree.go b/ui/channels_tree.go deleted file mode 100644 index 5d1b5fc..0000000 --- a/ui/channels_tree.go +++ /dev/null @@ -1,16 +0,0 @@ -package ui - -import "github.com/rivo/tview" - -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 -} diff --git a/ui/login_form.go b/ui/login_form.go deleted file mode 100644 index 1ec1848..0000000 --- a/ui/login_form.go +++ /dev/null @@ -1,22 +0,0 @@ -package ui - -import "github.com/rivo/tview" - -func NewLoginForm(onLoginFormLoginButtonSelected func(), mfa bool) *tview.Form { - w := tview.NewForm() - w. - AddButton("Login", onLoginFormLoginButtonSelected). - SetButtonsAlign(tview.AlignCenter). - SetBorder(true). - SetBorderPadding(0, 0, 1, 0) - - if mfa { - w.AddPasswordField("Code", "", 0, 0, nil) - } else { - w. - AddInputField("Email", "", 0, nil, nil). - AddPasswordField("Password", "", 0, 0, nil) - } - - return w -} diff --git a/ui/message_input_field.go b/ui/message_input_field.go deleted file mode 100644 index 2699230..0000000 --- a/ui/message_input_field.go +++ /dev/null @@ -1,19 +0,0 @@ -package ui - -import ( - "github.com/gdamore/tcell/v2" - "github.com/rivo/tview" -) - -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 -} diff --git a/ui/messages_view.go b/ui/messages_view.go deleted file mode 100644 index 1306fed..0000000 --- a/ui/messages_view.go +++ /dev/null @@ -1,16 +0,0 @@ -package ui - -import "github.com/rivo/tview" - -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 -}