Skip to content

Commit 898721a

Browse files
committed
moved NewBulletListXxx to putils
1 parent f5fe5e7 commit 898721a

File tree

5 files changed

+72
-30
lines changed

5 files changed

+72
-30
lines changed

_examples/bulletlist/demo/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

3-
import "github.com/pterm/pterm"
3+
import (
4+
"github.com/pterm/pterm"
5+
"github.com/pterm/pterm/putils"
6+
)
47

58
func main() {
69
// Print a list with different levels.
@@ -12,7 +15,7 @@ func main() {
1215
}).Render()
1316

1417
// Convert a text to a list and print it.
15-
pterm.NewBulletListFromString(`0
18+
putils.NewBulletListFromString(`0
1619
1
1720
2
1821
3`, " ").Render()

_examples/demo/demo/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func main() {
6767
pterm.Println()
6868
area, _ := pterm.DefaultArea.WithCenter().Start() // Start the Area printer, with the Center option.
6969
for i := 0; i < 10; i++ {
70-
str, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(time.Now().Format("15:04:05"))).Srender() // Save current time in str.
71-
area.Update(str) // Update Area contents.
70+
str, _ := pterm.DefaultBigText.WithLetters(putils.NewLettersFromString(time.Now().Format("15:04:05"))).Srender() // Save current time in str.
71+
area.Update(str) // Update Area contents.
7272
time.Sleep(time.Second)
7373
}
7474
area.Stop()

bulletlist_printer.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,8 @@ package pterm
33
import (
44
"io"
55
"strings"
6-
7-
"github.com/pterm/pterm/internal"
86
)
97

10-
// NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.
11-
func NewBulletListFromStrings(s []string, padding string) BulletListPrinter {
12-
var lis []BulletListItem
13-
for _, line := range s {
14-
lis = append(lis, NewBulletListItemFromString(line, padding))
15-
}
16-
return *DefaultBulletList.WithItems(lis)
17-
}
18-
19-
// NewBulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
20-
func NewBulletListItemFromString(text string, padding string) BulletListItem {
21-
s, l := internal.RemoveAndCountPrefix(text, padding)
22-
return BulletListItem{
23-
Level: l,
24-
Text: s,
25-
}
26-
}
27-
288
// BulletListItem is able to render a ListItem.
299
type BulletListItem struct {
3010
Level int
@@ -64,11 +44,6 @@ func (p BulletListItem) WithBulletStyle(style *Style) *BulletListItem {
6444
return &p
6545
}
6646

67-
// NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).
68-
func NewBulletListFromString(s string, padding string) BulletListPrinter {
69-
return NewBulletListFromStrings(strings.Split(s, "\n"), padding)
70-
}
71-
7247
// DefaultBulletList contains standards, which can be used to print a BulletListPrinter.
7348
var DefaultBulletList = BulletListPrinter{
7449
Bullet: "•",

deprecated.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package pterm
22

3-
import "strings"
3+
import (
4+
"strings"
5+
6+
"github.com/pterm/pterm/internal"
7+
)
48

59
// NewLettersFromString creates a Letters object from a string, which is prefilled with the LetterStyle from ThemeDefault.
610
// You can override the ThemeDefault LetterStyle if you want to.
@@ -44,3 +48,32 @@ func NewLettersFromStringWithRGB(text string, rgb RGB) Letters {
4448

4549
return l
4650
}
51+
52+
// NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.
53+
//
54+
// Deprecated: use putils.NewBulletListFromStrings instead.
55+
func NewBulletListFromStrings(s []string, padding string) BulletListPrinter {
56+
var lis []BulletListItem
57+
for _, line := range s {
58+
lis = append(lis, NewBulletListItemFromString(line, padding))
59+
}
60+
return *DefaultBulletList.WithItems(lis)
61+
}
62+
63+
// NewBulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
64+
//
65+
// Deprecated: use putils.NewBulletListItemFromString instead.
66+
func NewBulletListItemFromString(text string, padding string) BulletListItem {
67+
s, l := internal.RemoveAndCountPrefix(text, padding)
68+
return BulletListItem{
69+
Level: l,
70+
Text: s,
71+
}
72+
}
73+
74+
// NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).
75+
//
76+
// Deprecated: use putils.NewBulletListFromString instead.
77+
func NewBulletListFromString(s string, padding string) BulletListPrinter {
78+
return NewBulletListFromStrings(strings.Split(s, "\n"), padding)
79+
}

putils/new_bullet_list.go

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

0 commit comments

Comments
 (0)