Skip to content

Commit ba1b784

Browse files
srtaalejmwbrooks
andauthored
feat(style): add style.Separator for non ASCII em-dash (#430)
Co-authored-by: Michael Brooks <mbrooks@slack-corp.com>
1 parent cb30df8 commit ba1b784

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

internal/iostreams/forms.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func buildSelectForm(io *IOStreams, msg string, options []string, cfg SelectProm
9292
key := opt
9393
if cfg.Description != nil {
9494
if desc := style.RemoveEmoji(cfg.Description(opt, len(opts))); desc != "" {
95-
key = style.Bright(opt) + " — " + style.Secondary(desc)
95+
key = style.Bright(opt) + style.Separator() + style.Secondary(desc)
9696
}
9797
}
9898
opts = append(opts, huh.NewOption(key, opt))

internal/iostreams/forms_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestSelectForm(t *testing.T) {
195195
assert.Contains(t, view, "First letter")
196196
})
197197

198-
t.Run("descriptions use em-dash separator with lipgloss enabled", func(t *testing.T) {
198+
t.Run("descriptions use hyphen separator with lipgloss enabled", func(t *testing.T) {
199199
style.ToggleLipgloss(true)
200200
style.ToggleStyles(true)
201201
t.Cleanup(func() {
@@ -225,10 +225,10 @@ func TestSelectForm(t *testing.T) {
225225
f.Update(f.Init())
226226

227227
view := ansi.Strip(f.View())
228-
assert.Contains(t, view, " First letter")
228+
assert.Contains(t, view, " - First letter")
229229
})
230230

231-
t.Run("descriptions use em-dash separator without lipgloss", func(t *testing.T) {
231+
t.Run("descriptions use hyphen separator without lipgloss", func(t *testing.T) {
232232
var selected string
233233
options := []string{"Alpha", "Beta"}
234234
selectCfg := SelectPromptConfig{
@@ -243,7 +243,7 @@ func TestSelectForm(t *testing.T) {
243243
f.Update(f.Init())
244244

245245
view := ansi.Strip(f.View())
246-
assert.Contains(t, view, "Alpha First letter")
246+
assert.Contains(t, view, "Alpha - First letter")
247247
})
248248

249249
t.Run("page size sets field height", func(t *testing.T) {

internal/style/style.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ func Underline(text string) string {
273273
return render(lipgloss.NewStyle().Underline(true), text)
274274
}
275275

276+
func Separator() string {
277+
return " - "
278+
}
279+
276280
/*
277281
Lexical
278282
*/

internal/style/style_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func TestRemoveANSI(t *testing.T) {
5858
}
5959
}
6060

61+
func TestSeparator(t *testing.T) {
62+
assert.Equal(t, " - ", Separator())
63+
}
64+
6165
func TestRemoveEmoji(t *testing.T) {
6266
tests := map[string]struct {
6367
input string

0 commit comments

Comments
 (0)