Skip to content

Commit

Permalink
expand color configuration to support bold and italics
Browse files Browse the repository at this point in the history
  • Loading branch information
kotajacob committed Feb 28, 2024
1 parent 6aaaa05 commit 5db1284
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased
### Added
- Change color configuration settings to general style configuration
- Add holiday display feature

## [0.2.0]
Expand Down
9 changes: 7 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
# ANSI 16 colors: "5", "9", "12" (numbers 0-15)
# ANSI 256 Colors: "86", "201", "202" (numbers 16-255)
# True Color (16,777,216 colors; 24-bit): "#0000FF", "#04B575", "#3C3C3C"
TodayColor = "2"
InactiveColor = "8"
TodayStyle.Color = "2"
TodayStyle.Bold = false
TodayStyle.Italic = false

InactiveStyle.Color = "8"
InactiveStyle.Bold = false
InactiveStyle.Italic = false

# We use one more padding on the left to account for the border around the
# preview window. Looks a bit unbalanced without it, but feel free to tweak as
Expand Down
26 changes: 22 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"os"

"github.com/BurntSushi/toml"
"github.com/charmbracelet/lipgloss"
gap "github.com/muesli/go-app-paths"
)

// Config represents the toml configuration file.
type Config struct {
TodayColor string
InactiveColor string
TodayStyle Style
InactiveStyle Style
NoteDir string
Editor string
LeftPadding int
Expand Down Expand Up @@ -43,6 +44,23 @@ type Config struct {
HolidayLists []string
}

// Style represents how a type of date should be displayed.
type Style struct {
Color string
Bold bool
Italic bool
}

// Export takes a base lipgloss.Style and makes the changes needed based on this configured Style.
func (s Style) Export(base lipgloss.Style) lipgloss.Style {
if s.Color != "" {
base = base.Foreground(lipgloss.Color(s.Color))
}
base = base.Bold(s.Bold)
base = base.Italic(s.Italic)
return base
}

// Control is a slice of strings representing the keys bound to a given action.
type Control []string

Expand All @@ -59,8 +77,8 @@ func (c Control) Contains(key string) bool {
// Default returns the default configuration.
func Default() *Config {
return &Config{
TodayColor: "2",
InactiveColor: "8",
TodayStyle: Style{Color: "2"},
InactiveStyle: Style{Color: "8"},
LeftPadding: 2,
RightPadding: 1,
NoteDir: "$HOME/.local/share/calendar",
Expand Down
36 changes: 30 additions & 6 deletions doc/calendar-config.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,50 @@ empty lines.

Default: none

# COLOR OPTIONS
# STYLE OPTIONS

Colors can be specified in a few different ways. Terminal support may vary. By
default, all colors are specified using ANSI 16 which has the best support.
The way days are displayed in calendar is quite customizable. If you would like
today's date to be bold or italicized instead of colored you can do that.

The colors themselves can be specified in a few different ways. Terminal
support may vary. By default, all colors are specified using ANSI 16 which has
the best support.
```
ANSI 16 colors: "5", "9", "12" (numbers 0-15)
ANSI 256 Colors: "86", "201", "202" (numbers 16-255)
True Color (16,777,216 colors; 24-bit): "#0000FF", "#04B575", "#3C3C3C"
```

*TodayColor*
*TodayStyle.Color*
Foreground color used for the current date.

Default: "2"

*InactiveColor*
*TodayStyle.Bold*
Display the current date as bold.

Default: false

*TodayStyle.Italic*
Display the current date with italics.

Default: false

*InactiveStyle.Color*
Foreground color used in inactive months.

Default: "8"

*InactiveStyle.Bold*
Display the inactive months as bold.

Default: false

*InactiveStyle.Italic*
Display the inactive months with italics.

Default: false

# SPACING OPTIONS

We use one more padding on the left to account for the border around the preview
Expand Down Expand Up @@ -190,7 +214,7 @@ https://github.com/charmbracelet/bubbletea/blob/94d6f5079e07301046e38f6c59cb286d

# SEE ALSO

*calendar-config*(5)
*calendar*(1)

# AUTHORS

Expand Down
22 changes: 5 additions & 17 deletions month/month.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ func (m Month) Update(msg tea.Msg) (Month, tea.Cmd) {
year := t.Year()
month := t.Month()
m.selected = time.Date(
year,
month,
day,
0,
0,
0,
0,
year, month, day, 0, 0, 0, 0,
m.date.Location(),
)
break
Expand Down Expand Up @@ -179,7 +173,7 @@ func (m Month) heading() string {
style := headingStyle.Copy()
if !date.SameMonth(m.date, m.selected) {
style.Inherit(
lipgloss.NewStyle().Foreground(lipgloss.Color(m.config.InactiveColor)),
m.config.InactiveStyle.Export(lipgloss.NewStyle()),
)
}
return style.Render(heading.String())
Expand All @@ -206,25 +200,19 @@ func (m Month) grid() string {
}
} else {
day = day.Inherit(
lipgloss.NewStyle().Foreground(lipgloss.Color(m.config.InactiveColor)),
m.config.InactiveStyle.Export(lipgloss.NewStyle()),
)
}
// Render holidays.
if h, ok := m.holidays.Match(time.Date(
m.date.Year(),
m.date.Month(),
i,
0,
0,
0,
0,
m.date.Year(), m.date.Month(), i, 0, 0, 0, 0,
m.date.Location(),
)); ok {
day = day.Copy().Foreground(lipgloss.Color(h.Color))
}
// Render today.
if date.SameMonth(m.date, m.today) && i == m.today.Day() {
day = day.Copy().Foreground(lipgloss.Color(m.config.TodayColor))
day = m.config.TodayStyle.Export(day.Copy())
}
b.WriteString(
day.Render(zone.Mark(
Expand Down

0 comments on commit 5db1284

Please sign in to comment.