Repository: pterm/pterm
Pull request #94 (2020-10-27 12:02:46)

feat: add tree list
### Description
add a tree list printer

### Scope
> What is affected by this pull request?

- [ ] Bug Fix
- [x] New Feature
- [ ] Documentation
- [x] Other

### Related Issue
Fixes #


### To-Do Checklist
- [ ] I tested my changes
- [ ] I have commented every method that I created/changed
- [ ] I updated the examples to fit with my changes
- [ ] I have added tests for my newly created methods



Patch:
diff --git a/_examples/bulletlist/main.go b/_examples/bulletlist/main.go
index 150bf7b7..ef3b781c 100644
--- a/_examples/bulletlist/main.go
+++ b/_examples/bulletlist/main.go
@@ -12,7 +12,7 @@ func main() {
 	}).Render()
 
 	// Convert a text to a list and print it.
-	pterm.NewListFromString(`0
+	pterm.NewBulletListFromString(`0
  1
   2
    3`, " ").Render()
diff --git a/_examples/demo/main.go b/_examples/demo/main.go
index b9e1d62f..5a689e10 100644
--- a/_examples/demo/main.go
+++ b/_examples/demo/main.go
@@ -51,7 +51,7 @@ func installingPseudoList() {
 }
 
 func listPrinter() {
-	pterm.NewListFromString(`Good bye
+	pterm.NewBulletListFromString(`Good bye
  Have a nice day!`, " ").Render()
 }
 
diff --git a/bulletlist_printer.go b/bulletlist_printer.go
index d38979da..e0089ea9 100644
--- a/bulletlist_printer.go
+++ b/bulletlist_printer.go
@@ -6,17 +6,17 @@ import (
 	"github.com/pterm/pterm/internal"
 )
 
-// NewListFromStrings returns a BulletList with Text using the NewListItemFromString method.
-func NewListFromStrings(s []string, padding string) BulletList {
+// NewBulletListFromStrings returns a BulletList with Text using the NewTreeListItemFromString method.
+func NewBulletListFromStrings(s []string, padding string) BulletList {
 	var lis []BulletListItem
 	for _, line := range s {
-		lis = append(lis, NewListItemFromString(line, padding))
+		lis = append(lis, NewBulletListItemFromString(line, padding))
 	}
 	return *DefaultBulletList.WithItems(lis)
 }
 
-// NewListItemFromString returns a ListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
-func NewListItemFromString(text string, padding string) BulletListItem {
+// NewBulletListItemFromString returns a ListItem 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,
@@ -86,9 +86,9 @@ func (p BulletListItem) Srender() string {
 	return strings.Repeat(" ", p.Level) + p.BulletStyle.Sprint(p.Bullet) + " " + p.TextStyle.Sprint(p.Text)
 }
 
-// NewListFromString returns a BulletList with Text using the NewListItemFromString method, splitting after return (\n).
-func NewListFromString(s string, padding string) BulletList {
-	return NewListFromStrings(strings.Split(s, "\n"), padding)
+// NewBulletListFromString returns a BulletList with Text using the NewTreeListItemFromString method, splitting after return (\n).
+func NewBulletListFromString(s string, padding string) BulletList {
+	return NewBulletListFromStrings(strings.Split(s, "\n"), padding)
 }
 
 // DefaultBulletList contains standards, which can be used to print a BulletList.


Test patch:
diff --git a/bulletlist_printer_test.go b/bulletlist_printer_test.go
index c2aaf81b..23dcdde2 100644
--- a/bulletlist_printer_test.go
+++ b/bulletlist_printer_test.go
@@ -10,7 +10,7 @@ import (
 	"github.com/pterm/pterm/internal"
 )
 
-func TestListPrinterNilPrint(t *testing.T) {
+func TestBulletListPrinterNilPrint(t *testing.T) {
 	p := BulletList{}
 	p.Render()
 }
@@ -84,19 +84,19 @@ func TestBulletList_WithTextStyle(t *testing.T) {
 	assert.Empty(t, p.TextStyle)
 }
 
-func TestListItem_Render(t *testing.T) {
+func TestBulletListItem_Render(t *testing.T) {
 	internal.TestPrintContains(t, func(w io.Writer, a interface{}) {
 		DefaultListItem.WithText(fmt.Sprint(a)).Render()
 	})
 }
 
-func TestListItem_Srender(t *testing.T) {
+func TestBulletListItem_Srender(t *testing.T) {
 	internal.TestSprintContains(t, func(a interface{}) string {
 		return DefaultListItem.WithText(fmt.Sprint(a)).Srender()
 	})
 }
 
-func TestListItem_WithBullet(t *testing.T) {
+func TestBulletListItem_WithBullet(t *testing.T) {
 	p := BulletListItem{}
 	p2 := p.WithBullet("-")
 
@@ -104,7 +104,7 @@ func TestListItem_WithBullet(t *testing.T) {
 	assert.Empty(t, p.Bullet)
 }
 
-func TestListItem_WithBulletStyle(t *testing.T) {
+func TestBulletListItem_WithBulletStyle(t *testing.T) {
 	p := BulletListItem{}
 	s := NewStyle(FgRed, BgRed, Bold)
 	p2 := p.WithBulletStyle(s)
@@ -113,7 +113,7 @@ func TestListItem_WithBulletStyle(t *testing.T) {
 	assert.Empty(t, p.BulletStyle)
 }
 
-func TestListItem_WithLevel(t *testing.T) {
+func TestBulletListItem_WithLevel(t *testing.T) {
 	p := BulletListItem{}
 	p2 := p.WithLevel(1)
 
@@ -121,7 +121,7 @@ func TestListItem_WithLevel(t *testing.T) {
 	assert.Empty(t, p.Level)
 }
 
-func TestListItem_WithText(t *testing.T) {
+func TestBulletListItem_WithText(t *testing.T) {
 	p := BulletListItem{}
 	p2 := p.WithText("test")
 
@@ -129,7 +129,7 @@ func TestListItem_WithText(t *testing.T) {
 	assert.Empty(t, p.Text)
 }
 
-func TestListItem_WithTextStyle(t *testing.T) {
+func TestBulletListItem_WithTextStyle(t *testing.T) {
 	p := BulletListItem{}
 	s := NewStyle(FgRed, BgRed, Bold)
 	p2 := p.WithTextStyle(s)
@@ -138,7 +138,7 @@ func TestListItem_WithTextStyle(t *testing.T) {
 	assert.Empty(t, p.TextStyle)
 }
 
-func TestNewListFromString(t *testing.T) {
+func TestNewBulletListFromString(t *testing.T) {
 	p := *DefaultBulletList.WithItems([]BulletListItem{
 		{Level: 0, Text: "0"},
 		{Level: 1, Text: "1"},
@@ -154,7 +154,7 @@ func TestNewListFromString(t *testing.T) {
    3
     4
      5`
-	p2 := NewListFromString(s, " ")
+	p2 := NewBulletListFromString(s, " ")
 
 	assert.Equal(t, p, p2)
 }