Skip to content

Commit

Permalink
Merge pull request #365 from pterm/318-move-ptermnewbulletlistfromstr…
Browse files Browse the repository at this point in the history
…ings-to-putils-package
  • Loading branch information
MarvinJWendt committed Jun 14, 2022
2 parents 3c43e98 + 9c08855 commit 6d8d9d2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 30 deletions.
7 changes: 5 additions & 2 deletions _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.
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions _examples/demo/demo/main.go
Expand Up @@ -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()
Expand Down
25 changes: 0 additions & 25 deletions bulletlist_printer.go
Expand Up @@ -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
Expand Down Expand Up @@ -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: "•",
Expand Down
35 changes: 34 additions & 1 deletion 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.
Expand Down Expand Up @@ -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)
}
31 changes: 31 additions & 0 deletions 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)
}

0 comments on commit 6d8d9d2

Please sign in to comment.