Skip to content

Commit

Permalink
feat: rework unused style props, add default style for borders (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
prgres authored May 19, 2024
1 parent 1bad962 commit b8a95ff
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 185 deletions.
6 changes: 4 additions & 2 deletions ui/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
type UserContext struct {
Api *api.Api
Config *config.Config
Style theme.Style
Style *theme.Style
Theme *theme.Theme
WindowSize WindowSize
}

Expand All @@ -22,7 +23,8 @@ type WindowSize struct {

func NewUserContext(logger *log.Logger, api *api.Api, config *config.Config) UserContext {
return UserContext{
Style: theme.NewStyle(*theme.DefaultTheme),
Style: theme.DefautlStyle,
Theme: theme.DefaultTheme,
WindowSize: WindowSize{
Width: 0,
Height: 0,
Expand Down
146 changes: 7 additions & 139 deletions ui/theme/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,146 +3,14 @@ package theme
import "github.com/charmbracelet/lipgloss"

type Style struct {
ListViewPort struct {
PagerStyle lipgloss.Style
}
Table struct {
CellStyle lipgloss.Style
SelectedCellStyle lipgloss.Style
TitleCellStyle lipgloss.Style
SingleRuneTitleCellStyle lipgloss.Style
HeaderStyle lipgloss.Style
RowStyle lipgloss.Style
}
Tabs struct {
Tab lipgloss.Style
ActiveTab lipgloss.Style
TabSeparator lipgloss.Style
TabsRow lipgloss.Style
ViewSwitcher lipgloss.Style
ActiveView lipgloss.Style
ViewsSeparator lipgloss.Style
InactiveView lipgloss.Style
}
Borders lipgloss.Style
}

var (
SearchHeight = 3
FooterHeight = 1
ExpandedHelpHeight = 11
InputBoxHeight = 8
SingleRuneWidth = 4
MainContentPadding = 1
TabsBorderHeight = 1
TabsContentHeight = 2
TabsHeight = TabsBorderHeight + TabsContentHeight
ViewSwitcherMargin = 1
TableHeaderHeight = 2
)

type CommonStyles struct {
MainTextStyle lipgloss.Style
FooterStyle lipgloss.Style
ErrorStyle lipgloss.Style
WaitingGlyph string
FailureGlyph string
SuccessGlyph string
}

const (
WaitingIcon = ""
FailureIcon = "󰅙"
SuccessIcon = ""
)

func BuildStyles(theme Theme) CommonStyles {
var s CommonStyles

s.MainTextStyle = lipgloss.NewStyle().
Foreground(theme.PrimaryText).
Bold(true)
s.FooterStyle = lipgloss.NewStyle().
Background(theme.SelectedBackground).
Height(FooterHeight)

s.ErrorStyle = s.FooterStyle.Copy().
Foreground(theme.WarningText).
MaxHeight(FooterHeight)

s.WaitingGlyph = lipgloss.NewStyle().
Foreground(theme.FaintText).
Render(WaitingIcon)
s.FailureGlyph = lipgloss.NewStyle().
Foreground(theme.WarningText).
Render(FailureIcon)
s.SuccessGlyph = lipgloss.NewStyle().
Foreground(theme.SuccessText).
Render(SuccessIcon)

return s
}

func NewStyle(theme Theme) Style {
var s Style

s.ListViewPort.PagerStyle = lipgloss.NewStyle().
Padding(0, 1).
Background(theme.SelectedBackground).
Foreground(theme.FaintText)

s.Table.CellStyle = lipgloss.NewStyle().PaddingLeft(1).
PaddingRight(1).
MaxHeight(1)
s.Table.SelectedCellStyle = s.Table.CellStyle.Copy().
Background(theme.SelectedBackground)
s.Table.TitleCellStyle = s.Table.CellStyle.Copy().
Bold(true).
Foreground(theme.PrimaryText)
s.Table.SingleRuneTitleCellStyle = s.Table.TitleCellStyle.Copy().
Width(SingleRuneWidth)
s.Table.HeaderStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(theme.FaintBorder).
BorderBottom(true)
s.Table.RowStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(theme.FaintBorder)

s.Tabs.Tab = lipgloss.NewStyle().
Faint(true).
Padding(0, 2)
s.Tabs.ActiveTab = s.Tabs.Tab.
Copy().
Faint(false).
Bold(true).
Background(theme.SelectedBackground).
Foreground(theme.PrimaryText)
s.Tabs.TabSeparator = lipgloss.NewStyle().
Foreground(theme.SecondaryBorder)
s.Tabs.TabsRow = lipgloss.NewStyle().
Height(TabsContentHeight).
PaddingTop(1).
PaddingBottom(0).
var DefautlStyle = &Style{
Borders: lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderBottom(true).
BorderStyle(lipgloss.ThickBorder()).
BorderBottomForeground(theme.PrimaryBorder)
s.Tabs.ViewSwitcher = lipgloss.NewStyle().
Background(theme.SecondaryText).
Foreground(theme.InvertedText).
Padding(0, 1).
Bold(true)

s.Tabs.ActiveView = lipgloss.NewStyle().
Foreground(theme.PrimaryText).
Bold(true).
Background(theme.SelectedBackground)
s.Tabs.ViewsSeparator = lipgloss.NewStyle().
BorderForeground(theme.PrimaryBorder).
BorderStyle(lipgloss.NormalBorder()).
BorderRight(true)
s.Tabs.InactiveView = lipgloss.NewStyle().
Background(theme.FaintBorder).
Foreground(theme.SecondaryText)

return s
BorderRight(true).
BorderTop(true).
BorderLeft(true),
}
24 changes: 4 additions & 20 deletions ui/theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,11 @@ import (
)

type Theme struct {
SelectedBackground lipgloss.AdaptiveColor
PrimaryBorder lipgloss.AdaptiveColor
FaintBorder lipgloss.AdaptiveColor
SecondaryBorder lipgloss.AdaptiveColor
FaintText lipgloss.AdaptiveColor
PrimaryText lipgloss.AdaptiveColor
SecondaryText lipgloss.AdaptiveColor
InvertedText lipgloss.AdaptiveColor
SuccessText lipgloss.AdaptiveColor
WarningText lipgloss.AdaptiveColor
BordersColorActive lipgloss.Color
BordersColorInactive lipgloss.Color
}

var DefaultTheme = &Theme{
PrimaryBorder: lipgloss.AdaptiveColor{Light: "013", Dark: "008"},
SecondaryBorder: lipgloss.AdaptiveColor{Light: "008", Dark: "007"},
SelectedBackground: lipgloss.AdaptiveColor{Light: "006", Dark: "008"},
FaintBorder: lipgloss.AdaptiveColor{Light: "254", Dark: "000"},
PrimaryText: lipgloss.AdaptiveColor{Light: "000", Dark: "015"},
SecondaryText: lipgloss.AdaptiveColor{Light: "244", Dark: "251"},
FaintText: lipgloss.AdaptiveColor{Light: "007", Dark: "245"},
InvertedText: lipgloss.AdaptiveColor{Light: "015", Dark: "236"},
SuccessText: lipgloss.AdaptiveColor{Light: "002", Dark: "002"},
WarningText: lipgloss.AdaptiveColor{Light: "001", Dark: "001"},
BordersColorActive: lipgloss.Color("#8909FF"),
BordersColorInactive: lipgloss.Color("#FFF"),
}
14 changes: 6 additions & 8 deletions ui/widgets/tasks-sidebar/tasksidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,16 @@ func (m Model) renderTask(task clickup.Task) string {
}

func (m Model) View() string {
bColor := lipgloss.Color("#FFF")
bColor := m.ctx.Theme.BordersColorInactive
if m.Focused {
bColor = lipgloss.Color("#8909FF")
bColor = m.ctx.Theme.BordersColorActive
}

styleBorders := m.ctx.Style.Borders.Copy().
BorderForeground(bColor)

return lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(bColor).
BorderRight(m.ifBorders).
BorderBottom(m.ifBorders).
BorderTop(m.ifBorders).
BorderLeft(m.ifBorders).
Inherit(styleBorders).
Render(
m.viewport.View(),
)
Expand Down
14 changes: 6 additions & 8 deletions ui/widgets/tasks-table/taskstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,16 @@ func (m Model) Update(msg tea.Msg) (common.Widget, tea.Cmd) {
}

func (m Model) View() string {
bColor := lipgloss.Color("#FFF")
bColor := m.ctx.Theme.BordersColorInactive
if m.Focused {
bColor = lipgloss.Color("#8909FF")
bColor = m.ctx.Theme.BordersColorActive
}

styleBorders := m.ctx.Style.Borders.Copy().
BorderForeground(bColor)

return lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(bColor).
BorderBottom(m.ifBorders).
BorderRight(m.ifBorders).
BorderTop(m.ifBorders).
BorderLeft(m.ifBorders).
Inherit(styleBorders).
Render(
m.table.View(),
)
Expand Down
14 changes: 6 additions & 8 deletions ui/widgets/tasks-tabs/taskstabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,16 @@ func (m Model) View() string {
}
}

bColor := lipgloss.Color("#FFF")
bColor := m.ctx.Theme.BordersColorInactive
if m.Focused {
bColor = lipgloss.Color("#8909FF")
bColor = m.ctx.Theme.BordersColorActive
}

styleBorders := m.ctx.Style.Borders.Copy().
BorderForeground(bColor)

return lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(bColor).
BorderRight(true).
BorderBottom(true).
BorderTop(true).
BorderLeft(true).
Inherit(styleBorders).
Render(
s.String(),
)
Expand Down

0 comments on commit b8a95ff

Please sign in to comment.