Change Config.Theme type to tview.Theme

This commit is contained in:
rigormorrtiss 2021-08-23 08:21:46 +04:00
parent 59e0a5c0e5
commit e1a88777a7
5 changed files with 11 additions and 45 deletions

View file

@ -29,29 +29,7 @@ var (
func main() {
conf = util.NewConfig()
tview.Styles.PrimitiveBackgroundColor = tcell.GetColor(conf.Theme.Background)
if !conf.Theme.Borders {
tview.Borders = struct {
Horizontal rune
Vertical rune
TopLeft rune
TopRight rune
BottomLeft rune
BottomRight rune
LeftT rune
RightT rune
TopT rune
BottomT rune
Cross rune
HorizontalFocus rune
VerticalFocus rune
TopLeftFocus rune
TopRightFocus rune
BottomLeftFocus rune
BottomRightFocus rune
}{}
}
tview.Styles = conf.Theme
app = tview.NewApplication().
EnableMouse(conf.Mouse).
@ -59,7 +37,7 @@ func main() {
guildsTreeView = ui.NewGuildsTreeView(onGuildsTreeViewSelected)
channelsTreeView = ui.NewChannelsTreeView(onChannelsTreeViewSelected)
messagesTextView = ui.NewMessagesTextView(app)
messageInputField = ui.NewMessageInputField(onMessageInputFieldInputCapture, conf.Theme)
messageInputField = ui.NewMessageInputField(onMessageInputFieldInputCapture)
mainFlex = ui.NewMainFlex(guildsTreeView, channelsTreeView, messagesTextView, messageInputField)
token := conf.Token

View file

@ -16,7 +16,7 @@ func NewMainFlex(gTreeV *tview.TreeView, cTreeV *tview.TreeView, textV *tview.Te
AddItem(i, 3, 1, false)
mf := tview.NewFlex().
AddItem(lf, 0, 1, false).
AddItem(rf, 0, 4, false)
AddItem(rf, 0, 5, false)
return mf
}

View file

@ -1,7 +1,6 @@
package ui
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
@ -9,7 +8,6 @@ func newBaseLoginForm() *tview.Form {
f := tview.NewForm()
f.
SetButtonsAlign(tview.AlignCenter).
SetButtonBackgroundColor(tcell.GetColor("#5865F2")).
SetBorder(true).
SetBorderPadding(0, 0, 1, 0)

View file

@ -2,18 +2,16 @@ package ui
import (
"github.com/gdamore/tcell/v2"
"github.com/rigormorrtiss/discordo/util"
"github.com/rivo/tview"
)
// NewMessageInputField creates and returns a new message inputfield.
func NewMessageInputField(onMessageInputFieldInputCapture func(*tcell.EventKey) *tcell.EventKey, t *util.Theme) *tview.InputField {
func NewMessageInputField(onMessageInputFieldInputCapture func(*tcell.EventKey) *tcell.EventKey) *tview.InputField {
i := tview.NewInputField()
i.
SetPlaceholder("Message...").
SetPlaceholderTextColor(tcell.ColorWhite).
SetFieldBackgroundColor(tcell.GetColor(t.Background)).
SetBackgroundColor(tcell.GetColor(t.Background)).
SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
SetInputCapture(onMessageInputFieldInputCapture).
SetBorder(true).
SetBorderPadding(0, 0, 1, 0)

View file

@ -3,21 +3,16 @@ package util
import (
"encoding/json"
"os"
)
// Theme defines the theme for the application.
type Theme struct {
Background string `json:"background,omitempty"`
Foreground string `json:"foreground,omitempty"`
Borders bool `json:"borders,omitempty"`
}
"github.com/rivo/tview"
)
// Config consists of fields, such as theme, mouse, so on, that may be customized by the user.
type Config struct {
Token string `json:"token,omitempty"`
Mouse bool `json:"mouse,omitempty"`
GetMessagesLimit int `json:"getMessagesLimit,omitempty"`
Theme *Theme `json:"theme,omitempty"`
Token string `json:"token,omitempty"`
Mouse bool `json:"mouse,omitempty"`
GetMessagesLimit int `json:"getMessagesLimit,omitempty"`
Theme tview.Theme `json:"theme,omitempty"`
}
// NewConfig reads the configuration file (if exists) and returns a new config.
@ -30,9 +25,6 @@ func NewConfig() *Config {
var c Config = Config{
Mouse: true,
GetMessagesLimit: 50,
Theme: &Theme{
Borders: true,
},
}
configPath := userHomeDir + "/.config/discordo/config.json"
if _, err := os.Stat(configPath); os.IsNotExist(err) {