diff --git a/app/App.go b/app/App.go index 213f09a..a0d2c4c 100644 --- a/app/App.go +++ b/app/App.go @@ -7,6 +7,15 @@ 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, @@ -14,12 +23,14 @@ func init() { 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 } diff --git a/components/ConfirmationModal.go b/components/ConfirmationModal.go index c9723b9..d0f6e79 100644 --- a/components/ConfirmationModal.go +++ b/components/ConfirmationModal.go @@ -2,6 +2,8 @@ package components import ( "github.com/rivo/tview" + + "github.com/jorgerojas26/lazysql/app" ) type ConfirmationModal struct { @@ -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, diff --git a/components/ConnectionForm.go b/components/ConnectionForm.go index c168017..30145cb 100644 --- a/components/ConnectionForm.go +++ b/components/ConnectionForm.go @@ -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" @@ -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) @@ -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 @@ -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() } diff --git a/components/ConnectionSelection.go b/components/ConnectionSelection.go index 301b37b..c5f50e4 100644 --- a/components/ConnectionSelection.go +++ b/components/ConnectionSelection.go @@ -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) @@ -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 diff --git a/components/ConnectionsTable.go b/components/ConnectionsTable.go index e4ca4ab..411609d 100644 --- a/components/ConnectionsTable.go +++ b/components/ConnectionsTable.go @@ -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" ) @@ -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) diff --git a/components/HelpModal.go b/components/HelpModal.go index 7bbf58e..27c965b 100644 --- a/components/HelpModal.go +++ b/components/HelpModal.go @@ -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 @@ -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)) @@ -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)) } diff --git a/components/HelpStatus.go b/components/HelpStatus.go index dfa03cb..32dec87 100644 --- a/components/HelpStatus.go +++ b/components/HelpStatus.go @@ -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() diff --git a/components/Home.go b/components/Home.go index a4400c1..664ca9c 100644 --- a/components/Home.go +++ b/components/Home.go @@ -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) @@ -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() @@ -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() diff --git a/components/Pages.go b/components/Pages.go index 07222fe..7bea031 100644 --- a/components/Pages.go +++ b/components/Pages.go @@ -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) } diff --git a/components/ResultTableFilter.go b/components/ResultTableFilter.go index 97f0a2c..002582d 100644 --- a/components/ResultTableFilter.go +++ b/components/ResultTableFilter.go @@ -4,6 +4,7 @@ import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" + "github.com/jorgerojas26/lazysql/app" "github.com/jorgerojas26/lazysql/models" ) @@ -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: @@ -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) @@ -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) } diff --git a/components/ResultsTable.go b/components/ResultsTable.go index 77a4acc..44aed85 100644 --- a/components/ResultsTable.go +++ b/components/ResultsTable.go @@ -79,14 +79,14 @@ func NewResultsTable(listOfDbChanges *[]models.DbDmlChange, tree *Tree, dbdriver errorModal.AddButtons([]string{"Ok"}) errorModal.SetText("An error occurred") errorModal.SetBackgroundColor(tcell.ColorRed) - errorModal.SetTextColor(tview.Styles.PrimaryTextColor) - errorModal.SetButtonStyle(tcell.StyleDefault.Foreground(tview.Styles.PrimaryTextColor)) + errorModal.SetTextColor(app.Styles.PrimaryTextColor) + errorModal.SetButtonStyle(tcell.StyleDefault.Foreground(app.Styles.PrimaryTextColor)) errorModal.SetFocus(0) loadingModal := tview.NewModal() loadingModal.SetText("Loading...") - loadingModal.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor) - loadingModal.SetTextColor(tview.Styles.SecondaryTextColor) + loadingModal.SetBackgroundColor(app.Styles.PrimitiveBackgroundColor) + loadingModal.SetTextColor(app.Styles.SecondaryTextColor) pages := tview.NewPages() pages.AddPage(pageNameTable, wrapper, true, true) @@ -115,7 +115,7 @@ func NewResultsTable(listOfDbChanges *[]models.DbDmlChange, tree *Tree, dbdriver table.SetBorders(true) table.SetFixed(1, 0) table.SetInputCapture(table.tableInputCapture) - table.SetSelectedStyle(tcell.StyleDefault.Background(tview.Styles.SecondaryTextColor).Foreground(tview.Styles.ContrastSecondaryTextColor)) + table.SetSelectedStyle(tcell.StyleDefault.Background(app.Styles.SecondaryTextColor).Foreground(tview.Styles.ContrastSecondaryTextColor)) table.Page.AddPage(pageNameSidebar, table.Sidebar, false, false) table.SetSelectionChangedFunc(func(_, _ int) { @@ -172,8 +172,8 @@ func (table *ResultsTable) WithEditor() *ResultsTable { resultsInfoWrapper := tview.NewFlex().SetDirection(tview.FlexColumnCSS) resultsInfoText := tview.NewTextView() resultsInfoText.SetBorder(true) - resultsInfoText.SetBorderColor(tview.Styles.PrimaryTextColor) - resultsInfoText.SetTextColor(tview.Styles.PrimaryTextColor) + resultsInfoText.SetBorderColor(app.Styles.PrimaryTextColor) + resultsInfoText.SetTextColor(app.Styles.PrimaryTextColor) resultsInfoWrapper.AddItem(resultsInfoText, 3, 0, false) editorPages.AddPage(pageNameTableEditorTable, tableWrapper, true, false) @@ -224,7 +224,7 @@ func (table *ResultsTable) AddRows(rows [][]string) { tableCell.SetSelectable(i > 0) tableCell.SetExpansion(1) - tableCell.SetTextColor(tview.Styles.PrimaryTextColor) + tableCell.SetTextColor(app.Styles.PrimaryTextColor) table.SetCell(i, j, tableCell) } @@ -272,7 +272,7 @@ func (table *ResultsTable) AppendNewRow(cells []models.CellValue, index int, UUI tableCell := tview.NewTableCell(cell.Value.(string)) tableCell.SetExpansion(1) tableCell.SetReference(UUID) - tableCell.SetTextColor(tview.Styles.PrimaryTextColor) + tableCell.SetTextColor(app.Styles.PrimaryTextColor) tableCell.SetBackgroundColor(tcell.ColorDarkGreen) switch cell.Type { @@ -280,7 +280,7 @@ func (table *ResultsTable) AppendNewRow(cells []models.CellValue, index int, UUI case models.Default: case models.String: tableCell.SetText("") - tableCell.SetTextColor(tview.Styles.InverseTextColor) + tableCell.SetTextColor(app.Styles.InverseTextColor) } table.SetCell(index, i, tableCell) @@ -455,10 +455,10 @@ func (table *ResultsTable) UpdateRowsColor(headerColor tcell.Color, rowColor tce } func (table *ResultsTable) RemoveHighlightTable() { - table.SetBorderColor(tview.Styles.InverseTextColor) - table.SetBordersColor(tview.Styles.InverseTextColor) - table.SetTitleColor(tview.Styles.InverseTextColor) - table.UpdateRowsColor(tview.Styles.InverseTextColor, tview.Styles.InverseTextColor) + table.SetBorderColor(app.Styles.InverseTextColor) + table.SetBordersColor(app.Styles.InverseTextColor) + table.SetTitleColor(app.Styles.InverseTextColor) + table.UpdateRowsColor(app.Styles.InverseTextColor, tview.Styles.InverseTextColor) } func (table *ResultsTable) RemoveHighlightAll() { @@ -472,10 +472,10 @@ func (table *ResultsTable) RemoveHighlightAll() { } func (table *ResultsTable) HighlightTable() { - table.SetBorderColor(tview.Styles.PrimaryTextColor) - table.SetBordersColor(tview.Styles.PrimaryTextColor) - table.SetTitleColor(tview.Styles.PrimaryTextColor) - table.UpdateRowsColor(tview.Styles.PrimaryTextColor, tview.Styles.PrimaryTextColor) + table.SetBorderColor(app.Styles.PrimaryTextColor) + table.SetBordersColor(app.Styles.PrimaryTextColor) + table.SetTitleColor(app.Styles.PrimaryTextColor) + table.UpdateRowsColor(app.Styles.PrimaryTextColor, tview.Styles.PrimaryTextColor) } func (table *ResultsTable) HighlightAll() { @@ -801,7 +801,7 @@ func (table *ResultsTable) SetSortedBy(column string, direction string) { tableCell := tview.NewTableCell(col[0]) tableCell.SetSelectable(false) tableCell.SetExpansion(1) - tableCell.SetTextColor(tview.Styles.PrimaryTextColor) + tableCell.SetTextColor(app.Styles.PrimaryTextColor) if col[0] == column { tableCell.SetText(fmt.Sprintf("%s %s", col[0], iconDirection)) @@ -868,8 +868,8 @@ func (table *ResultsTable) StartEditingCell(row int, col int, callback func(newV cell := table.GetCell(row, col) inputField := tview.NewInputField() inputField.SetText(cell.Text) - inputField.SetFieldBackgroundColor(tview.Styles.PrimaryTextColor) - inputField.SetFieldTextColor(tview.Styles.PrimitiveBackgroundColor) + inputField.SetFieldBackgroundColor(app.Styles.PrimaryTextColor) + inputField.SetFieldTextColor(app.Styles.PrimitiveBackgroundColor) inputField.SetDoneFunc(func(key tcell.Key) { table.SetIsEditing(false) @@ -990,7 +990,7 @@ func (table *ResultsTable) AppendNewChange(changeType models.DmlType, databaseNa } else { (*table.state.listOfDbChanges)[i].Values = append((*table.state.listOfDbChanges)[i].Values[:valueIndex], (*table.state.listOfDbChanges)[i].Values[valueIndex+1:]...) } - table.SetCellColor(rowIndex, colIndex, tview.Styles.PrimitiveBackgroundColor) + table.SetCellColor(rowIndex, colIndex, app.Styles.PrimitiveBackgroundColor) } else { (*table.state.listOfDbChanges)[i].Values[valueIndex] = value } @@ -1001,7 +1001,7 @@ func (table *ResultsTable) AppendNewChange(changeType models.DmlType, databaseNa case models.DmlDeleteType: *table.state.listOfDbChanges = append((*table.state.listOfDbChanges)[:i], (*table.state.listOfDbChanges)[i+1:]...) - table.SetRowColor(rowIndex, tview.Styles.PrimitiveBackgroundColor) + table.SetRowColor(rowIndex, app.Styles.PrimitiveBackgroundColor) } } } @@ -1307,7 +1307,7 @@ func (table *ResultsTable) UpdateSidebar() { if repeatCount <= 0 { repeatCount = 1 } - title += "[gray]" + strings.Repeat("-", repeatCount) + title += fmt.Sprintf("[%s]", app.Styles.SidebarTitleBorderColor) + strings.Repeat("-", repeatCount) title += colType table.Sidebar.AddField(title, text, sidebarWidth) diff --git a/components/ResultsTableMenu.go b/components/ResultsTableMenu.go index a2aa0df..e37ba9b 100644 --- a/components/ResultsTableMenu.go +++ b/components/ResultsTableMenu.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/rivo/tview" + + "github.com/jorgerojas26/lazysql/app" ) type ResultsTableMenuState struct { @@ -46,7 +48,7 @@ func NewResultsTableMenu() *ResultsTableMenu { textview := tview.NewTextView().SetText(text) if i == 0 { - textview.SetTextColor(tview.Styles.PrimaryTextColor) + textview.SetTextColor(app.Styles.PrimaryTextColor) } size := 15 @@ -80,29 +82,29 @@ func (menu *ResultsTableMenu) SetSelectedOption(option int) { itemCount := menu.GetItemCount() for i := 0; i < itemCount; i++ { - menu.GetItem(i).(*tview.TextView).SetTextColor(tview.Styles.PrimaryTextColor) + menu.GetItem(i).(*tview.TextView).SetTextColor(app.Styles.PrimaryTextColor) } - menu.GetItem(option - 1).(*tview.TextView).SetTextColor(tview.Styles.SecondaryTextColor) + menu.GetItem(option - 1).(*tview.TextView).SetTextColor(app.Styles.SecondaryTextColor) } } func (menu *ResultsTableMenu) SetBlur() { - menu.SetBorderColor(tview.Styles.InverseTextColor) + menu.SetBorderColor(app.Styles.InverseTextColor) for _, item := range menu.MenuItems { - item.SetTextColor(tview.Styles.InverseTextColor) + item.SetTextColor(app.Styles.InverseTextColor) } } func (menu *ResultsTableMenu) SetFocus() { - menu.SetBorderColor(tview.Styles.PrimaryTextColor) + menu.SetBorderColor(app.Styles.PrimaryTextColor) for i, item := range menu.MenuItems { if i+1 == menu.GetSelectedOption() { - item.SetTextColor(tview.Styles.SecondaryTextColor) + item.SetTextColor(app.Styles.SecondaryTextColor) } else { - item.SetTextColor(tview.Styles.PrimaryTextColor) + item.SetTextColor(app.Styles.PrimaryTextColor) } } } diff --git a/components/SQLEditor.go b/components/SQLEditor.go index e314811..dc5e3ba 100644 --- a/components/SQLEditor.go +++ b/components/SQLEditor.go @@ -79,13 +79,13 @@ func (s *SQLEditor) SetIsFocused(isFocused bool) { } func (s *SQLEditor) Highlight() { - s.SetBorderColor(tview.Styles.PrimaryTextColor) - s.SetTextStyle(tcell.StyleDefault.Foreground(tview.Styles.PrimaryTextColor)) + s.SetBorderColor(app.Styles.PrimaryTextColor) + s.SetTextStyle(tcell.StyleDefault.Foreground(app.Styles.PrimaryTextColor)) } func (s *SQLEditor) SetBlur() { - s.SetBorderColor(tview.Styles.InverseTextColor) - s.SetTextStyle(tcell.StyleDefault.Foreground(tview.Styles.InverseTextColor)) + s.SetBorderColor(app.Styles.InverseTextColor) + s.SetTextStyle(tcell.StyleDefault.Foreground(app.Styles.InverseTextColor)) } /* diff --git a/components/Sidebar.go b/components/Sidebar.go index 69b593e..0fba002 100644 --- a/components/Sidebar.go +++ b/components/Sidebar.go @@ -24,7 +24,7 @@ type Sidebar struct { func NewSidebar() *Sidebar { flex := tview.NewFlex().SetDirection(tview.FlexColumnCSS) frame := tview.NewFrame(flex) - frame.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor) + frame.SetBackgroundColor(app.Styles.PrimitiveBackgroundColor) frame.SetBorder(true) sidebarState := &SidebarState{ @@ -56,9 +56,9 @@ func (sidebar *Sidebar) AddField(title, text string, fieldWidth int) { field.SetBorder(true) field.SetTitle(title) field.SetTitleAlign(tview.AlignLeft) - field.SetTitleColor(tview.Styles.PrimaryTextColor) + field.SetTitleColor(app.Styles.PrimaryTextColor) field.SetText(text, true) - field.SetTextStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.SecondaryTextColor)) + field.SetTextStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.SecondaryTextColor)) textLength := len(field.GetText()) @@ -186,20 +186,20 @@ func (sidebar *Sidebar) inputCapture(event *tcell.EventKey) *tcell.EventKey { } func (sidebar *Sidebar) SetEditingStyles(item *tview.TextArea) { - item.SetBackgroundColor(tview.Styles.SecondaryTextColor) - item.SetTextStyle(tcell.StyleDefault.Background(tview.Styles.SecondaryTextColor).Foreground(tview.Styles.ContrastSecondaryTextColor)) - item.SetTitleColor(tview.Styles.ContrastSecondaryTextColor) - item.SetBorderColor(tview.Styles.ContrastSecondaryTextColor) + item.SetBackgroundColor(app.Styles.SecondaryTextColor) + item.SetTextStyle(tcell.StyleDefault.Background(app.Styles.SecondaryTextColor).Foreground(tview.Styles.ContrastSecondaryTextColor)) + item.SetTitleColor(app.Styles.ContrastSecondaryTextColor) + item.SetBorderColor(app.Styles.ContrastSecondaryTextColor) item.SetWrap(true) item.SetDisabled(false) } func (sidebar *Sidebar) SetDisabledStyles(item *tview.TextArea) { - item.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor) - item.SetTextStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.SecondaryTextColor)) - item.SetTitleColor(tview.Styles.PrimaryTextColor) - item.SetBorderColor(tview.Styles.BorderColor) + item.SetBackgroundColor(app.Styles.PrimitiveBackgroundColor) + item.SetTextStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.SecondaryTextColor)) + item.SetTitleColor(app.Styles.PrimaryTextColor) + item.SetBorderColor(app.Styles.BorderColor) item.SetWrap(true) item.SetDisabled(true) diff --git a/components/TabbedMenu.go b/components/TabbedMenu.go index 75dfd0f..2ee7bf7 100644 --- a/components/TabbedMenu.go +++ b/components/TabbedMenu.go @@ -241,9 +241,9 @@ func (t *TabbedPane) HighlightTabHeader(tab *Tab) { for i := 0; tabToHighlight != nil && i < t.state.Length; i++ { if tabToHighlight.Header == tab.Header { - tabToHighlight.Header.SetTextColor(tview.Styles.SecondaryTextColor) + tabToHighlight.Header.SetTextColor(app.Styles.SecondaryTextColor) } else { - tabToHighlight.Header.SetTextColor(tview.Styles.PrimaryTextColor) + tabToHighlight.Header.SetTextColor(app.Styles.PrimaryTextColor) } tabToHighlight = tabToHighlight.NextTab } @@ -254,9 +254,9 @@ func (t *TabbedPane) Highlight() { for i := 0; tab != nil && i < t.state.Length; i++ { if tab == t.state.CurrentTab { - tab.Header.SetTextColor(tview.Styles.SecondaryTextColor) + tab.Header.SetTextColor(app.Styles.SecondaryTextColor) } else { - tab.Header.SetTextColor(tview.Styles.PrimaryTextColor) + tab.Header.SetTextColor(app.Styles.PrimaryTextColor) } tab = tab.NextTab } @@ -266,7 +266,7 @@ func (t *TabbedPane) SetBlur() { tab := t.state.FirstTab for i := 0; tab != nil && i < t.state.Length; i++ { - tab.Header.SetTextColor(tview.Styles.InverseTextColor) + tab.Header.SetTextColor(app.Styles.InverseTextColor) tab = tab.NextTab } } diff --git a/components/Tree.go b/components/Tree.go index 8e15d75..17ac075 100644 --- a/components/Tree.go +++ b/components/Tree.go @@ -49,7 +49,7 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree { } tree.SetTopLevel(1) - tree.SetGraphicsColor(tview.Styles.PrimaryTextColor) + tree.SetGraphicsColor(app.Styles.PrimaryTextColor) // tree.SetBorder(true) tree.SetTitle("Databases") tree.SetTitleAlign(tview.AlignLeft) @@ -77,7 +77,7 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree { childNode := tview.NewTreeNode(database) childNode.SetExpanded(false) childNode.SetReference(database) - childNode.SetColor(tview.Styles.PrimaryTextColor) + childNode.SetColor(app.Styles.PrimaryTextColor) rootNode.AddChild(childNode) go func(database string, node *tview.TreeNode) { @@ -95,7 +95,7 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree { tree.SetFocusFunc(nil) }) - selectedNodeTextColor := fmt.Sprintf("[black:%s]", tview.Styles.SecondaryTextColor.Name()) + selectedNodeTextColor := fmt.Sprintf("[black:%s]", app.Styles.SecondaryTextColor.Name()) previouslyFocusedNode := tree.GetCurrentNode() previouslyFocusedNode.SetText(selectedNodeTextColor + previouslyFocusedNode.GetText()) @@ -253,33 +253,33 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree { return event }) - tree.Filter.SetFieldStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.PrimaryTextColor)) - tree.Filter.SetPlaceholderStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.InverseTextColor)) + tree.Filter.SetFieldStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.PrimaryTextColor)) + tree.Filter.SetPlaceholderStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.InverseTextColor)) tree.Filter.SetBorderPadding(0, 0, 0, 0) - tree.Filter.SetBorderColor(tview.Styles.PrimaryTextColor) + tree.Filter.SetBorderColor(app.Styles.PrimaryTextColor) tree.Filter.SetLabel("Search: ") - tree.Filter.SetLabelColor(tview.Styles.InverseTextColor) + tree.Filter.SetLabelColor(app.Styles.InverseTextColor) tree.Filter.SetFocusFunc(func() { - tree.Filter.SetLabelColor(tview.Styles.TertiaryTextColor) - tree.Filter.SetFieldTextColor(tview.Styles.PrimaryTextColor) + tree.Filter.SetLabelColor(app.Styles.TertiaryTextColor) + tree.Filter.SetFieldTextColor(app.Styles.PrimaryTextColor) }) tree.Filter.SetBlurFunc(func() { if tree.Filter.GetText() == "" { - tree.Filter.SetLabelColor(tview.Styles.InverseTextColor) + tree.Filter.SetLabelColor(app.Styles.InverseTextColor) } else { - tree.Filter.SetLabelColor(tview.Styles.TertiaryTextColor) + tree.Filter.SetLabelColor(app.Styles.TertiaryTextColor) } - tree.Filter.SetFieldTextColor(tview.Styles.InverseTextColor) + tree.Filter.SetFieldTextColor(app.Styles.InverseTextColor) }) - tree.FoundNodeCountInput.SetFieldStyle(tcell.StyleDefault.Background(tview.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.PrimaryTextColor)) + tree.FoundNodeCountInput.SetFieldStyle(tcell.StyleDefault.Background(app.Styles.PrimitiveBackgroundColor).Foreground(tview.Styles.PrimaryTextColor)) tree.Wrapper.SetDirection(tview.FlexRow) tree.Wrapper.SetBorder(true) tree.Wrapper.SetBorderPadding(0, 0, 1, 1) - tree.Wrapper.SetTitleColor(tview.Styles.PrimaryTextColor) + tree.Wrapper.SetTitleColor(app.Styles.PrimaryTextColor) tree.Wrapper.AddItem(tree.Filter, 1, 0, false) tree.Wrapper.AddItem(tree.FoundNodeCountInput, 1, 0, false) @@ -300,14 +300,14 @@ func (tree *Tree) databasesToNodes(children map[string][]string, node *tview.Tre rootNode = tview.NewTreeNode(key) rootNode.SetExpanded(false) rootNode.SetReference(key) - rootNode.SetColor(tview.Styles.PrimaryTextColor) + rootNode.SetColor(app.Styles.PrimaryTextColor) node.AddChild(rootNode) } for _, child := range values { childNode := tview.NewTreeNode(child) childNode.SetExpanded(defaultExpanded) - childNode.SetColor(tview.Styles.PrimaryTextColor) + childNode.SetColor(app.Styles.PrimaryTextColor) if tree.DBDriver.GetProvider() == "sqlite3" { childNode.SetReference(child) } else if tree.DBDriver.GetProvider() == "postgres" { @@ -411,10 +411,10 @@ func (tree *Tree) SetIsFiltering(isFiltering bool) { // Blur func func (tree *Tree) RemoveHighlight() { - tree.SetBorderColor(tview.Styles.InverseTextColor) - tree.SetGraphicsColor(tview.Styles.InverseTextColor) - tree.SetTitleColor(tview.Styles.InverseTextColor) - // tree.GetRoot().SetColor(tview.Styles.InverseTextColor) + tree.SetBorderColor(app.Styles.InverseTextColor) + tree.SetGraphicsColor(app.Styles.InverseTextColor) + tree.SetTitleColor(app.Styles.InverseTextColor) + // tree.GetRoot().SetColor(app.Styles.InverseTextColor) childrens := tree.GetRoot().GetChildren() @@ -423,8 +423,8 @@ func (tree *Tree) RemoveHighlight() { childrenIsCurrentNode := children.GetReference() == tree.GetCurrentNode().GetReference() - if !childrenIsCurrentNode && currentColor == tview.Styles.PrimaryTextColor { - children.SetColor(tview.Styles.InverseTextColor) + if !childrenIsCurrentNode && currentColor == app.Styles.PrimaryTextColor { + children.SetColor(app.Styles.InverseTextColor) } childrenOfChildren := children.GetChildren() @@ -434,8 +434,8 @@ func (tree *Tree) RemoveHighlight() { childrenIsCurrentNode := children.GetReference() == tree.GetCurrentNode().GetReference() - if !childrenIsCurrentNode && currentColor == tview.Styles.PrimaryTextColor { - children.SetColor(tview.Styles.InverseTextColor) + if !childrenIsCurrentNode && currentColor == app.Styles.PrimaryTextColor { + children.SetColor(app.Styles.InverseTextColor) } } @@ -444,21 +444,21 @@ func (tree *Tree) RemoveHighlight() { } func (tree *Tree) ForceRemoveHighlight() { - tree.SetBorderColor(tview.Styles.InverseTextColor) - tree.SetGraphicsColor(tview.Styles.InverseTextColor) - tree.SetTitleColor(tview.Styles.InverseTextColor) - tree.GetRoot().SetColor(tview.Styles.InverseTextColor) + tree.SetBorderColor(app.Styles.InverseTextColor) + tree.SetGraphicsColor(app.Styles.InverseTextColor) + tree.SetTitleColor(app.Styles.InverseTextColor) + tree.GetRoot().SetColor(app.Styles.InverseTextColor) childrens := tree.GetRoot().GetChildren() for _, children := range childrens { - children.SetColor(tview.Styles.InverseTextColor) + children.SetColor(app.Styles.InverseTextColor) childrenOfChildren := children.GetChildren() for _, children := range childrenOfChildren { - children.SetColor(tview.Styles.InverseTextColor) + children.SetColor(app.Styles.InverseTextColor) } } @@ -466,26 +466,26 @@ func (tree *Tree) ForceRemoveHighlight() { // Focus func func (tree *Tree) Highlight() { - tree.SetBorderColor(tview.Styles.PrimaryTextColor) - tree.SetGraphicsColor(tview.Styles.PrimaryTextColor) - tree.SetTitleColor(tview.Styles.PrimaryTextColor) - tree.GetRoot().SetColor(tview.Styles.PrimaryTextColor) + tree.SetBorderColor(app.Styles.PrimaryTextColor) + tree.SetGraphicsColor(app.Styles.PrimaryTextColor) + tree.SetTitleColor(app.Styles.PrimaryTextColor) + tree.GetRoot().SetColor(app.Styles.PrimaryTextColor) childrens := tree.GetRoot().GetChildren() for _, children := range childrens { currentColor := children.GetColor() - if currentColor == tview.Styles.InverseTextColor { - children.SetColor(tview.Styles.PrimaryTextColor) + if currentColor == app.Styles.InverseTextColor { + children.SetColor(app.Styles.PrimaryTextColor) childrenOfChildren := children.GetChildren() for _, children := range childrenOfChildren { currentColor := children.GetColor() - if currentColor == tview.Styles.InverseTextColor { - children.SetColor(tview.Styles.PrimaryTextColor) + if currentColor == app.Styles.InverseTextColor { + children.SetColor(app.Styles.PrimaryTextColor) } }