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"
)
// BulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.
func BulletListFromStrings(s []string, padding string) pterm.BulletListPrinter {
var lis []pterm.BulletListItem
for _, line := range s {
lis = append(lis, BulletListItemFromString(line, padding))
}
return *pterm.DefaultBulletList.WithItems(lis)
}
// BulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
func BulletListItemFromString(text string, padding string) pterm.BulletListItem {
s, l := internal.RemoveAndCountPrefix(text, padding)
return pterm.BulletListItem{
Level: l,
Text: s,
}
}
// BulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).
func BulletListFromString(s string, padding string) pterm.BulletListPrinter {
return BulletListFromStrings(strings.Split(s, "\n"), padding)
}
|