Skip to content

Commit 3032b7c

Browse files
committed
Add custom headline style support
Add `HeadlineStyle` function to apply a custom style to the headline.
1 parent 6793dc8 commit 3032b7c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

box.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ import (
3434
type BoxStyle func(*boxOptions)
3535

3636
type boxOptions struct {
37-
headlineColor *colorful.Color
38-
contentColor *colorful.Color
37+
headlineColor *colorful.Color
38+
contentColor *colorful.Color
39+
headlineStyles []bunt.StyleOption
3940
}
4041

4142
// HeadlineColor sets the color of the headline text
@@ -45,6 +46,13 @@ func HeadlineColor(color colorful.Color) BoxStyle {
4546
}
4647
}
4748

49+
// HeadlineStyle sets the style to be used for the headline text
50+
func HeadlineStyle(style bunt.StyleOption) BoxStyle {
51+
return func(options *boxOptions) {
52+
options.headlineStyles = append(options.headlineStyles, style)
53+
}
54+
}
55+
4856
// ContentColor sets the color of the content text
4957
func ContentColor(color colorful.Color) BoxStyle {
5058
return func(options *boxOptions) {
@@ -87,6 +95,10 @@ func ContentBox(headline string, content string, opts ...BoxStyle) string {
8795
}
8896
}
8997

98+
for _, style := range options.headlineStyles {
99+
headline = bunt.Style(headline, style)
100+
}
101+
90102
var buf buntBuffer
91103
buf.Write("%s %s\n", beginning, headline)
92104

box_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ content
5858
`)))
5959
})
6060

61+
It("should create a simply styled content box with bold headline", func() {
62+
Expect("\n" + ContentBox(headline, content,
63+
HeadlineStyle(Bold()),
64+
)).To(BeEquivalentTo(Sprintf(`
65+
╭ *headline*
66+
│ multi
67+
│ line
68+
│ content
69+
70+
`)))
71+
})
72+
73+
It("should create a simply styled content box with italic, underline, and bold headline", func() {
74+
Expect("\n" + ContentBox(headline, content,
75+
HeadlineStyle(Italic()),
76+
HeadlineStyle(Underline()),
77+
HeadlineStyle(Bold()),
78+
)).To(BeEquivalentTo(Sprintf(`
79+
╭ _*~headline~*_
80+
│ multi
81+
│ line
82+
│ content
83+
84+
`)))
85+
})
86+
6187
It("should create styled content box with headline colors", func() {
6288
Expect("\n" + ContentBox(headline, content,
6389
HeadlineColor(DodgerBlue),

0 commit comments

Comments
 (0)