From 9bb8dce3d01d966f40f17df70c4c7bc26581973f Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Wed, 18 Aug 2021 22:15:22 +0400 Subject: [PATCH] refactor: add comments for exported functions --- ui/app.go | 1 + ui/flex.go | 1 + ui/forms.go | 2 ++ ui/inputfields.go | 1 + ui/lists.go | 1 + ui/textviews.go | 1 + ui/treeviews.go | 1 + util/config.go | 1 + util/discord.go | 1 + util/keyring.go | 2 ++ 10 files changed, 12 insertions(+) diff --git a/ui/app.go b/ui/app.go index 45fa929..9379ccc 100644 --- a/ui/app.go +++ b/ui/app.go @@ -5,6 +5,7 @@ import ( "github.com/rivo/tview" ) +// NewApp creates and returns a new application. func NewApp(onAppInputCapture func(*tcell.EventKey) *tcell.EventKey) (app *tview.Application) { app = tview.NewApplication(). EnableMouse(true). diff --git a/ui/flex.go b/ui/flex.go index 9fd960f..257e275 100644 --- a/ui/flex.go +++ b/ui/flex.go @@ -4,6 +4,7 @@ import ( "github.com/rivo/tview" ) +// NewMainFlex creates and returns a new main flex. func NewMainFlex(l *tview.List, treeV *tview.TreeView, textV *tview.TextView, i *tview.InputField) (mf *tview.Flex) { lf := tview.NewFlex(). SetDirection(tview.FlexRow). diff --git a/ui/forms.go b/ui/forms.go index 0692840..6a404a6 100644 --- a/ui/forms.go +++ b/ui/forms.go @@ -16,6 +16,7 @@ func newBaseLoginForm() (f *tview.Form) { return } +// NewLoginForm creates and returns a new login form. func NewLoginForm(onLoginFormLoginButtonSelected func()) (f *tview.Form) { f = newBaseLoginForm() f. @@ -26,6 +27,7 @@ func NewLoginForm(onLoginFormLoginButtonSelected func()) (f *tview.Form) { return } +// NewMfaLoginForm creates and returns a new MFA login form. func NewMfaLoginForm(onMfaLoginFormLoginButtonSelected func()) (f *tview.Form) { f = newBaseLoginForm(). AddPasswordField("Code", "", 0, 0, nil). diff --git a/ui/inputfields.go b/ui/inputfields.go index e48e24f..7cf3ec9 100644 --- a/ui/inputfields.go +++ b/ui/inputfields.go @@ -6,6 +6,7 @@ import ( "github.com/rivo/tview" ) +// NewMessageInputField creates and returns a new message inputfield. func NewMessageInputField(onMessageInputFieldInputCapture func(*tcell.EventKey) *tcell.EventKey, t *util.Theme) (i *tview.InputField) { i = tview.NewInputField() i. diff --git a/ui/lists.go b/ui/lists.go index 2dd8fe5..bd869dd 100644 --- a/ui/lists.go +++ b/ui/lists.go @@ -5,6 +5,7 @@ import ( "github.com/rivo/tview" ) +// NewGuildsList creates and returns a new guilds list. func NewGuildsList(onGuildsListSelected func(int, string, string, rune), t *util.Theme) (l *tview.List) { l = tview.NewList() l. diff --git a/ui/textviews.go b/ui/textviews.go index 5b38667..3fff362 100644 --- a/ui/textviews.go +++ b/ui/textviews.go @@ -4,6 +4,7 @@ import ( "github.com/rivo/tview" ) +// NewMessagesTextView creates and returns a new messages textview. func NewMessagesTextView(app *tview.Application) (textV *tview.TextView) { textV = tview.NewTextView() textV. diff --git a/ui/treeviews.go b/ui/treeviews.go index effcea6..9aa388b 100644 --- a/ui/treeviews.go +++ b/ui/treeviews.go @@ -4,6 +4,7 @@ import ( "github.com/rivo/tview" ) +// NewChannelsTreeView creates and returns a new channels treeview. func NewChannelsTreeView(onChannelsTreeViewSelected func(*tview.TreeNode)) (treeV *tview.TreeView) { treeV = tview.NewTreeView() treeN := tview.NewTreeNode("") diff --git a/util/config.go b/util/config.go index 18288ca..943f222 100644 --- a/util/config.go +++ b/util/config.go @@ -16,6 +16,7 @@ type Config struct { Theme *Theme `json:"theme,omitempty"` } +// NewConfig reads the configuration file (if exists) and returns a new config. func NewConfig() *Config { userHomeDir, err := os.UserHomeDir() if err != nil { diff --git a/util/discord.go b/util/discord.go index fb75be4..0acbf74 100644 --- a/util/discord.go +++ b/util/discord.go @@ -8,6 +8,7 @@ import ( "github.com/rivo/tview" ) +// WriteMessage parses and writes the parsed message to the provided textview. func WriteMessage(v *tview.TextView, clientID discord.UserID, m discord.Message) { var b strings.Builder switch m.Type { diff --git a/util/keyring.go b/util/keyring.go index 0a8d542..729d480 100644 --- a/util/keyring.go +++ b/util/keyring.go @@ -2,6 +2,7 @@ package util import "github.com/zalando/go-keyring" +// GetPassword retrieves the password in keyring for provided user. func GetPassword(u string) string { p, err := keyring.Get("discordo", u) if err != nil { @@ -11,6 +12,7 @@ func GetPassword(u string) string { return p } +// SetPassword sets the password in keyring for provided user. func SetPassword(u string, p string) { if err := keyring.Set("discordo", u, p); err != nil { panic(err)