Skip to content

Commit 6b0c7fb

Browse files
committed
Added management for default style
To avoid repeated setting of the style in every keymap
1 parent 00a7ce4 commit 6b0c7fb

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

bubblehelp.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
package bubblehelp
33

44
import (
5-
"github.com/charmbracelet/bubbles/key"
6-
"github.com/charmbracelet/lipgloss"
75
"log"
86
"math"
97
"strings"
8+
9+
"github.com/charmbracelet/bubbles/key"
10+
"github.com/charmbracelet/lipgloss"
1011
)
1112

1213
var (
@@ -21,11 +22,36 @@ var (
2122

2223
// previousContext allows to reset the previous context.
2324
previousContext KeymapContext
25+
26+
// defaultStyle is used by defautl by all keymaps.
27+
defaultStyle Style
2428
)
2529

2630
// Init is the first function that needs to be called in the start of the app.
2731
func Init() {
2832
Contexts = make(map[KeymapContext]*Keymap)
33+
defaultStyle = Style{
34+
EssentialKey: lipgloss.NewStyle().
35+
Bold(true),
36+
EssentialKeyDescription: lipgloss.NewStyle().
37+
Italic(true),
38+
EssentialKeySeparator: lipgloss.NewStyle().
39+
Italic(true),
40+
EssentialKeySeparatorValue: " - ",
41+
EssentialColSeparator: lipgloss.NewStyle().
42+
Bold(true),
43+
EssentialColSeparatorValue: " • ",
44+
FullKey: lipgloss.NewStyle().
45+
Bold(true),
46+
FullKeyDescription: lipgloss.NewStyle().
47+
Italic(true),
48+
FullKeySeparator: lipgloss.NewStyle().
49+
Italic(true),
50+
FullKeySeparatorValue: " - ",
51+
FullColSeparator: lipgloss.NewStyle().
52+
Italic(true),
53+
FullColSeparatorValue: " ",
54+
}
2955
}
3056

3157
// RegisterContext allows to register a new Keymap context and link it with the given identifier.
@@ -195,3 +221,7 @@ func ViewEssential(keymap *Keymap, width int) string {
195221
AlignHorizontal(lipgloss.Center).
196222
Width(width).Render(b.String())
197223
}
224+
225+
func SetDefaultStyle(style Style) {
226+
defaultStyle = style
227+
}

type.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,7 @@ func NewKeymap(showAllColCount int) *Keymap {
5555
return &Keymap{
5656
Bindings: make([]Key, 0),
5757
ShowAllColumnCount: showAllColCount,
58-
Style: Style{
59-
EssentialKey: lipgloss.NewStyle().
60-
Bold(true),
61-
EssentialKeyDescription: lipgloss.NewStyle().
62-
Italic(true),
63-
EssentialKeySeparator: lipgloss.NewStyle().
64-
Italic(true),
65-
EssentialKeySeparatorValue: " - ",
66-
EssentialColSeparator: lipgloss.NewStyle().
67-
Bold(true),
68-
EssentialColSeparatorValue: " • ",
69-
FullKey: lipgloss.NewStyle().
70-
Bold(true),
71-
FullKeyDescription: lipgloss.NewStyle().
72-
Italic(true),
73-
FullKeySeparator: lipgloss.NewStyle().
74-
Italic(true),
75-
FullKeySeparatorValue: " - ",
76-
FullColSeparator: lipgloss.NewStyle().
77-
Italic(true),
78-
FullColSeparatorValue: " ",
79-
},
58+
Style: defaultStyle,
8059
}
8160
}
8261

0 commit comments

Comments
 (0)