diff --git a/_examples/bulletlist/demo/main.go b/_examples/bulletlist/demo/main.go index ef3b781c4..c8ac041df 100644 --- a/_examples/bulletlist/demo/main.go +++ b/_examples/bulletlist/demo/main.go @@ -1,6 +1,9 @@ package main -import "github.com/pterm/pterm" +import ( + "github.com/pterm/pterm" + "github.com/pterm/pterm/putils" +) func main() { // Print a list with different levels. @@ -12,7 +15,7 @@ func main() { }).Render() // Convert a text to a list and print it. - pterm.NewBulletListFromString(`0 + putils.NewBulletListFromString(`0 1 2 3`, " ").Render() diff --git a/_examples/demo/demo/main.go b/_examples/demo/demo/main.go index 739c4c29b..7e96b2c94 100644 --- a/_examples/demo/demo/main.go +++ b/_examples/demo/demo/main.go @@ -67,8 +67,8 @@ func main() { pterm.Println() area, _ := pterm.DefaultArea.WithCenter().Start() // Start the Area printer, with the Center option. for i := 0; i < 10; i++ { - str, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(time.Now().Format("15:04:05"))).Srender() // Save current time in str. - area.Update(str) // Update Area contents. + str, _ := pterm.DefaultBigText.WithLetters(putils.NewLettersFromString(time.Now().Format("15:04:05"))).Srender() // Save current time in str. + area.Update(str) // Update Area contents. time.Sleep(time.Second) } area.Stop() diff --git a/bulletlist_printer.go b/bulletlist_printer.go index 80e28a701..ed997aa54 100644 --- a/bulletlist_printer.go +++ b/bulletlist_printer.go @@ -3,28 +3,8 @@ package pterm import ( "io" "strings" - - "github.com/pterm/pterm/internal" ) -// NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method. -func NewBulletListFromStrings(s []string, padding string) BulletListPrinter { - var lis []BulletListItem - for _, line := range s { - lis = append(lis, NewBulletListItemFromString(line, padding)) - } - return *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) BulletListItem { - s, l := internal.RemoveAndCountPrefix(text, padding) - return BulletListItem{ - Level: l, - Text: s, - } -} - // BulletListItem is able to render a ListItem. type BulletListItem struct { Level int @@ -64,11 +44,6 @@ func (p BulletListItem) WithBulletStyle(style *Style) *BulletListItem { return &p } -// NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n). -func NewBulletListFromString(s string, padding string) BulletListPrinter { - return NewBulletListFromStrings(strings.Split(s, "\n"), padding) -} - // DefaultBulletList contains standards, which can be used to print a BulletListPrinter. var DefaultBulletList = BulletListPrinter{ Bullet: "•", diff --git a/deprecated.go b/deprecated.go index 61a4f8977..d9301fa81 100644 --- a/deprecated.go +++ b/deprecated.go @@ -1,6 +1,10 @@ package pterm -import "strings" +import ( + "strings" + + "github.com/pterm/pterm/internal" +) // NewLettersFromString creates a Letters object from a string, which is prefilled with the LetterStyle from ThemeDefault. // You can override the ThemeDefault LetterStyle if you want to. @@ -44,3 +48,32 @@ func NewLettersFromStringWithRGB(text string, rgb RGB) Letters { return l } + +// NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method. +// +// Deprecated: use putils.NewBulletListFromStrings instead. +func NewBulletListFromStrings(s []string, padding string) BulletListPrinter { + var lis []BulletListItem + for _, line := range s { + lis = append(lis, NewBulletListItemFromString(line, padding)) + } + return *DefaultBulletList.WithItems(lis) +} + +// NewBulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem. +// +// Deprecated: use putils.NewBulletListItemFromString instead. +func NewBulletListItemFromString(text string, padding string) BulletListItem { + s, l := internal.RemoveAndCountPrefix(text, padding) + return BulletListItem{ + Level: l, + Text: s, + } +} + +// NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n). +// +// Deprecated: use putils.NewBulletListFromString instead. +func NewBulletListFromString(s string, padding string) BulletListPrinter { + return NewBulletListFromStrings(strings.Split(s, "\n"), padding) +} diff --git a/putils/new_bullet_list.go b/putils/new_bullet_list.go new file mode 100644 index 000000000..740006f64 --- /dev/null +++ b/putils/new_bullet_list.go @@ -0,0 +1,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) +}