Documentation ¶
Overview ¶
Package putils contains utility functions for PTerm, to make it's usage even easier! It contains pre-made functions, that utilize PTerm, to print various stuff to the terminal. You can use PUtils, to simplify various scenarios for which PTerm is frequently used.
Index ¶
- func BulletListFromString(s string, padding string) pterm.BulletListPrinter
- func BulletListFromStrings(s []string, padding string) pterm.BulletListPrinter
- func BulletListItemFromString(text string, padding string) pterm.BulletListItem
- func CenterText(text string) string
- func DefaultTableFromStructSlice(structSlice interface{}) *pterm.TablePrinter
- func DownloadFileWithDefaultProgressbar(title, outputPath, url string, mode os.FileMode) error
- func DownloadFileWithProgressbar(progressbar *pterm.ProgressbarPrinter, outputPath, url string, ...) error
- func LettersFromString(text string) pterm.Letters
- func LettersFromStringWithRGB(text string, rgb pterm.RGB) pterm.Letters
- func LettersFromStringWithStyle(text string, style *pterm.Style) pterm.Letters
- func PrintAverageExecutionTime(count int, f func(i int) error) error
- func RGBFromHEX(hex string) (pterm.RGB, error)
- func RunWithDefaultSpinner(initzialSpinnerText string, f func(spinner *pterm.SpinnerPrinter) error) error
- func RunWithSpinner(spinner *pterm.SpinnerPrinter, f func(spinner *pterm.SpinnerPrinter) error) error
- func TableDataFromCSV(csv string) (td pterm.TableData)
- func TableDataFromSeparatedValues(text, valueSeparator, rowSeparator string) (td pterm.TableData)
- func TableDataFromTSV(csv string) (td pterm.TableData)
- func TableFromStructSlice(tablePrinter pterm.TablePrinter, structSlice interface{}) *pterm.TablePrinter
- func TreeFromLeveledList(leveledListItems pterm.LeveledList) pterm.TreeNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BulletListFromString ¶ added in v0.12.42
func BulletListFromString(s string, padding string) pterm.BulletListPrinter
BulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).
func BulletListFromStrings ¶ added in v0.12.42
func BulletListFromStrings(s []string, padding string) pterm.BulletListPrinter
BulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.
func BulletListItemFromString ¶ added in v0.12.42
func BulletListItemFromString(text string, padding string) pterm.BulletListItem
BulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
func CenterText ¶ added in v0.12.46
CenterText returns a centered string with each line centered in respect to the longest line.
func DefaultTableFromStructSlice ¶ added in v0.12.23
func DefaultTableFromStructSlice(structSlice interface{}) *pterm.TablePrinter
DefaultTableFromStructSlice will be populate the pterm.DefaultTable with the values of the structs. The header will be set to the structs field name. Use .WithHasHeader() to color the header. The function will return the populated pterm.TablePrinter.
func DownloadFileWithDefaultProgressbar ¶ added in v0.12.21
DownloadFileWithDefaultProgressbar downloads a file, by url, and writes it to outputPath. The download progress, will be reported via the default progressbar.
func DownloadFileWithProgressbar ¶ added in v0.12.21
func DownloadFileWithProgressbar(progressbar *pterm.ProgressbarPrinter, outputPath, url string, mode os.FileMode) error
DownloadFileWithProgressbar downloads a file, by url, and writes it to outputPath. The download progress, will be reported via a progressbar.
func LettersFromString ¶ added in v0.12.42
LettersFromString 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.
func LettersFromStringWithRGB ¶ added in v0.12.42
LettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it (overwrites style).
func LettersFromStringWithStyle ¶ added in v0.12.42
LettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.
func PrintAverageExecutionTime ¶ added in v0.12.29
PrintAverageExecutionTime times the average execution time of a function.
func RGBFromHEX ¶ added in v0.12.42
RGBFromHEX converts a HEX and returns a new RGB. If the hex code is not valid it returns pterm.ErrHexCodeIsInvalid.
func RunWithDefaultSpinner ¶
func RunWithDefaultSpinner(initzialSpinnerText string, f func(spinner *pterm.SpinnerPrinter) error) error
RunWithDefaultSpinner starts a default spinner, then runs a function and after the function is done, the spinner will stop again.
func RunWithSpinner ¶
func RunWithSpinner(spinner *pterm.SpinnerPrinter, f func(spinner *pterm.SpinnerPrinter) error) error
RunWithSpinner starts a spinner, then runs a function and after the function is done, the spinner will stop again.
func TableDataFromCSV ¶ added in v0.12.24
TableDataFromCSV converts CSV data into pterm.TableData.
Usage:
pterm.DefaultTable.WithData(putils.TableDataFromCSV(csv)).Render()
func TableDataFromSeparatedValues ¶ added in v0.12.24
TableDataFromSeparatedValues converts values, separated by separator, into pterm.TableData.
Usage:
pterm.DefaultTable.WithData(putils.TableDataFromCSV(csv)).Render()
func TableDataFromTSV ¶ added in v0.12.24
TableDataFromTSV converts TSV data into pterm.TableData.
Usage:
pterm.DefaultTable.WithData(putils.TableDataFromTSV(tsv)).Render()
func TableFromStructSlice ¶ added in v0.12.23
func TableFromStructSlice(tablePrinter pterm.TablePrinter, structSlice interface{}) *pterm.TablePrinter
TableFromStructSlice accepts a customized table printer and and a slice of a struct. The table will be populated with the values of the structs. The header will be set to the structs field name. Use .WithHasHeader() to color the header. The function will return the populated pterm.TablePrinter.
func TreeFromLeveledList ¶ added in v0.12.42
func TreeFromLeveledList(leveledListItems pterm.LeveledList) pterm.TreeNode
TreeFromLeveledList converts a TreeItems list to a TreeNode and returns it.
Types ¶
This section is empty.