Skip to content

Commit

Permalink
chore: creates a custom theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerojas26 committed Sep 8, 2024
1 parent 5bfeb76 commit 2305a74
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 136 deletions.
13 changes: 12 additions & 1 deletion app/App.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@ import (

var App = tview.NewApplication()

type Theme struct {
SidebarTitleBorderColor string
tview.Theme
}

var Styles = Theme{
SidebarTitleBorderColor: "#666A7E",
}

func init() {
theme := tview.Theme{
PrimitiveBackgroundColor: tcell.ColorDefault,
ContrastBackgroundColor: tcell.ColorBlue,
MoreContrastBackgroundColor: tcell.ColorGreen,
BorderColor: tcell.ColorWhite,
TitleColor: tcell.ColorWhite,
GraphicsColor: tcell.ColorWhite,
GraphicsColor: tcell.ColorGray,
PrimaryTextColor: tcell.ColorDefault.TrueColor(),
SecondaryTextColor: tcell.ColorYellow,
TertiaryTextColor: tcell.ColorGreen,
InverseTextColor: tcell.ColorWhite,
ContrastSecondaryTextColor: tcell.ColorBlack,
}

Styles.Theme = theme
tview.Styles = theme
}
6 changes: 4 additions & 2 deletions components/ConfirmationModal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package components

import (
"github.com/rivo/tview"

"github.com/jorgerojas26/lazysql/app"
)

type ConfirmationModal struct {
Expand All @@ -16,8 +18,8 @@ func NewConfirmationModal(confirmationText string) *ConfirmationModal {
modal.SetText("Are you sure?")
}
modal.AddButtons([]string{"Yes", "No"})
modal.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
modal.SetTextColor(tview.Styles.PrimaryTextColor)
modal.SetBackgroundColor(app.Styles.PrimitiveBackgroundColor)
modal.SetTextColor(app.Styles.PrimaryTextColor)

return &ConfirmationModal{
Modal: modal,
Expand Down
15 changes: 8 additions & 7 deletions components/ConnectionForm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"

"github.com/jorgerojas26/lazysql/app"
"github.com/jorgerojas26/lazysql/drivers"
"github.com/jorgerojas26/lazysql/helpers"
"github.com/jorgerojas26/lazysql/models"
Expand All @@ -23,35 +24,35 @@ func NewConnectionForm(connectionPages *models.ConnectionPages) *ConnectionForm

wrapper.SetDirection(tview.FlexColumnCSS)

addForm := tview.NewForm().SetFieldBackgroundColor(tview.Styles.InverseTextColor).SetButtonBackgroundColor(tview.Styles.InverseTextColor).SetLabelColor(tview.Styles.PrimaryTextColor).SetFieldTextColor(tview.Styles.ContrastSecondaryTextColor)
addForm := tview.NewForm().SetFieldBackgroundColor(app.Styles.InverseTextColor).SetButtonBackgroundColor(tview.Styles.InverseTextColor).SetLabelColor(tview.Styles.PrimaryTextColor).SetFieldTextColor(tview.Styles.ContrastSecondaryTextColor)
addForm.AddInputField("Name", "", 0, nil, nil)
addForm.AddInputField("URL", "", 0, nil, nil)

buttonsWrapper := tview.NewFlex().SetDirection(tview.FlexColumn)

saveButton := tview.NewButton("[yellow]F1 [dark]Save")
saveButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimaryTextColor))
saveButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimaryTextColor))
saveButton.SetBorder(true)

buttonsWrapper.AddItem(saveButton, 0, 1, false)
buttonsWrapper.AddItem(nil, 1, 0, false)

testButton := tview.NewButton("[yellow]F2 [dark]Test")
testButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimaryTextColor))
testButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimaryTextColor))
testButton.SetBorder(true)

buttonsWrapper.AddItem(testButton, 0, 1, false)
buttonsWrapper.AddItem(nil, 1, 0, false)

connectButton := tview.NewButton("[yellow]F3 [dark]Connect")
connectButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimaryTextColor))
connectButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimaryTextColor))
connectButton.SetBorder(true)

buttonsWrapper.AddItem(connectButton, 0, 1, false)
buttonsWrapper.AddItem(nil, 1, 0, false)

cancelButton := tview.NewButton("[yellow]Esc [dark]Cancel")
cancelButton.SetStyle(tcell.StyleDefault.Background(tcell.Color(tview.Styles.PrimaryTextColor)))
cancelButton.SetStyle(tcell.StyleDefault.Background(tcell.Color(app.Styles.PrimaryTextColor)))
cancelButton.SetBorder(true)

buttonsWrapper.AddItem(cancelButton, 0, 1, false)
Expand Down Expand Up @@ -168,7 +169,7 @@ func (form *ConnectionForm) testConnection(connectionString string) {
return
}

form.StatusText.SetText("Connecting...").SetTextColor(tview.Styles.TertiaryTextColor)
form.StatusText.SetText("Connecting...").SetTextColor(app.Styles.TertiaryTextColor)

var db drivers.Driver

Expand All @@ -186,7 +187,7 @@ func (form *ConnectionForm) testConnection(connectionString string) {
if err != nil {
form.StatusText.SetText(err.Error()).SetTextStyle(tcell.StyleDefault.Foreground(tcell.ColorRed))
} else {
form.StatusText.SetText("Connection success").SetTextColor(tview.Styles.TertiaryTextColor)
form.StatusText.SetText("Connection success").SetTextColor(app.Styles.TertiaryTextColor)
}
App.ForceDraw()
}
Expand Down
12 changes: 6 additions & 6 deletions components/ConnectionSelection.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@ func NewConnectionSelection(connectionForm *ConnectionForm, connectionPages *mod
buttonsWrapper := tview.NewFlex().SetDirection(tview.FlexRowCSS)

newButton := tview.NewButton("[yellow]N[dark]ew")
newButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor))
newButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor))
newButton.SetBorder(true)

buttonsWrapper.AddItem(newButton, 0, 1, false)
buttonsWrapper.AddItem(nil, 1, 0, false)

connectButton := tview.NewButton("[yellow]C[dark]onnect")
connectButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor))
connectButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor))
connectButton.SetBorder(true)

buttonsWrapper.AddItem(connectButton, 0, 1, false)
buttonsWrapper.AddItem(nil, 1, 0, false)

editButton := tview.NewButton("[yellow]E[dark]dit")
editButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor))
editButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor))
editButton.SetBorder(true)

buttonsWrapper.AddItem(editButton, 0, 1, false)
buttonsWrapper.AddItem(nil, 1, 0, false)

deleteButton := tview.NewButton("[yellow]D[dark]elete")
deleteButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor))
deleteButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor))
deleteButton.SetBorder(true)

buttonsWrapper.AddItem(deleteButton, 0, 1, false)
buttonsWrapper.AddItem(nil, 1, 0, false)

quitButton := tview.NewButton("[yellow]Q[dark]uit")
quitButton.SetStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor))
quitButton.SetStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor))
quitButton.SetBorder(true)

buttonsWrapper.AddItem(quitButton, 0, 1, false)
Expand Down Expand Up @@ -145,7 +145,7 @@ func (cs *ConnectionSelection) Connect(connection models.Connection) {
MainPages.SwitchToPage(connection.URL)
App.Draw()
} else {
cs.StatusText.SetText("Connecting...").SetTextColor(tview.Styles.TertiaryTextColor)
cs.StatusText.SetText("Connecting...").SetTextColor(app.Styles.TertiaryTextColor)
App.Draw()

var newDbDriver drivers.Driver
Expand Down
3 changes: 2 additions & 1 deletion components/ConnectionsTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"

"github.com/jorgerojas26/lazysql/app"
"github.com/jorgerojas26/lazysql/helpers"
"github.com/jorgerojas26/lazysql/models"
)
Expand All @@ -29,7 +30,7 @@ func NewConnectionsTable() *ConnectionsTable {
}

table.SetOffset(5, 0)
table.SetSelectedStyle(tcell.StyleDefault.Foreground(tview.Styles.SecondaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor))
table.SetSelectedStyle(tcell.StyleDefault.Foreground(app.Styles.SecondaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor))

wrapper.AddItem(table, 0, 1, true)

Expand Down
8 changes: 4 additions & 4 deletions components/HelpModal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func NewHelpModal() *HelpModal {

// table.SetBorders(true)
table.SetBorder(true)
table.SetBorderColor(tview.Styles.PrimaryTextColor)
table.SetBorderColor(app.Styles.PrimaryTextColor)
table.SetTitle(" Keybindings ")
table.SetSelectable(true, false)
table.SetSelectedStyle(tcell.StyleDefault.Background(tview.Styles.SecondaryTextColor).Foreground(tview.Styles.ContrastSecondaryTextColor))
table.SetSelectedStyle(tcell.StyleDefault.Background(app.Styles.SecondaryTextColor).Foreground(tview.Styles.ContrastSecondaryTextColor))

keymapGroups := app.Keymaps.Groups

Expand All @@ -51,7 +51,7 @@ func NewHelpModal() *HelpModal {
for groupName, keys := range keymapGroups {
rowCount := table.GetRowCount()
groupNameCell := tview.NewTableCell(strings.ToUpper(groupName))
groupNameCell.SetTextColor(tview.Styles.TertiaryTextColor)
groupNameCell.SetTextColor(app.Styles.TertiaryTextColor)
groupNameCell.SetSelectable(rowCount == 0)

table.SetCell(rowCount, 0, tview.NewTableCell("").SetSelectable(false))
Expand All @@ -64,7 +64,7 @@ func NewHelpModal() *HelpModal {
if len(keyText) < len(mostLengthyKey) {
keyText = strings.Repeat(" ", len(mostLengthyKey)-len(keyText)) + keyText
}
table.SetCell(rowCount+3+i, 0, tview.NewTableCell(keyText).SetAlign(tview.AlignRight).SetTextColor(tview.Styles.SecondaryTextColor))
table.SetCell(rowCount+3+i, 0, tview.NewTableCell(keyText).SetAlign(tview.AlignRight).SetTextColor(app.Styles.SecondaryTextColor))
table.SetCell(rowCount+3+i, 1, tview.NewTableCell(key.Description).SetAlign(tview.AlignLeft).SetExpansion(1))
}

Expand Down
2 changes: 1 addition & 1 deletion components/HelpStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type HelpStatus struct {
}

func NewHelpStatus() HelpStatus {
status := HelpStatus{tview.NewTextView().SetTextColor(tview.Styles.TertiaryTextColor)}
status := HelpStatus{tview.NewTextView().SetTextColor(app.Styles.TertiaryTextColor)}

status.SetStatusOnTree()

Expand Down
12 changes: 6 additions & 6 deletions components/Home.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func NewHomePage(connection models.Connection, dbdriver drivers.Driver) *Home {

go home.subscribeToTreeChanges()

leftWrapper.SetBorderColor(tview.Styles.InverseTextColor)
leftWrapper.SetBorderColor(app.Styles.InverseTextColor)
leftWrapper.AddItem(tree.Wrapper, 0, 1, true)

rightWrapper.SetBorderColor(tview.Styles.InverseTextColor)
rightWrapper.SetBorderColor(app.Styles.InverseTextColor)
rightWrapper.SetBorder(true)
rightWrapper.SetDirection(tview.FlexColumnCSS)
rightWrapper.SetInputCapture(home.rightWrapperInputCapture)
Expand Down Expand Up @@ -131,8 +131,8 @@ func (home *Home) subscribeToTreeChanges() {
func (home *Home) focusRightWrapper() {
home.Tree.RemoveHighlight()

home.RightWrapper.SetBorderColor(tview.Styles.PrimaryTextColor)
home.LeftWrapper.SetBorderColor(tview.Styles.InverseTextColor)
home.RightWrapper.SetBorderColor(app.Styles.PrimaryTextColor)
home.LeftWrapper.SetBorderColor(app.Styles.InverseTextColor)
home.TabbedPane.Highlight()
tab := home.TabbedPane.GetCurrentTab()

Expand Down Expand Up @@ -177,8 +177,8 @@ func (home *Home) focusTab(tab *Tab) {
func (home *Home) focusLeftWrapper() {
home.Tree.Highlight()

home.RightWrapper.SetBorderColor(tview.Styles.InverseTextColor)
home.LeftWrapper.SetBorderColor(tview.Styles.PrimaryTextColor)
home.RightWrapper.SetBorderColor(app.Styles.InverseTextColor)
home.LeftWrapper.SetBorderColor(app.Styles.PrimaryTextColor)

tab := home.TabbedPane.GetCurrentTab()

Expand Down
4 changes: 3 additions & 1 deletion components/Pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package components

import (
"github.com/rivo/tview"

"github.com/jorgerojas26/lazysql/app"
)

var MainPages = tview.NewPages()

func init() {
MainPages.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
MainPages.SetBackgroundColor(app.Styles.PrimitiveBackgroundColor)
MainPages.AddPage(pageNameConnections, NewConnectionPages().Flex, true, true)
}
35 changes: 18 additions & 17 deletions components/ResultTableFilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"

"github.com/jorgerojas26/lazysql/app"
"github.com/jorgerojas26/lazysql/models"
)

Expand All @@ -27,14 +28,14 @@ func NewResultsFilter() *ResultsTableFilter {
recordsFilter.SetTitleAlign(tview.AlignCenter)
recordsFilter.SetBorderPadding(0, 0, 1, 1)

recordsFilter.Label.SetTextColor(tview.Styles.TertiaryTextColor)
recordsFilter.Label.SetTextColor(app.Styles.TertiaryTextColor)
recordsFilter.Label.SetText("WHERE")
recordsFilter.Label.SetBorderPadding(0, 0, 0, 1)

recordsFilter.Input.SetPlaceholder("Enter a WHERE clause to filter the results")
recordsFilter.Input.SetPlaceholderStyle(tcell.StyleDefault.Foreground(tview.Styles.PrimaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor))
recordsFilter.Input.SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
recordsFilter.Input.SetFieldTextColor(tview.Styles.PrimaryTextColor)
recordsFilter.Input.SetPlaceholderStyle(tcell.StyleDefault.Foreground(app.Styles.PrimaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor))
recordsFilter.Input.SetFieldBackgroundColor(app.Styles.PrimitiveBackgroundColor)
recordsFilter.Input.SetFieldTextColor(app.Styles.PrimaryTextColor)
recordsFilter.Input.SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyEnter:
Expand All @@ -50,7 +51,7 @@ func NewResultsFilter() *ResultsTableFilter {

}
})
recordsFilter.Input.SetAutocompleteStyles(tview.Styles.PrimitiveBackgroundColor, tcell.StyleDefault.Foreground(tview.Styles.PrimaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor), tcell.StyleDefault.Foreground(tview.Styles.SecondaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor))
recordsFilter.Input.SetAutocompleteStyles(app.Styles.PrimitiveBackgroundColor, tcell.StyleDefault.Foreground(tview.Styles.PrimaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor), tcell.StyleDefault.Foreground(tview.Styles.SecondaryTextColor).Background(tview.Styles.PrimitiveBackgroundColor))

recordsFilter.AddItem(recordsFilter.Label, 6, 0, false)
recordsFilter.AddItem(recordsFilter.Input, 0, 1, false)
Expand Down Expand Up @@ -87,29 +88,29 @@ func (filter *ResultsTableFilter) SetIsFiltering(filtering bool) {

// Function to blur
func (filter *ResultsTableFilter) RemoveHighlight() {
filter.SetBorderColor(tview.Styles.InverseTextColor)
filter.Label.SetTextColor(tview.Styles.InverseTextColor)
filter.Input.SetPlaceholderTextColor(tview.Styles.InverseTextColor)
filter.Input.SetFieldTextColor(tview.Styles.InverseTextColor)
filter.SetBorderColor(app.Styles.InverseTextColor)
filter.Label.SetTextColor(app.Styles.InverseTextColor)
filter.Input.SetPlaceholderTextColor(app.Styles.InverseTextColor)
filter.Input.SetFieldTextColor(app.Styles.InverseTextColor)
}

func (filter *ResultsTableFilter) RemoveLocalHighlight() {
filter.SetBorderColor(tcell.ColorWhite)
filter.Label.SetTextColor(tview.Styles.TertiaryTextColor)
filter.Input.SetPlaceholderTextColor(tview.Styles.InverseTextColor)
filter.Input.SetFieldTextColor(tview.Styles.InverseTextColor)
filter.Label.SetTextColor(app.Styles.TertiaryTextColor)
filter.Input.SetPlaceholderTextColor(app.Styles.InverseTextColor)
filter.Input.SetFieldTextColor(app.Styles.InverseTextColor)
}

func (filter *ResultsTableFilter) Highlight() {
filter.SetBorderColor(tcell.ColorWhite)
filter.Label.SetTextColor(tview.Styles.TertiaryTextColor)
filter.Label.SetTextColor(app.Styles.TertiaryTextColor)
filter.Input.SetPlaceholderTextColor(tcell.ColorWhite)
filter.Input.SetFieldTextColor(tview.Styles.PrimaryTextColor)
filter.Input.SetFieldTextColor(app.Styles.PrimaryTextColor)
}

func (filter *ResultsTableFilter) HighlightLocal() {
filter.SetBorderColor(tview.Styles.PrimaryTextColor)
filter.Label.SetTextColor(tview.Styles.TertiaryTextColor)
filter.SetBorderColor(app.Styles.PrimaryTextColor)
filter.Label.SetTextColor(app.Styles.TertiaryTextColor)
filter.Input.SetPlaceholderTextColor(tcell.ColorWhite)
filter.Input.SetFieldTextColor(tview.Styles.PrimaryTextColor)
filter.Input.SetFieldTextColor(app.Styles.PrimaryTextColor)
}
Loading

0 comments on commit 2305a74

Please sign in to comment.