Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from pterm/318-move-ptermnewbulletlistfromstr…
…ings-to-putils-package
- Loading branch information
Showing
5 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |