/
new_bullet_list.go
31 lines (26 loc) · 1.07 KB
/
new_bullet_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package putils
import (
"strings"
"github.com/pterm/pterm"
"github.com/pterm/pterm/internal"
)
// NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.
func NewBulletListFromStrings(s []string, padding string) pterm.BulletListPrinter {
var lis []pterm.BulletListItem
for _, line := range s {
lis = append(lis, NewBulletListItemFromString(line, padding))
}
return *pterm.DefaultBulletList.WithItems(lis)
}
// NewBulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
func NewBulletListItemFromString(text string, padding string) pterm.BulletListItem {
s, l := internal.RemoveAndCountPrefix(text, padding)
return pterm.BulletListItem{
Level: l,
Text: s,
}
}
// NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).
func NewBulletListFromString(s string, padding string) pterm.BulletListPrinter {
return NewBulletListFromStrings(strings.Split(s, "\n"), padding)
}