prettyprint

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 2 Imported by: 11

README

Description

The prettyprint package provides utilities for formatting strings with ANSI color codes. It includes predefined icons for different message types and functions to format strings with foreground and background colors.

Key Features:

  • Foreground Color Formatting: Wraps a string in the ANSI color and ANSI reset codes, i.e. Cyan and Cyanf.
  • Background Color Formatting: Wraps a string in the ANSI color and ANSI reset codes, i.e. CyanBg and CyanBgf.
  • Predefined Icons: These icons can be used in front of text to provide better readability when writing to console or a log file.
  • Helper functions for using predefined icons and color coding them to common colors, i.e. Complete, Alert, and Fail.

Installation

prettyprint is available using the standard go get command.

Install by running:

go get github.com/engmtcdrm/go-prettyprint

Run tests by running:

go test github.com/engmtcdrm/go-prettyprint

Usage

Using the alias pp makes using the package less verbose.

import pp "github.com/engmtcdrm/go-prettyprint"

Index

Variables

var (
    // IconComplete is the icon for a completed message.
    IconComplete = "[✓] "

    // IconAlert is the icon for an alerted message.
    IconAlert = "[!] "

    // IconFailed is the icon for a failed message.
    IconFailed = "[✗] "

    // IconInfo is the icon for an informational message.
    IconInfo = "[i] "
)

func Alert

func Alert(msg string) string

Alert returns a string with a yellow exclamation icon and the given message.

func Black

func Black(a ...any) string

Black formats using the default formats for its operands and returns the resulting string with a black foreground. Spaces are added between operands when neither is a string.

func BlackBg

func BlackBg(a ...any) string

BlackBg formats using the default formats for its operands and returns the resulting string with a black background. Spaces are added between operands when neither is a string.

func BlackBgf

func BlackBgf(format string, a ...any) string

BlackBgf formats according to a format specifier and returns the resulting string with a black background.

func Blackf

func Blackf(format string, a ...any) string

Blackf formats according to a format specifier and returns the resulting string with a black foreground.

func Blue

func Blue(a ...any) string

Blue formats using the default formats for its operands and returns the resulting string with a blue foreground. Spaces are added between operands when neither is a string.

func BlueBg

func BlueBg(a ...any) string

BlueBg formats using the default formats for its operands and returns the resulting string with a blue background. Spaces are added between operands when neither is a string.

func BlueBgf

func BlueBgf(format string, a ...any) string

BlueBgf formats according to a format specifier and returns the resulting string with a blue background.

func Bluef

func Bluef(format string, a ...any) string

Bluef formats according to a format specifier and returns the resulting string with a blue foreground.

func Complete

func Complete(msg string) string

Complete returns a string with a green checkmark icon and the given message.

func Cyan

func Cyan(a ...any) string

Cyan formats using the default formats for its operands and returns the resulting string with a cyan foreground. Spaces are added between operands when neither is a string.

func CyanBg

func CyanBg(a ...any) string

CyanBg formats using the default formats for its operands and returns the resulting string with a cyan background. Spaces are added between operands when neither is a string.

func CyanBgf

func CyanBgf(format string, a ...any) string

CyanBgf formats according to a format specifier and returns the resulting string with a cyan background.

func Cyanf

func Cyanf(format string, a ...any) string

Cyanf formats according to a format specifier and returns the resulting string with a cyan foreground.

func Fail

func Fail(msg string) string

Fail returns a string with a red X icon and the given message.

func Green

func Green(a ...any) string

Green formats using the default formats for its operands and returns the resulting string with a green foreground. Spaces are added between operands when neither is a string.

func GreenBg

func GreenBg(a ...any) string

GreenBg formats using the default formats for its operands and returns the resulting string with a green background. Spaces are added between operands when neither is a string.

func GreenBgf

func GreenBgf(format string, a ...any) string

GreenBgf formats according to a format specifier and returns the resulting string with a green background.

func Greenf

func Greenf(format string, a ...any) string

Greenf formats according to a format specifier and returns the resulting string with a green foreground.

func Info

func Info(msg string) string

Info returns a string with a cyan info icon and the given message.

func Magenta

func Magenta(a ...any) string

Magenta formats using the default formats for its operands and returns the resulting string with a magenta foreground. Spaces are added between operands when neither is a string.

func MagentaBg

func MagentaBg(a ...any) string

MagentaBg formats using the default formats for its operands and returns the resulting string with a magenta background. Spaces are added between operands when neither is a string.

func MagentaBgf

func MagentaBgf(format string, a ...any) string

MagentaBgf formats according to a format specifier and returns the resulting string with a magenta background.

func Magentaf

func Magentaf(format string, a ...any) string

Magentaf formats according to a format specifier and returns the resulting string with a magenta foreground.

func Red

func Red(a ...any) string

Red formats using the default formats for its operands and returns the resulting string with a red foreground. Spaces are added between operands when neither is a string.

func RedAlert

func RedAlert(msg string) string

RedAlert returns a string with a red exclamation icon and the given message.

func RedBg

func RedBg(a ...any) string

RedBg formats using the default formats for its operands and returns the resulting string with a red background. Spaces are added between operands when neither is a string.

func RedBgf

func RedBgf(format string, a ...any) string

RedBgf formats according to a format specifier and returns the resulting string with a red background.

func Redf

func Redf(format string, a ...any) string

Redf formats according to a format specifier and returns the resulting string with a red foreground.

func Var

func Var(variable string, value string) string

Var returns a string with the given variable and value.

func VarQuote

func VarQuote(variable string, value string) string

VarQuote returns a string with the given variable and value, quoted.

func White

func White(a ...any) string

White formats using the default formats for its operands and returns the resulting string with a white foreground. Spaces are added between operands when neither is a string.

func WhiteBg

func WhiteBg(a ...any) string

WhiteBg formats using the default formats for its operands and returns the resulting string with a white background. Spaces are added between operands when neither is a string.

func WhiteBgf

func WhiteBgf(format string, a ...any) string

WhiteBgf formats according to a format specifier and returns the resulting string with a white background.

func Whitef

func Whitef(format string, a ...any) string

Whitef formats according to a format specifier and returns the resulting string with a white foreground.

func Yellow

func Yellow(a ...any) string

Yellow formats using the default formats for its operands and returns the resulting string with a yellow foreground. Spaces are added between operands when neither is a string.

func YellowBg

func YellowBg(a ...any) string

YellowBg formats using the default formats for its operands and returns the resulting string with a yellow background. Spaces are added between operands when neither is a string.

func YellowBgf

func YellowBgf(format string, a ...any) string

YellowBgf formats according to a format specifier and returns the resulting string with a yellow background.

func Yellowf

func Yellowf(format string, a ...any) string

Yellowf formats according to a format specifier and returns the resulting string with a yellow foreground.

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// IconComplete is the icon for a completed message.
	IconComplete = "[✓] "

	// IconAlert is the icon for an alerted message.
	IconAlert = "[!] "

	// IconFailed is the icon for a failed message.
	IconFailed = "[✗] "

	// IconInfo is the icon for an informational message.
	IconInfo = "[i] "
)

Functions

func Alert

func Alert(msg string) string

Alert returns a string with a yellow exclamation icon and the given message.

func Black

func Black(a ...any) string

Black formats using the default formats for its operands and returns the resulting string with a black foreground. Spaces are added between operands when neither is a string.

func BlackBg added in v1.1.0

func BlackBg(a ...any) string

BlackBg formats using the default formats for its operands and returns the resulting string with a black background. Spaces are added between operands when neither is a string.

func BlackBgf added in v1.1.0

func BlackBgf(format string, a ...any) string

BlackBgf formats according to a format specifier and returns the resulting string with a black background.

func Blackf

func Blackf(format string, a ...any) string

Blackf formats according to a format specifier and returns the resulting string with a black foreground.

func Blue

func Blue(a ...any) string

Blue formats using the default formats for its operands and returns the resulting string with a blue foreground. Spaces are added between operands when neither is a string.

func BlueBg added in v1.1.0

func BlueBg(a ...any) string

BlueBg formats using the default formats for its operands and returns the resulting string with a blue background. Spaces are added between operands when neither is a string.

func BlueBgf added in v1.1.0

func BlueBgf(format string, a ...any) string

BlueBgf formats according to a format specifier and returns the resulting string with a blue background.

func Bluef

func Bluef(format string, a ...any) string

Bluef formats according to a format specifier and returns the resulting string with a blue foreground.

func Complete

func Complete(msg string) string

Complete returns a string with a green checkmark icon and the given message.

func Cyan

func Cyan(a ...any) string

Cyan formats using the default formats for its operands and returns the resulting string with a cyan foreground. Spaces are added between operands when neither is a string.

func CyanBg added in v1.1.0

func CyanBg(a ...any) string

CyanBg formats using the default formats for its operands and returns the resulting string with a cyan background. Spaces are added between operands when neither is a string.

func CyanBgf added in v1.1.0

func CyanBgf(format string, a ...any) string

CyanBgf formats according to a format specifier and returns the resulting string with a cyan background.

func Cyanf

func Cyanf(format string, a ...any) string

Cyanf formats according to a format specifier and returns the resulting string with a cyan foreground.

func Fail

func Fail(msg string) string

Fail returns a string with a red X icon and the given message.

func Green

func Green(a ...any) string

Green formats using the default formats for its operands and returns the resulting string with a green foreground. Spaces are added between operands when neither is a string.

func GreenBg added in v1.1.0

func GreenBg(a ...any) string

GreenBg formats using the default formats for its operands and returns the resulting string with a green background. Spaces are added between operands when neither is a string.

func GreenBgf added in v1.1.0

func GreenBgf(format string, a ...any) string

GreenBgf formats according to a format specifier and returns the resulting string with a green background.

func Greenf

func Greenf(format string, a ...any) string

Greenf formats according to a format specifier and returns the resulting string with a green foreground.

func Info

func Info(msg string) string

Info returns a string with a cyan info icon and the given message.

func Magenta

func Magenta(a ...any) string

Magenta formats using the default formats for its operands and returns the resulting string with a magenta foreground. Spaces are added between operands when neither is a string.

func MagentaBg added in v1.1.0

func MagentaBg(a ...any) string

MagentaBg formats using the default formats for its operands and returns the resulting string with a magenta background. Spaces are added between operands when neither is a string.

func MagentaBgf added in v1.1.0

func MagentaBgf(format string, a ...any) string

MagentaBgf formats according to a format specifier and returns the resulting string with a magenta background.

func Magentaf

func Magentaf(format string, a ...any) string

Magentaf formats according to a format specifier and returns the resulting string with a magenta foreground.

func Red

func Red(a ...any) string

Red formats using the default formats for its operands and returns the resulting string with a red foreground. Spaces are added between operands when neither is a string.

func RedAlert

func RedAlert(msg string) string

RedAlert returns a string with a red exclamation icon and the given message.

func RedBg added in v1.1.0

func RedBg(a ...any) string

RedBg formats using the default formats for its operands and returns the resulting string with a red background. Spaces are added between operands when neither is a string.

func RedBgf added in v1.1.0

func RedBgf(format string, a ...any) string

RedBgf formats according to a format specifier and returns the resulting string with a red background.

func Redf

func Redf(format string, a ...any) string

Redf formats according to a format specifier and returns the resulting string with a red foreground.

func Var

func Var(variable string, value string) string

Var returns a string with the given variable and value.

func VarQuote

func VarQuote(variable string, value string) string

VarQuote returns a string with the given variable and value, quoted.

func White

func White(a ...any) string

White formats using the default formats for its operands and returns the resulting string with a white foreground. Spaces are added between operands when neither is a string.

func WhiteBg added in v1.1.0

func WhiteBg(a ...any) string

WhiteBg formats using the default formats for its operands and returns the resulting string with a white background. Spaces are added between operands when neither is a string.

func WhiteBgf added in v1.1.0

func WhiteBgf(format string, a ...any) string

WhiteBgf formats according to a format specifier and returns the resulting string with a white background.

func Whitef

func Whitef(format string, a ...any) string

Whitef formats according to a format specifier and returns the resulting string with a white foreground.

func Yellow

func Yellow(a ...any) string

Yellow formats using the default formats for its operands and returns the resulting string with a yellow foreground. Spaces are added between operands when neither is a string.

func YellowBg added in v1.1.0

func YellowBg(a ...any) string

YellowBg formats using the default formats for its operands and returns the resulting string with a yellow background. Spaces are added between operands when neither is a string.

func YellowBgf added in v1.1.0

func YellowBgf(format string, a ...any) string

YellowBgf formats according to a format specifier and returns the resulting string with a yellow background.

func Yellowf

func Yellowf(format string, a ...any) string

Yellowf formats according to a format specifier and returns the resulting string with a yellow foreground.

Types

This section is empty.

Jump to

Keyboard shortcuts

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