File: bullet_list.go

package info (click to toggle)
golang-github-pterm-pterm 0.12.79-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,640 kB
  • sloc: makefile: 4
file content (31 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download
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)
}