putils

package
v0.12.71 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 11 Imported by: 103

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 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, mode os.FileMode) 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

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

func CenterText(text string) string

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

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 LettersFromString added in v0.12.42

func LettersFromString(text string) pterm.Letters

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

func LettersFromStringWithRGB(text string, rgb pterm.RGB) pterm.Letters

LettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it (overwrites style).

func LettersFromStringWithStyle added in v0.12.42

func LettersFromStringWithStyle(text string, style *pterm.Style) pterm.Letters

LettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.

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 RGBFromHEX added in v0.12.42

func RGBFromHEX(hex string) (pterm.RGB, error)

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

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.

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.

Jump to

Keyboard shortcuts

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