putils

package
v0.12.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 10 Imported by: 73

README

PUtils - PTerm Utils

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.\

You can read the documentation of this package here.

Feel free to contribute your utility functions via pull request!

Util Functions

func DefaultTableFromStructSlice(structSlice interface{}) *pterm.TablePrinter
func DownloadFileWithDefaultProgressbar(title, outputPath, url string, mode os.FileMode) error
func DownloadFileWithProgressbar(progressbar *pterm.ProgressbarPrinter, outputPath, url string, mode os.FileMode) 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

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

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

func DownloadFileWithDefaultProgressbar(title, outputPath, url string, mode os.FileMode) error

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

func PrintAverageExecutionTime(count int, f func(i int) error) error

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

func TableDataFromCSV(csv string) (td pterm.TableData)

TableDataFromCSV converts CSV data into pterm.TableData.

Usage:

pterm.DefaultTable.WithData(putils.TableDataFromCSV(csv)).Render()

func TableDataFromSeparatedValues added in v0.12.24

func TableDataFromSeparatedValues(text, valueSeparator, rowSeparator string) (td pterm.TableData)

TableDataFromSeparatedValues converts values, separated by separator, into pterm.TableData.

Usage:

pterm.DefaultTable.WithData(putils.TableDataFromCSV(csv)).Render()

func TableDataFromTSV added in v0.12.24

func TableDataFromTSV(csv string) (td pterm.TableData)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL