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 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 PrintAverageExecutionTime(count int, f func(i int) error) 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 PrintAverageExecutionTime ¶ added in v0.12.29
PrintAverageExecutionTime times the average execution time of a function.
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.
Types ¶
This section is empty.