Skip to content

Commit

Permalink
feat: add option for choosing border style
Browse files Browse the repository at this point in the history
border style can be changed in the settings

Signed-off-by: moson-mo <mo-son@mailbox.org>
  • Loading branch information
moson-mo committed Jul 27, 2022
1 parent fe79c72 commit 2f8e7b3
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
112 changes: 112 additions & 0 deletions internal/config/borders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package config

import "github.com/rivo/tview"

// Borders contains all border elements of our border style
type Borders struct {
Horizontal rune
Vertical rune
TopLeft rune
TopRight rune
BottomLeft rune
BottomRight rune

HorizontalFocus rune
VerticalFocus rune
TopLeftFocus rune
TopRightFocus rune
BottomLeftFocus rune
BottomRightFocus rune
}

// default scheme
const (
defaultBorderStyle = "Double"
)

// border style definitions
var (
borderStyles = map[string]Borders{
"Double": {
Horizontal: tview.BoxDrawingsLightHorizontal,
Vertical: tview.BoxDrawingsLightVertical,
TopLeft: tview.BoxDrawingsLightDownAndRight,
TopRight: tview.BoxDrawingsLightDownAndLeft,
BottomLeft: tview.BoxDrawingsLightUpAndRight,
BottomRight: tview.BoxDrawingsLightUpAndLeft,

HorizontalFocus: tview.BoxDrawingsDoubleHorizontal,
VerticalFocus: tview.BoxDrawingsDoubleVertical,
TopLeftFocus: tview.BoxDrawingsDoubleDownAndRight,
TopRightFocus: tview.BoxDrawingsDoubleDownAndLeft,
BottomLeftFocus: tview.BoxDrawingsDoubleUpAndRight,
BottomRightFocus: tview.BoxDrawingsDoubleUpAndLeft,
},
"Thick": {
Horizontal: tview.BoxDrawingsLightHorizontal,
Vertical: tview.BoxDrawingsLightVertical,
TopLeft: tview.BoxDrawingsLightDownAndRight,
TopRight: tview.BoxDrawingsLightDownAndLeft,
BottomLeft: tview.BoxDrawingsLightUpAndRight,
BottomRight: tview.BoxDrawingsLightUpAndLeft,

HorizontalFocus: tview.BoxDrawingsHeavyHorizontal,
VerticalFocus: tview.BoxDrawingsHeavyVertical,
TopLeftFocus: tview.BoxDrawingsHeavyDownAndRight,
TopRightFocus: tview.BoxDrawingsHeavyDownAndLeft,
BottomLeftFocus: tview.BoxDrawingsHeavyUpAndRight,
BottomRightFocus: tview.BoxDrawingsHeavyUpAndLeft,
},
"Single": {
Horizontal: tview.BoxDrawingsLightHorizontal,
Vertical: tview.BoxDrawingsLightVertical,
TopLeft: tview.BoxDrawingsLightDownAndRight,
TopRight: tview.BoxDrawingsLightDownAndLeft,
BottomLeft: tview.BoxDrawingsLightUpAndRight,
BottomRight: tview.BoxDrawingsLightUpAndLeft,

HorizontalFocus: tview.BoxDrawingsLightHorizontal,
VerticalFocus: tview.BoxDrawingsLightVertical,
TopLeftFocus: tview.BoxDrawingsLightDownAndRight,
TopRightFocus: tview.BoxDrawingsLightDownAndLeft,
BottomLeftFocus: tview.BoxDrawingsLightUpAndRight,
BottomRightFocus: tview.BoxDrawingsLightUpAndLeft,
},
"Round": {
Horizontal: tview.BoxDrawingsLightHorizontal,
Vertical: tview.BoxDrawingsLightVertical,
TopLeft: tview.BoxDrawingsLightArcDownAndRight,
TopRight: tview.BoxDrawingsLightArcDownAndLeft,
BottomLeft: tview.BoxDrawingsLightArcUpAndRight,
BottomRight: tview.BoxDrawingsLightArcUpAndLeft,

HorizontalFocus: tview.BoxDrawingsLightHorizontal,
VerticalFocus: tview.BoxDrawingsLightVertical,
TopLeftFocus: tview.BoxDrawingsLightArcDownAndRight,
TopRightFocus: tview.BoxDrawingsLightArcDownAndLeft,
BottomLeftFocus: tview.BoxDrawingsLightArcUpAndRight,
BottomRightFocus: tview.BoxDrawingsLightArcUpAndLeft,
},
}
)

func (s *Settings) SetBorderStyle(style string) {
tview.Borders.Horizontal = borderStyles[style].Horizontal
tview.Borders.Vertical = borderStyles[style].Vertical
tview.Borders.TopLeft = borderStyles[style].TopLeft
tview.Borders.TopRight = borderStyles[style].TopRight
tview.Borders.BottomLeft = borderStyles[style].BottomLeft
tview.Borders.BottomRight = borderStyles[style].BottomRight

tview.Borders.HorizontalFocus = borderStyles[style].HorizontalFocus
tview.Borders.VerticalFocus = borderStyles[style].VerticalFocus
tview.Borders.TopLeftFocus = borderStyles[style].TopLeftFocus
tview.Borders.TopRightFocus = borderStyles[style].TopRightFocus
tview.Borders.BottomLeftFocus = borderStyles[style].BottomLeftFocus
tview.Borders.BottomRightFocus = borderStyles[style].BottomRightFocus
}

// Returns all available border styles
func BorderStyles() []string {
return []string{"Double", "Thick", "Single", "Round"}
}
9 changes: 9 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Settings struct {
CacheExpiry int
DisableCache bool
ColorScheme string
BorderStyle string
colors Colors
}

Expand All @@ -48,6 +49,7 @@ func Defaults() *Settings {
CacheExpiry: 5,
DisableCache: false,
ColorScheme: defaultColorScheme,
BorderStyle: "Double",
colors: colorSchemes[defaultColorScheme],
}

Expand Down Expand Up @@ -96,6 +98,7 @@ func Load() (*Settings, error) {
}
ret.applyUpgradeFixes()
ret.SetColorScheme(ret.ColorScheme)
ret.SetBorderStyle(ret.BorderStyle)
return &ret, nil
}

Expand Down Expand Up @@ -134,6 +137,12 @@ func (s *Settings) applyUpgradeFixes() {
fixApplied = true
}

// border style: added with 1.4.2
if s.BorderStyle == "" {
s.BorderStyle = "Double"
fixApplied = true
}

// save config file when we applied changes
if fixApplied {
s.Save()
Expand Down
10 changes: 10 additions & 0 deletions internal/pacseek/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (ps *UI) drawSettingsFields(disableAur, disableCache, separateAurCommands b
by = 1
}
cIndex := util.IndexOf(config.ColorSchemes(), ps.conf.ColorScheme)
bIndex := util.IndexOf(config.BorderStyles(), ps.conf.BorderStyle)

// handle text/drop-down field changes
sc := func(txt string) {
Expand All @@ -43,6 +44,15 @@ func (ps *UI) drawSettingsFields(disableAur, disableCache, separateAurCommands b
}
})
}
ps.settings.AddDropDown("Border style: ", config.BorderStyles(), bIndex, nil)
if dd, ok := ps.settings.GetFormItemByLabel("Border style: ").(*tview.DropDown); ok {
dd.SetSelectedFunc(func(text string, index int) {
ps.conf.SetBorderStyle(text)
if text != ps.conf.BorderStyle {
ps.settingsChanged = true
}
})
}
ps.settings.AddCheckbox("Disable AUR: ", disableAur, func(checked bool) {
ps.settingsChanged = true
ps.drawSettingsFields(checked, disableCache, separateAurCommands)
Expand Down
4 changes: 3 additions & 1 deletion internal/pacseek/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (ps *UI) setupColors() {

// apply drop-down colors
func (ps *UI) setupDropDownColors() {
for _, title := range []string{"Search mode: ", "Search by: ", "Color scheme: "} {
for _, title := range []string{"Search mode: ", "Search by: ", "Color scheme: ", "Border style: "} {
if dd, ok := ps.settings.GetFormItemByLabel(title).(*tview.DropDown); ok {
dd.SetListStyles(tcell.StyleDefault.Background(ps.conf.Colors().SettingsDropdownNotSelected).Foreground(ps.conf.Colors().SettingsFieldText),
tcell.StyleDefault.Background(ps.conf.Colors().SettingsFieldText).Foreground(ps.conf.Colors().SettingsDropdownNotSelected))
Expand Down Expand Up @@ -379,6 +379,8 @@ func (ps *UI) saveSettings(defaults bool) {
ps.conf.SearchBy = opt
case "Color scheme: ":
ps.conf.ColorScheme = opt
case "Border style: ":
ps.conf.BorderStyle = opt
}
} else if cb, ok := item.(*tview.Checkbox); ok {
switch cb.GetLabel() {
Expand Down

0 comments on commit 2f8e7b3

Please sign in to comment.