Skip to content

Instantly share code, notes, and snippets.

@princjef
Last active June 12, 2021 18:12
Show Gist options
  • Save princjef/ba9265239132c477e438cabd55431186 to your computer and use it in GitHub Desktop.
Save princjef/ba9265239132c477e438cabd55431186 to your computer and use it in GitHub Desktop.
Output of running `gomarkdoc . > output.md` in the root of the github.com/pterm/pterm repository

pterm

import "github.com/pterm/pterm"

Package pterm is a modern go module to beautify console output. It can be used without configuration, but if desired, everything can be customized down to the smallest detail. View the animated examples here: https://github.com/pterm/pterm#-examples

Index

Variables

var (
    // Red is an alias for FgRed.Sprint.
    Red = FgRed.Sprint
    // Cyan is an alias for FgCyan.Sprint.
    Cyan = FgCyan.Sprint
    // Gray is an alias for FgGray.Sprint.
    Gray = FgGray.Sprint
    // Blue is an alias for FgBlue.Sprint.
    Blue = FgBlue.Sprint
    // Black is an alias for FgBlack.Sprint.
    Black = FgBlack.Sprint
    // Green is an alias for FgGreen.Sprint.
    Green = FgGreen.Sprint
    // White is an alias for FgWhite.Sprint.
    White = FgWhite.Sprint
    // Yellow is an alias for FgYellow.Sprint.
    Yellow = FgYellow.Sprint
    // Magenta is an alias for FgMagenta.Sprint.
    Magenta = FgMagenta.Sprint

    // Normal is an alias for FgDefault.Sprint.
    Normal = FgDefault.Sprint

    // LightRed is a shortcut for FgLightRed.Sprint.
    LightRed = FgLightRed.Sprint
    // LightCyan is a shortcut for FgLightCyan.Sprint.
    LightCyan = FgLightCyan.Sprint
    // LightBlue is a shortcut for FgLightBlue.Sprint.
    LightBlue = FgLightBlue.Sprint
    // LightGreen is a shortcut for FgLightGreen.Sprint.
    LightGreen = FgLightGreen.Sprint
    // LightWhite is a shortcut for FgLightWhite.Sprint.
    LightWhite = FgLightWhite.Sprint
    // LightYellow is a shortcut for FgLightYellow.Sprint.
    LightYellow = FgLightYellow.Sprint
    // LightMagenta is a shortcut for FgLightMagenta.Sprint.
    LightMagenta = FgLightMagenta.Sprint
)
var (
    // ErrTerminalSizeNotDetectable - the terminal size can not be detected and the fallback values are used.
    ErrTerminalSizeNotDetectable = errors.New("terminal size could not be detected - using fallback value")

    // ErrHexCodeIsInvalid - the given HEX code is invalid.
    ErrHexCodeIsInvalid = errors.New("hex code is not valid")
)
var (
    // Info returns a PrefixPrinter, which can be used to print text with an "info" Prefix.
    Info = PrefixPrinter{
        MessageStyle: &ThemeDefault.InfoMessageStyle,
        Prefix: Prefix{
            Style: &ThemeDefault.InfoPrefixStyle,
            Text:  "INFO",
        },
    }

    // Warning returns a PrefixPrinter, which can be used to print text with a "warning" Prefix.
    Warning = PrefixPrinter{
        MessageStyle: &ThemeDefault.WarningMessageStyle,
        Prefix: Prefix{
            Style: &ThemeDefault.WarningPrefixStyle,
            Text:  "WARNING",
        },
    }

    // Success returns a PrefixPrinter, which can be used to print text with a "success" Prefix.
    Success = PrefixPrinter{
        MessageStyle: &ThemeDefault.SuccessMessageStyle,
        Prefix: Prefix{
            Style: &ThemeDefault.SuccessPrefixStyle,
            Text:  "SUCCESS",
        },
    }

    // Error returns a PrefixPrinter, which can be used to print text with an "error" Prefix.
    Error = PrefixPrinter{
        MessageStyle: &ThemeDefault.ErrorMessageStyle,
        Prefix: Prefix{
            Style: &ThemeDefault.ErrorPrefixStyle,
            Text:  " ERROR ",
        },
    }

    // Fatal returns a PrefixPrinter, which can be used to print text with an "fatal" Prefix.
    // NOTICE: Fatal terminates the application immediately!
    Fatal = PrefixPrinter{
        MessageStyle: &ThemeDefault.FatalMessageStyle,
        Prefix: Prefix{
            Style: &ThemeDefault.FatalPrefixStyle,
            Text:  " FATAL ",
        },
        Fatal: true,
    }

    // Debug Prints debug messages. By default it will only print if PrintDebugMessages is true.
    // You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself.
    Debug = PrefixPrinter{
        MessageStyle: &ThemeDefault.DebugMessageStyle,
        Prefix: Prefix{
            Text:  " DEBUG ",
            Style: &ThemeDefault.DebugPrefixStyle,
        },
        Debugger: true,
    }

    // Description returns a PrefixPrinter, which can be used to print text with a "description" Prefix.
    Description = PrefixPrinter{
        MessageStyle: &ThemeDefault.DescriptionMessageStyle,
        Prefix: Prefix{
            Style: &ThemeDefault.DescriptionPrefixStyle,
            Text:  "Description",
        },
    }
)
var (
    // Output completely disables output from pterm if set to false. Can be used in CLI application quiet mode.
    Output = true

    // PrintDebugMessages sets if messages printed by the DebugPrinter should be printed.
    PrintDebugMessages = false

    // RawOutput disables any styling and color output of pterm, if set to true.
    // You can use this to get raw output for text files etc.
    RawOutput = false
)

ActiveProgressBarPrinters contains all running ProgressbarPrinters. Generally, there should only be one active ProgressbarPrinter at a time.

var ActiveProgressBarPrinters []*ProgressbarPrinter

DefaultArea is the default area printer.

var DefaultArea = AreaPrinter{}
var (
    // DefaultBarChart is the default BarChartPrinter.
    DefaultBarChart = BarChartPrinter{
        Horizontal:             false,
        VerticalBarCharacter:   "██",
        HorizontalBarCharacter: "█",
        Height:                 GetTerminalHeight() * 2 / 3,
        Width:                  GetTerminalWidth() * 2 / 3,
    }
)
var (
    // DefaultBasicText returns a default BasicTextPrinter, which can be used to print text as is.
    // No default style is present for BasicTextPrinter.
    DefaultBasicText = BasicTextPrinter{}
)

DefaultBigText contains default values for BigTextPrinter.

var DefaultBigText = BigTextPrinter{
    BigCharacters: map[string]string{
        "a": ` █████  
██   ██ 
███████ 
██   ██ 
██   ██ `,
        "A": ` █████  
██   ██ 
███████ 
██   ██ 
██   ██ `,
        "b": `██████  
██   ██ 
██████  
██   ██ 
██████`,
        "B": `██████  
██   ██ 
██████  
██   ██ 
██████`,
        "c": ` ██████ 
██      
██      
██      
 ██████`,
        "C": ` ██████ 
██      
██      
██      
 ██████`,
        "d": `██████  
██   ██ 
██   ██ 
██   ██ 
██████ `,
        "D": `██████  
██   ██ 
██   ██ 
██   ██ 
██████ `,
        "e": `███████ 
██      
█████   
██      
███████`,
        "E": `███████ 
██      
█████   
██      
███████`,
        "f": `███████ 
██      
█████   
██      
██     `,
        "F": `███████ 
██      
█████   
██      
██     `,
        "g": ` ██████  
██       
██   ███ 
██    ██ 
 ██████  `,
        "G": ` ██████  
██       
██   ███ 
██    ██ 
 ██████  `,
        "h": `██   ██ 
██   ██ 
███████ 
██   ██ 
██   ██ `,
        "H": `██   ██ 
██   ██ 
███████ 
██   ██ 
██   ██ `,
        "i": `██ 
██ 
██ 
██ 
██`,
        "I": `██ 
██ 
██ 
██ 
██`,
        "j": `     ██ 
     ██ 
     ██ 
██   ██ 
 █████ `,
        "J": `     ██ 
     ██ 
     ██ 
██   ██ 
 █████ `,
        "k": `██   ██ 
██  ██  
█████   
██  ██  
██   ██`,
        "K": `██   ██ 
██  ██  
█████   
██  ██  
██   ██`,
        "l": `██      
██      
██      
██      
███████ `,
        "L": `██      
██      
██      
██      
███████ `,
        "m": `███    ███ 
████  ████ 
██ ████ ██ 
██  ██  ██ 
██      ██`,
        "M": `███    ███ 
████  ████ 
██ ████ ██ 
██  ██  ██ 
██      ██`,
        "n": `███    ██ 
████   ██ 
██ ██  ██ 
██  ██ ██ 
██   ████`,
        "N": `███    ██ 
████   ██ 
██ ██  ██ 
██  ██ ██ 
██   ████`,
        "o": ` ██████  
██    ██ 
██    ██ 
██    ██ 
 ██████  `,
        "O": ` ██████  
██    ██ 
██    ██ 
██    ██ 
 ██████  `,
        "p": `██████  
██   ██ 
██████  
██      
██     `,
        "P": `██████  
██   ██ 
██████  
██      
██     `,
        "q": ` ██████  
██    ██ 
██    ██ 
██ ▄▄ ██ 
 ██████  
    ▀▀   `,
        "Q": ` ██████  
██    ██ 
██    ██ 
██ ▄▄ ██ 
 ██████  
    ▀▀   `,
        "r": `██████  
██   ██ 
██████  
██   ██ 
██   ██`,
        "R": `██████  
██   ██ 
██████  
██   ██ 
██   ██`,
        "s": `███████ 
██      
███████ 
     ██ 
███████`,
        "S": `███████ 
██      
███████ 
     ██ 
███████`,
        "t": `████████ 
   ██    
   ██    
   ██    
   ██    `,
        "T": `████████ 
   ██    
   ██    
   ██    
   ██    `,
        "u": `██    ██ 
██    ██ 
██    ██ 
██    ██ 
 ██████ `,
        "U": `██    ██ 
██    ██ 
██    ██ 
██    ██ 
 ██████ `,
        "v": `██    ██ 
██    ██ 
██    ██ 
 ██  ██  
  ████   `,
        "V": `██    ██ 
██    ██ 
██    ██ 
 ██  ██  
  ████   `,
        "w": `██     ██ 
██     ██ 
██  █  ██ 
██ ███ ██ 
 ███ ███ `,
        "W": `██     ██ 
██     ██ 
██  █  ██ 
██ ███ ██ 
 ███ ███ `,
        "x": `██   ██ 
 ██ ██  
  ███   
 ██ ██  
██   ██ `,
        "X": `██   ██ 
 ██ ██  
  ███   
 ██ ██  
██   ██ `,
        "y": `██    ██ 
 ██  ██  
  ████   
   ██    
   ██   `,
        "Y": `██    ██ 
 ██  ██  
  ████   
   ██    
   ██   `,
        "z": `███████ 
   ███  
  ███   
 ███    
███████`,
        "Z": `███████ 
   ███  
  ███   
 ███    
███████`,
        "0": ` ██████  
██  ████ 
██ ██ ██ 
████  ██ 
 ██████ `,
        "1": ` ██ 
███ 
 ██ 
 ██ 
 ██ `,
        "2": `██████  
     ██ 
 █████  
██      
███████ `,
        "3": `██████  
     ██ 
 █████  
     ██ 
██████ `,
        "4": `██   ██ 
██   ██ 
███████ 
     ██ 
     ██ `,
        "5": `███████ 
██      
███████ 
     ██ 
███████`,
        "6": ` ██████  
██       
███████  
██    ██ 
 ██████ `,
        "7": `███████ 
     ██ 
    ██  
   ██   
   ██`,
        "8": ` █████  
██   ██ 
 █████  
██   ██ 
 █████ `,
        "9": ` █████  
██   ██ 
 ██████ 
     ██ 
 █████ `,
        " ": "    ",
        "!": `██ 
██ 
██ 
   
██ `,
        "$": `▄▄███▄▄·
██      
███████ 
     ██ 
███████ 
  ▀▀▀  `,
        "%": `██  ██ 
   ██  
  ██   
 ██    
██  ██`,
        "/": `    ██ 
   ██  
  ██   
 ██    
██   `,
        "(": ` ██ 
██  
██  
██  
 ██ `,
        ")": `██  
 ██ 
 ██ 
 ██ 
██  `,
        "?": `██████  
     ██ 
  ▄███  
  ▀▀    
  ██   `,
        "[": `███ 
██  
██  
██  
███`,
        "]": `███ 
 ██ 
 ██ 
 ██ 
███ `,
        ".": `   
   
   
   
██`,
        ",": `   
   
   
   
▄█`,
        "-": `      
      
█████ 
      
      
     `,
        "<": `  ██ 
 ██  
██   
 ██  
  ██ `,
        ">": `██   
 ██  
  ██ 
 ██  
██ `,
        "*": `      
▄ ██ ▄
 ████ 
▀ ██ ▀
     `,
        "#": ` ██  ██  
████████ 
 ██  ██  
████████ 
 ██  ██ `,
        "_": `        
        
        
        
███████ `,
        ":": `   
██ 
   
   
██ `,
        "°": ` ████  
██  ██ 
 ████  
       
      `,
    },
}

DefaultBox is the default BoxPrinter.

var DefaultBox = BoxPrinter{
    VerticalString:          "|",
    TopRightCornerString:    "└",
    TopLeftCornerString:     "┘",
    BottomLeftCornerString:  "┐",
    BottomRightCornerString: "┌",
    HorizontalString:        "─",
    BoxStyle:                &ThemeDefault.BoxStyle,
    TextStyle:               &ThemeDefault.BoxTextStyle,
    RightPadding:            1,
    LeftPadding:             1,
    TopPadding:              0,
    BottomPadding:           0,
}

DefaultBulletList contains standards, which can be used to print a BulletListPrinter.

var DefaultBulletList = BulletListPrinter{
    Bullet:      "•",
    TextStyle:   &ThemeDefault.BulletListTextStyle,
    BulletStyle: &ThemeDefault.BulletListBulletStyle,
}

DefaultCenter is the default CenterPrinter.

var DefaultCenter = CenterPrinter{
    CenterEachLineSeparately: false,
}
var (
    // DefaultHeader returns the printer for a default header text.
    // Defaults to LightWhite, Bold Text and a Gray DefaultHeader background.
    DefaultHeader = HeaderPrinter{
        TextStyle:       &ThemeDefault.HeaderTextStyle,
        BackgroundStyle: &ThemeDefault.HeaderBackgroundStyle,
        Margin:          5,
    }
)

DefaultPanel is the default PanelPrinter.

var DefaultPanel = PanelPrinter{
    Padding: 1,
}

DefaultParagraph contains the default values for a ParagraphPrinter.

var DefaultParagraph = ParagraphPrinter{
    MaxWidth: GetTerminalWidth(),
}
var (
    // DefaultProgressbar is the default ProgressbarPrinter.
    DefaultProgressbar = ProgressbarPrinter{
        Total:                     100,
        BarCharacter:              "█",
        LastCharacter:             "█",
        ElapsedTimeRoundingFactor: time.Second,
        BarStyle:                  &ThemeDefault.ProgressbarBarStyle,
        TitleStyle:                &ThemeDefault.ProgressbarTitleStyle,
        ShowTitle:                 true,
        ShowCount:                 true,
        ShowPercentage:            true,
        ShowElapsedTime:           true,
        BarFiller:                 " ",
    }
)

DefaultSection is the default section printer.

var DefaultSection = SectionPrinter{
    Style:           &ThemeDefault.SectionStyle,
    Level:           1,
    TopPadding:      1,
    BottomPadding:   1,
    IndentCharacter: "#",
}

DefaultSpinner is the default SpinnerPrinter.

var DefaultSpinner = SpinnerPrinter{
    Sequence:       []string{"▀ ", " ▀", " ▄", "▄ "},
    Style:          &ThemeDefault.SpinnerStyle,
    Delay:          time.Millisecond * 200,
    MessageStyle:   &ThemeDefault.SpinnerTextStyle,
    SuccessPrinter: &Success,
    FailPrinter:    &Error,
    WarningPrinter: &Warning,
}

DefaultTable contains standards, which can be used to print a TablePrinter.

var DefaultTable = TablePrinter{
    Style:          &ThemeDefault.TableStyle,
    HeaderStyle:    &ThemeDefault.TableHeaderStyle,
    Separator:      " | ",
    SeparatorStyle: &ThemeDefault.TableSeparatorStyle,
}

DefaultTree contains standards, which can be used to render a TreePrinter.

var DefaultTree = TreePrinter{
    TreeStyle:            &ThemeDefault.TreeStyle,
    TextStyle:            &ThemeDefault.TreeTextStyle,
    TopRightCornerString: "└",
    HorizontalString:     "─",
    TopRightDownString:   "├",
    VerticalString:       "│",
    RightDownLeftString:  "┬",
    Indent:               2,
}

FallbackTerminalHeight is the value used for GetTerminalHeight, if the actual height can not be detected You can override that value if necessary.

var FallbackTerminalHeight = 10

FallbackTerminalWidth is the value used for GetTerminalWidth, if the actual width can not be detected You can override that value if necessary.

var FallbackTerminalWidth = 80
var (
    // GrayBoxStyle wraps text in a gray box.
    GrayBoxStyle = NewStyle(BgGray, FgLightWhite)
)

PrintColor is false if PTerm should not print colored output.

var PrintColor = true
var (
    // ThemeDefault is the default theme used by PTerm.
    // If this variable is overwritten, the new value is used as default theme.
    ThemeDefault = Theme{
        PrimaryStyle:            Style{FgCyan},
        SecondaryStyle:          Style{FgLightMagenta},
        HighlightStyle:          Style{Bold, FgYellow},
        InfoMessageStyle:        Style{FgLightCyan},
        InfoPrefixStyle:         Style{FgBlack, BgCyan},
        SuccessMessageStyle:     Style{FgGreen},
        SuccessPrefixStyle:      Style{FgBlack, BgGreen},
        WarningMessageStyle:     Style{FgYellow},
        WarningPrefixStyle:      Style{FgBlack, BgYellow},
        ErrorMessageStyle:       Style{FgLightRed},
        ErrorPrefixStyle:        Style{FgBlack, BgLightRed},
        FatalMessageStyle:       Style{FgLightRed},
        FatalPrefixStyle:        Style{FgBlack, BgLightRed},
        DescriptionMessageStyle: Style{FgDefault},
        DescriptionPrefixStyle:  Style{FgLightWhite, BgDarkGray},
        ScopeStyle:              Style{FgGray},
        ProgressbarBarStyle:     Style{FgCyan},
        ProgressbarTitleStyle:   Style{FgLightCyan},
        HeaderTextStyle:         Style{FgLightWhite, Bold},
        HeaderBackgroundStyle:   Style{BgGray},
        SpinnerStyle:            Style{FgLightCyan},
        SpinnerTextStyle:        Style{FgLightWhite},
        TableStyle:              Style{FgDefault},
        TableHeaderStyle:        Style{FgLightCyan},
        TableSeparatorStyle:     Style{FgGray},
        SectionStyle:            Style{Bold, FgYellow},
        BulletListTextStyle:     Style{FgDefault},
        BulletListBulletStyle:   Style{FgGray},
        TreeStyle:               Style{FgGray},
        TreeTextStyle:           Style{FgDefault},
        LetterStyle:             Style{FgDefault},
        DebugMessageStyle:       Style{FgGray},
        DebugPrefixStyle:        Style{FgBlack, BgGray},
        BoxStyle:                Style{FgDefault},
        BoxTextStyle:            Style{FgDefault},
        BarLabelStyle:           Style{FgLightCyan},
        BarStyle:                Style{FgCyan},
    }
)
func DisableColor()

DisableColor disables colors.

func DisableDebugMessages()

DisableDebugMessages disables the output of debug printers.

func DisableOutput()

DisableOutput disables the output of PTerm.

func DisableStyling()

DisableStyling sets PTerm to RawOutput mode and disables all of PTerms styling. You can use this to print to text files etc. This also calls DisableColor.

func EnableColor()

EnableColor enables colors.

func EnableDebugMessages()

EnableDebugMessages enables the output of debug printers.

func EnableOutput()

EnableOutput enables the output of PTerm.

func EnableStyling()

EnableStyling enables the default PTerm styling. This also calls EnableColor.

func Fprint

func Fprint(writer io.Writer, a ...interface{})

Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func Fprintln(writer io.Writer, a ...interface{})

Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func Fprinto

func Fprinto(w io.Writer, a ...interface{})

Fprinto prints Printo to a custom writer.

func GetTerminalHeight() int

GetTerminalHeight returns the terminal height of the active terminal.

func GetTerminalSize() (width, height int, err error)

GetTerminalSize returns the width and the height of the active terminal.

func GetTerminalWidth() int

GetTerminalWidth returns the terminal width of the active terminal.

func Print

func Print(a ...interface{})

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func PrintOnError(a ...interface{})

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func Printf

func Printf(format string, a ...interface{})

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func Printfln(format string, a ...interface{})

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func Println

func Println(a ...interface{})

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func Printo

func Printo(a ...interface{})

Printo overrides the current line in a terminal. If the current line is empty, the text will be printed like with pterm.Print. Example: pterm.Printo("Hello, World") time.Sleep(time.Second) pterm.Printo("Hello, Earth!")

func RemoveColorFromString(a ...interface{}) string

RemoveColorFromString removes color codes from a string.

func SetDefaultOutput(w io.Writer)

SetDefaultOutput sets the default output of pterm.

func Sprint

func Sprint(a ...interface{}) string

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

func Sprintf

func Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func Sprintln(a ...interface{}) string

Sprintln returns what Println would print to the terminal.

func Sprinto

func Sprinto(a ...interface{}) string

Sprinto returns what Printo would print.

AreaPrinter prints an area which can be updated easily. use this printer for live output like charts, algorithm visualizations, simulations and even games.

type AreaPrinter struct {
    RemoveWhenDone bool
    Fullscreen     bool
    Center         bool
    // contains filtered or unexported fields
}

func (*AreaPrinter) GenericStart

func (p *AreaPrinter) GenericStart() (*LivePrinter, error)

GenericStart runs Start, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Start instead of this in your program.

func (*AreaPrinter) GenericStop

func (p *AreaPrinter) GenericStop() (*LivePrinter, error)

GenericStop runs Stop, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Stop instead of this in your program.

func (*AreaPrinter) GetContent

func (p *AreaPrinter) GetContent() string

GetContent returns the current area content.

func (*AreaPrinter) Start

func (p *AreaPrinter) Start(text ...interface{}) (*AreaPrinter, error)

Start the AreaPrinter.

func (*AreaPrinter) Stop

func (p *AreaPrinter) Stop() error

Stop terminates the AreaPrinter immediately. The AreaPrinter will not resolve into anything.

func (*AreaPrinter) Update

func (p *AreaPrinter) Update(text ...interface{})

Update overwrites the content of the AreaPrinter. Can be used live.

func (AreaPrinter) WithCenter

func (p AreaPrinter) WithCenter(b ...bool) *AreaPrinter

WithCenter centers the AreaPrinter content to the terminal.

func (AreaPrinter) WithFullscreen

func (p AreaPrinter) WithFullscreen(b ...bool) *AreaPrinter

WithFullscreen sets the AreaPrinter height the same height as the terminal, making it fullscreen.

func (AreaPrinter) WithRemoveWhenDone

func (p AreaPrinter) WithRemoveWhenDone(b ...bool) *AreaPrinter

WithRemoveWhenDone removes the AreaPrinter content after it is stopped.

type Bar

Bar is used in bar charts.

type Bar struct {
    Label      string
    Value      int
    Style      *Style
    LabelStyle *Style
}

func (Bar) WithLabel

func (p Bar) WithLabel(s string) *Bar

WithLabel returns a new Bar with a specific option.

func (Bar) WithLabelStyle

func (p Bar) WithLabelStyle(style *Style) *Bar

WithLabelStyle returns a new Bar with a specific option.

func (Bar) WithStyle

func (p Bar) WithStyle(style *Style) *Bar

WithStyle returns a new Bar with a specific option.

func (Bar) WithValue

func (p Bar) WithValue(value int) *Bar

WithValue returns a new Bar with a specific option.

BarChartPrinter is used to print bar charts.

type BarChartPrinter struct {
    Bars       Bars
    Horizontal bool
    ShowValue  bool
    // Height sets the maximum height of a vertical bar chart.
    // The default is calculated to fit into the terminal.
    // Ignored if Horizontal is set to true.
    Height int
    // Width sets the maximum width of a horizontal bar chart.
    // The default is calculated to fit into the terminal.
    // Ignored if Horizontal is set to false.
    Width                  int
    VerticalBarCharacter   string
    HorizontalBarCharacter string
}

func (BarChartPrinter) Render

func (p BarChartPrinter) Render() error

Render prints the Template to the terminal.

func (BarChartPrinter) Srender

func (p BarChartPrinter) Srender() (string, error)

Srender renders the BarChart as a string.

func (BarChartPrinter) WithBars

func (p BarChartPrinter) WithBars(bars Bars) *BarChartPrinter

WithBars returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithHeight

func (p BarChartPrinter) WithHeight(value int) *BarChartPrinter

WithHeight returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithHorizontal

func (p BarChartPrinter) WithHorizontal(b ...bool) *BarChartPrinter

WithHorizontal returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithHorizontalBarCharacter

func (p BarChartPrinter) WithHorizontalBarCharacter(char string) *BarChartPrinter

WithHorizontalBarCharacter returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithShowValue

func (p BarChartPrinter) WithShowValue(b ...bool) *BarChartPrinter

WithShowValue returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithVerticalBarCharacter

func (p BarChartPrinter) WithVerticalBarCharacter(char string) *BarChartPrinter

WithVerticalBarCharacter returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithWidth

func (p BarChartPrinter) WithWidth(value int) *BarChartPrinter

WithWidth returns a new BarChartPrinter with a specific option.

type Bars

Bars is used to display multiple Bar.

type Bars []Bar

BasicTextPrinter is the printer used to print the input as-is or as specified by user formatting.

type BasicTextPrinter struct {
    Style *Style
}

func (*BasicTextPrinter) Print

func (p *BasicTextPrinter) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (*BasicTextPrinter) PrintOnError

func (p *BasicTextPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*BasicTextPrinter) Printf

func (p *BasicTextPrinter) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (*BasicTextPrinter) Printfln

func (p *BasicTextPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (*BasicTextPrinter) Println

func (p *BasicTextPrinter) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (BasicTextPrinter) Sprint

func (p BasicTextPrinter) Sprint(a ...interface{}) string

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

func (BasicTextPrinter) Sprintf

func (p BasicTextPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (BasicTextPrinter) Sprintfln

func (p BasicTextPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (BasicTextPrinter) Sprintln

func (p BasicTextPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (BasicTextPrinter) WithStyle

func (p BasicTextPrinter) WithStyle(style *Style) *BasicTextPrinter

WithStyle adds a style to the printer.

BigTextPrinter renders big text. You can use this as title screen for your application.

type BigTextPrinter struct {
    // BigCharacters holds the map from a normal character to it's big version.
    BigCharacters map[string]string
    Letters       Letters
}

func (BigTextPrinter) Render

func (p BigTextPrinter) Render() error

Render prints the BigText to the terminal.

func (BigTextPrinter) Srender

func (p BigTextPrinter) Srender() (string, error)

Srender renders the BigText as a string.

func (BigTextPrinter) WithBigCharacters

func (p BigTextPrinter) WithBigCharacters(chars map[string]string) *BigTextPrinter

WithBigCharacters returns a new BigTextPrinter with specific BigCharacters.

func (BigTextPrinter) WithLetters

func (p BigTextPrinter) WithLetters(letters ...Letters) *BigTextPrinter

WithLetters returns a new BigTextPrinter with specific Letters

BoxPrinter is able to render a box around printables.

type BoxPrinter struct {
    TextStyle               *Style
    VerticalString          string
    BoxStyle                *Style
    HorizontalString        string
    TopRightCornerString    string
    TopLeftCornerString     string
    BottomLeftCornerString  string
    BottomRightCornerString string
    TopPadding              int
    BottomPadding           int
    RightPadding            int
    LeftPadding             int
}

func (BoxPrinter) Print

func (p BoxPrinter) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (BoxPrinter) PrintOnError

func (p BoxPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (BoxPrinter) Printf

func (p BoxPrinter) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (BoxPrinter) Printfln

func (p BoxPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (BoxPrinter) Println

func (p BoxPrinter) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (BoxPrinter) Sprint

func (p BoxPrinter) Sprint(a ...interface{}) string

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

func (BoxPrinter) Sprintf

func (p BoxPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (BoxPrinter) Sprintfln

func (p BoxPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (BoxPrinter) Sprintln

func (p BoxPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (BoxPrinter) WithBottomLeftCornerString

func (p BoxPrinter) WithBottomLeftCornerString(str string) *BoxPrinter

WithBottomLeftCornerString returns a new box with a specific BottomLeftCornerString.

func (BoxPrinter) WithBottomPadding

func (p BoxPrinter) WithBottomPadding(padding int) *BoxPrinter

WithBottomPadding returns a new box with a specific BottomPadding.

func (BoxPrinter) WithBottomRightCornerString

func (p BoxPrinter) WithBottomRightCornerString(str string) *BoxPrinter

WithBottomRightCornerString returns a new box with a specific BottomRightCornerString.

func (BoxPrinter) WithBoxStyle

func (p BoxPrinter) WithBoxStyle(style *Style) *BoxPrinter

WithBoxStyle returns a new box with a specific box Style.

func (BoxPrinter) WithHorizontalString

func (p BoxPrinter) WithHorizontalString(str string) *BoxPrinter

WithHorizontalString returns a new box with a specific HorizontalString.

func (BoxPrinter) WithLeftPadding

func (p BoxPrinter) WithLeftPadding(padding int) *BoxPrinter

WithLeftPadding returns a new box with a specific LeftPadding.

func (BoxPrinter) WithRightPadding

func (p BoxPrinter) WithRightPadding(padding int) *BoxPrinter

WithRightPadding returns a new box with a specific RightPadding.

func (BoxPrinter) WithTextStyle

func (p BoxPrinter) WithTextStyle(style *Style) *BoxPrinter

WithTextStyle returns a new box with a specific text Style.

func (BoxPrinter) WithTopLeftCornerString

func (p BoxPrinter) WithTopLeftCornerString(str string) *BoxPrinter

WithTopLeftCornerString returns a new box with a specific TopLeftCornerString.

func (BoxPrinter) WithTopPadding

func (p BoxPrinter) WithTopPadding(padding int) *BoxPrinter

WithTopPadding returns a new box with a specific TopPadding.

func (BoxPrinter) WithTopRightCornerString

func (p BoxPrinter) WithTopRightCornerString(str string) *BoxPrinter

WithTopRightCornerString returns a new box with a specific TopRightCornerString.

func (BoxPrinter) WithVerticalString

func (p BoxPrinter) WithVerticalString(str string) *BoxPrinter

WithVerticalString returns a new box with a specific VerticalString.

BulletListItem is able to render a ListItem.

type BulletListItem struct {
    Level       int
    Text        string
    TextStyle   *Style
    Bullet      string
    BulletStyle *Style
}
func NewBulletListItemFromString(text string, padding string) BulletListItem

NewBulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.

func (BulletListItem) WithBullet

func (p BulletListItem) WithBullet(bullet string) *BulletListItem

WithBullet returns a new BulletListItem with a specific Prefix.

func (BulletListItem) WithBulletStyle

func (p BulletListItem) WithBulletStyle(style *Style) *BulletListItem

WithBulletStyle returns a new BulletListItem with a specific BulletStyle.

func (BulletListItem) WithLevel

func (p BulletListItem) WithLevel(level int) *BulletListItem

WithLevel returns a new BulletListItem with a specific Level.

func (BulletListItem) WithText

func (p BulletListItem) WithText(text string) *BulletListItem

WithText returns a new BulletListItem with a specific Text.

func (BulletListItem) WithTextStyle

func (p BulletListItem) WithTextStyle(style *Style) *BulletListItem

WithTextStyle returns a new BulletListItem with a specific TextStyle.

BulletListPrinter is able to render a list.

type BulletListPrinter struct {
    Items       []BulletListItem
    TextStyle   *Style
    Bullet      string
    BulletStyle *Style
}
func NewBulletListFromString(s string, padding string) BulletListPrinter

NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).

func NewBulletListFromStrings(s []string, padding string) BulletListPrinter

NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.

func (BulletListPrinter) Render

func (l BulletListPrinter) Render() error

Render prints the list to the terminal.

func (BulletListPrinter) Srender

func (l BulletListPrinter) Srender() (string, error)

Srender renders the list as a string.

func (BulletListPrinter) WithBullet

func (l BulletListPrinter) WithBullet(bullet string) *BulletListPrinter

WithBullet returns a new list with a specific bullet.

func (BulletListPrinter) WithBulletStyle

func (l BulletListPrinter) WithBulletStyle(style *Style) *BulletListPrinter

WithBulletStyle returns a new list with a specific bullet style.

func (BulletListPrinter) WithItems

func (l BulletListPrinter) WithItems(items []BulletListItem) *BulletListPrinter

WithItems returns a new list with specific Items.

func (BulletListPrinter) WithTextStyle

func (l BulletListPrinter) WithTextStyle(style *Style) *BulletListPrinter

WithTextStyle returns a new list with a specific text style.

CenterPrinter prints centered text.

type CenterPrinter struct {
    CenterEachLineSeparately bool
}

func (CenterPrinter) Print

func (p CenterPrinter) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (CenterPrinter) PrintOnError

func (p CenterPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (CenterPrinter) Printf

func (p CenterPrinter) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (CenterPrinter) Printfln

func (p CenterPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (CenterPrinter) Println

func (p CenterPrinter) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (CenterPrinter) Sprint

func (p CenterPrinter) Sprint(a ...interface{}) string

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

func (CenterPrinter) Sprintf

func (p CenterPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (CenterPrinter) Sprintfln

func (p CenterPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (CenterPrinter) Sprintln

func (p CenterPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (CenterPrinter) WithCenterEachLineSeparately

func (p CenterPrinter) WithCenterEachLineSeparately(b ...bool) *CenterPrinter

WithCenterEachLineSeparately centers each line separately.

type Color

Color is a number which will be used to color strings in the terminal.

type Color uint8

Foreground colors. basic foreground colors 30 - 37.

const (
    FgBlack Color = iota + 30
    FgRed
    FgGreen
    FgYellow
    FgBlue
    FgMagenta
    FgCyan
    FgWhite
    // FgDefault revert default FG.
    FgDefault Color = 39
)

Extra foreground color 90 - 97.

const (
    FgDarkGray Color = iota + 90
    FgLightRed
    FgLightGreen
    FgLightYellow
    FgLightBlue
    FgLightMagenta
    FgLightCyan
    FgLightWhite
    // FgGray is an alias of FgDarkGray.
    FgGray Color = 90
)

Background colors. basic background colors 40 - 47.

const (
    BgBlack Color = iota + 40
    BgRed
    BgGreen
    BgYellow // BgBrown like yellow
    BgBlue
    BgMagenta
    BgCyan
    BgWhite
    // BgDefault reverts to the default background.
    BgDefault Color = 49
)

Extra background color 100 - 107.

const (
    BgDarkGray Color = iota + 100
    BgLightRed
    BgLightGreen
    BgLightYellow
    BgLightBlue
    BgLightMagenta
    BgLightCyan
    BgLightWhite
    // BgGray is an alias of BgDarkGray.
    BgGray Color = 100
)

Option settings.

const (
    Reset Color = iota
    Bold
    Fuzzy
    Italic
    Underscore
    Blink
    FastBlink
    Reverse
    Concealed
    Strikethrough
)

func (Color) Print

func (c Color) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Color.

func (Color) PrintOnError

func (p Color) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (Color) Printf

func (c Color) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Color.

func (Color) Printfln

func (c Color) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Color.

func (Color) Println

func (c Color) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Color.

func (Color) Sprint

func (c Color) Sprint(a ...interface{}) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string. Input will be colored with the parent Color.

func (Color) Sprintf

func (c Color) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string. Input will be colored with the parent Color.

func (Color) Sprintfln

func (c Color) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended. Input will be colored with the parent Color.

func (Color) Sprintln

func (c Color) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended. Input will be colored with the parent Color.

func (Color) String

func (c Color) String() string

String converts the color to a string. eg "35".

HeaderPrinter contains the data used to craft a header. A header is printed as a big box with text in it. Can be used as title screens or section separator.

type HeaderPrinter struct {
    TextStyle       *Style
    BackgroundStyle *Style
    Margin          int
    FullWidth       bool
}

func (*HeaderPrinter) Print

func (p *HeaderPrinter) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (*HeaderPrinter) PrintOnError

func (p *HeaderPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*HeaderPrinter) Printf

func (p *HeaderPrinter) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (*HeaderPrinter) Printfln

func (p *HeaderPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (*HeaderPrinter) Println

func (p *HeaderPrinter) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (HeaderPrinter) Sprint

func (p HeaderPrinter) Sprint(a ...interface{}) string

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

func (HeaderPrinter) Sprintf

func (p HeaderPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (HeaderPrinter) Sprintfln

func (p HeaderPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (HeaderPrinter) Sprintln

func (p HeaderPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (HeaderPrinter) WithBackgroundStyle

func (p HeaderPrinter) WithBackgroundStyle(style *Style) *HeaderPrinter

WithBackgroundStyle changes the background styling of the header.

func (HeaderPrinter) WithFullWidth

func (p HeaderPrinter) WithFullWidth(b ...bool) *HeaderPrinter

WithFullWidth enables full width on a HeaderPrinter.

func (HeaderPrinter) WithMargin

func (p HeaderPrinter) WithMargin(margin int) *HeaderPrinter

WithMargin changes the background styling of the header.

func (HeaderPrinter) WithTextStyle

func (p HeaderPrinter) WithTextStyle(style *Style) *HeaderPrinter

WithTextStyle returns a new HeaderPrinter with changed

type Letter

Letter is an object, which holds a string and a specific Style for it.

type Letter struct {
    String string
    Style  *Style
}

func (Letter) WithString

func (l Letter) WithString(s string) *Letter

WithString returns a new Letter with a specific String.

func (Letter) WithStyle

func (l Letter) WithStyle(style *Style) *Letter

WithStyle returns a new Letter with a specific Style.

type Letters

Letters is a slice of Letter.

type Letters []Letter
func NewLettersFromString(text string) Letters

NewLettersFromString 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 NewLettersFromStringWithStyle(text string, style *Style) Letters

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

LeveledList is a list, which contains multiple LeveledListItem.

type LeveledList []LeveledListItem

LeveledListItem combines a text with a specific level. The level is the indent, which would normally be seen in a BulletListPrinter.

type LeveledListItem struct {
    Level int
    Text  string
}

LivePrinter is a printer which can update it's output live.

type LivePrinter interface {
    // GenericStart runs Start, but returns a LivePrinter.
    // This is used for the interface LivePrinter.
    // You most likely want to use Start instead of this in your program.
    GenericStart() (*LivePrinter, error)

    // GenericStop runs Stop, but returns a LivePrinter.
    // This is used for the interface LivePrinter.
    // You most likely want to use Stop instead of this in your program.
    GenericStop() (*LivePrinter, error)
}

type Panel

Panel contains the data, which should be printed inside a PanelPrinter.

type Panel struct {
    Data string
}

PanelPrinter prints content in boxes.

type PanelPrinter struct {
    Panels          Panels
    Padding         int
    BottomPadding   int
    SameColumnWidth bool
    BoxPrinter      BoxPrinter
}

func (PanelPrinter) Render

func (p PanelPrinter) Render() error

Render prints the Template to the terminal.

func (PanelPrinter) Srender

func (p PanelPrinter) Srender() (string, error)

Srender renders the Template as a string.

func (PanelPrinter) WithBottomPadding

func (p PanelPrinter) WithBottomPadding(bottomPadding int) *PanelPrinter

WithBottomPadding returns a new PanelPrinter with specific options.

func (PanelPrinter) WithBoxPrinter

func (p PanelPrinter) WithBoxPrinter(boxPrinter BoxPrinter) *PanelPrinter

WithBoxPrinter returns a new PanelPrinter with specific options.

func (PanelPrinter) WithPadding

func (p PanelPrinter) WithPadding(padding int) *PanelPrinter

WithPadding returns a new PanelPrinter with specific options.

func (PanelPrinter) WithPanels

func (p PanelPrinter) WithPanels(panels Panels) *PanelPrinter

WithPanels returns a new PanelPrinter with specific options.

func (PanelPrinter) WithSameColumnWidth

func (p PanelPrinter) WithSameColumnWidth(b ...bool) *PanelPrinter

WithSameColumnWidth returns a new PanelPrinter with specific options.

type Panels

Panels is a two dimensional coordinate system for Panel.

type Panels [][]Panel

ParagraphPrinter can print paragraphs to a fixed line width. The text will split between words, so that words will stick together. It's like in a book.

type ParagraphPrinter struct {
    MaxWidth int
}

func (*ParagraphPrinter) Print

func (p *ParagraphPrinter) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (*ParagraphPrinter) PrintOnError

func (p *ParagraphPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*ParagraphPrinter) Printf

func (p *ParagraphPrinter) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (*ParagraphPrinter) Printfln

func (p *ParagraphPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (*ParagraphPrinter) Println

func (p *ParagraphPrinter) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (ParagraphPrinter) Sprint

func (p ParagraphPrinter) Sprint(a ...interface{}) string

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

func (ParagraphPrinter) Sprintf

func (p ParagraphPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (ParagraphPrinter) Sprintfln

func (p ParagraphPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (ParagraphPrinter) Sprintln

func (p ParagraphPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (ParagraphPrinter) WithMaxWidth

func (p ParagraphPrinter) WithMaxWidth(width int) *ParagraphPrinter

WithMaxWidth returns a new ParagraphPrinter with a specific MaxWidth

type Prefix

Prefix contains the data used as the beginning of a printed text via a PrefixPrinter.

type Prefix struct {
    Text  string
    Style *Style
}

PrefixPrinter is the printer used to print a Prefix.

type PrefixPrinter struct {
    Prefix         Prefix
    Scope          Scope
    MessageStyle   *Style
    Fatal          bool
    ShowLineNumber bool
    // If Debugger is true, the printer will only print if PrintDebugMessages is set to true.
    // You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself.
    Debugger bool
}

func (PrefixPrinter) GetFormattedPrefix

func (p PrefixPrinter) GetFormattedPrefix() string

GetFormattedPrefix returns the Prefix as a styled text string.

func (*PrefixPrinter) Print

func (p *PrefixPrinter) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (*PrefixPrinter) PrintOnError

func (p *PrefixPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

Note: Use WithFatal(true) or Fatal to panic after first non nil error.

func (*PrefixPrinter) Printf

func (p *PrefixPrinter) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (*PrefixPrinter) Printfln

func (p *PrefixPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (*PrefixPrinter) Println

func (p *PrefixPrinter) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (*PrefixPrinter) Sprint

func (p *PrefixPrinter) Sprint(a ...interface{}) string

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

func (PrefixPrinter) Sprintf

func (p PrefixPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (PrefixPrinter) Sprintfln

func (p PrefixPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (PrefixPrinter) Sprintln

func (p PrefixPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (PrefixPrinter) WithDebugger

func (p PrefixPrinter) WithDebugger(b ...bool) *PrefixPrinter

WithDebugger returns a new Printer with specific Debugger value. If Debugger is true, the printer will only print if PrintDebugMessages is set to true. You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself.

func (PrefixPrinter) WithFatal

func (p PrefixPrinter) WithFatal(b ...bool) *PrefixPrinter

WithFatal sets if the printer should panic after printing. NOTE: The printer will only panic if either PrefixPrinter.Println, PrefixPrinter.Print or PrefixPrinter.Printf is called.

func (PrefixPrinter) WithMessageStyle

func (p PrefixPrinter) WithMessageStyle(style *Style) *PrefixPrinter

WithMessageStyle adds a custom prefix to the printer.

func (PrefixPrinter) WithPrefix

func (p PrefixPrinter) WithPrefix(prefix Prefix) *PrefixPrinter

WithPrefix adds a custom prefix to the printer.

func (PrefixPrinter) WithScope

func (p PrefixPrinter) WithScope(scope Scope) *PrefixPrinter

WithScope adds a scope to the Prefix.

func (PrefixPrinter) WithShowLineNumber

func (p PrefixPrinter) WithShowLineNumber(b ...bool) *PrefixPrinter

WithShowLineNumber sets if the printer should print the line number from where it's called in a go file.

ProgressbarPrinter shows a progress animation in the terminal.

type ProgressbarPrinter struct {
    Title                     string
    Total                     int
    Current                   int
    BarCharacter              string
    LastCharacter             string
    ElapsedTimeRoundingFactor time.Duration
    BarFiller                 string

    ShowElapsedTime bool
    ShowCount       bool
    ShowTitle       bool
    ShowPercentage  bool
    RemoveWhenDone  bool

    TitleStyle *Style
    BarStyle   *Style

    IsActive bool
    // contains filtered or unexported fields
}

func (*ProgressbarPrinter) Add

func (p *ProgressbarPrinter) Add(count int) *ProgressbarPrinter

Add to current value.

func (ProgressbarPrinter) GenericStart

func (p ProgressbarPrinter) GenericStart() (*LivePrinter, error)

GenericStart runs Start, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Start instead of this in your program.

func (ProgressbarPrinter) GenericStop

func (p ProgressbarPrinter) GenericStop() (*LivePrinter, error)

GenericStop runs Stop, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Stop instead of this in your program.

func (*ProgressbarPrinter) GetElapsedTime

func (p *ProgressbarPrinter) GetElapsedTime() time.Duration

GetElapsedTime returns the elapsed time, since the ProgressbarPrinter was started.

func (*ProgressbarPrinter) Increment

func (p *ProgressbarPrinter) Increment() *ProgressbarPrinter

Increment current value by one.

func (ProgressbarPrinter) Start

func (p ProgressbarPrinter) Start() (*ProgressbarPrinter, error)

Start the ProgressbarPrinter.

func (*ProgressbarPrinter) Stop

func (p *ProgressbarPrinter) Stop() (*ProgressbarPrinter, error)

Stop the ProgressbarPrinter.

func (ProgressbarPrinter) WithBarCharacter

func (p ProgressbarPrinter) WithBarCharacter(char string) *ProgressbarPrinter

WithBarCharacter sets the bar character of the ProgressbarPrinter.

func (ProgressbarPrinter) WithBarStyle

func (p ProgressbarPrinter) WithBarStyle(style *Style) *ProgressbarPrinter

WithBarStyle sets the style of the bar.

func (ProgressbarPrinter) WithCurrent

func (p ProgressbarPrinter) WithCurrent(current int) *ProgressbarPrinter

WithCurrent sets the current value of the ProgressbarPrinter.

func (ProgressbarPrinter) WithElapsedTimeRoundingFactor

func (p ProgressbarPrinter) WithElapsedTimeRoundingFactor(duration time.Duration) *ProgressbarPrinter

WithElapsedTimeRoundingFactor sets the rounding factor of the elapsed time.

func (ProgressbarPrinter) WithLastCharacter

func (p ProgressbarPrinter) WithLastCharacter(char string) *ProgressbarPrinter

WithLastCharacter sets the last character of the ProgressbarPrinter.

func (ProgressbarPrinter) WithRemoveWhenDone

func (p ProgressbarPrinter) WithRemoveWhenDone(b ...bool) *ProgressbarPrinter

WithRemoveWhenDone sets if the ProgressbarPrinter should be removed when it is done.

func (ProgressbarPrinter) WithShowCount

func (p ProgressbarPrinter) WithShowCount(b ...bool) *ProgressbarPrinter

WithShowCount sets if the total and current count should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithShowElapsedTime

func (p ProgressbarPrinter) WithShowElapsedTime(b ...bool) *ProgressbarPrinter

WithShowElapsedTime sets if the elapsed time should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithShowPercentage

func (p ProgressbarPrinter) WithShowPercentage(b ...bool) *ProgressbarPrinter

WithShowPercentage sets if the completed percentage should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithShowTitle

func (p ProgressbarPrinter) WithShowTitle(b ...bool) *ProgressbarPrinter

WithShowTitle sets if the title should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithTitle

func (p ProgressbarPrinter) WithTitle(name string) *ProgressbarPrinter

WithTitle sets the name of the ProgressbarPrinter.

func (ProgressbarPrinter) WithTitleStyle

func (p ProgressbarPrinter) WithTitleStyle(style *Style) *ProgressbarPrinter

WithTitleStyle sets the style of the title.

func (ProgressbarPrinter) WithTotal

func (p ProgressbarPrinter) WithTotal(total int) *ProgressbarPrinter

WithTotal sets the total value of the ProgressbarPrinter.

type RGB

RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue. https://en.wikipedia.org/wiki/RGB_color_model

type RGB struct {
    R   uint8
    G   uint8
    B   uint8
}

func NewRGB

func NewRGB(r, g, b uint8) RGB

NewRGB returns a new RGB.

func NewRGBFromHEX(hex string) (RGB, error)

NewRGBFromHEX converts a HEX and returns a new RGB.

func (RGB) Fade

func (p RGB) Fade(min, max, current float32, end ...RGB) RGB

Fade fades one RGB value (over other RGB values) to another RGB value, by giving the function a minimum, maximum and current value.

func (RGB) GetValues

func (p RGB) GetValues() (r, g, b uint8)

GetValues returns the RGB values separately.

func (RGB) Print

func (p RGB) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (RGB) PrintOnError

func (p RGB) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (RGB) Printf

func (p RGB) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (RGB) Printfln

func (p RGB) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (RGB) Println

func (p RGB) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (RGB) Sprint

func (p RGB) Sprint(a ...interface{}) string

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

func (RGB) Sprintf

func (p RGB) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (RGB) Sprintfln

func (p RGB) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (RGB) Sprintln

func (p RGB) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

RenderPrinter is used to display renderable content. Example for renderable content is a Table.

type RenderPrinter interface {
    // Render the XXX to the terminal.
    Render() error

    // Srender returns the rendered string of XXX.
    Srender() (string, error)
}

type Scope

Scope contains the data of the optional scope of a prefix. If it has a text, it will be printed after the Prefix in brackets.

type Scope struct {
    Text  string
    Style *Style
}

SectionPrinter prints a new section title. It can be used to structure longer text, or different chapters of your program.

type SectionPrinter struct {
    Style           *Style
    Level           int
    IndentCharacter string
    TopPadding      int
    BottomPadding   int
}

func (*SectionPrinter) Print

func (p *SectionPrinter) Print(a ...interface{}) *TextPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (*SectionPrinter) PrintOnError

func (p *SectionPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*SectionPrinter) Printf

func (p *SectionPrinter) Printf(format string, a ...interface{}) *TextPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (*SectionPrinter) Printfln

func (p *SectionPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (*SectionPrinter) Println

func (p *SectionPrinter) Println(a ...interface{}) *TextPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (SectionPrinter) Sprint

func (p SectionPrinter) Sprint(a ...interface{}) string

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

func (SectionPrinter) Sprintf

func (p SectionPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (SectionPrinter) Sprintfln

func (p SectionPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (SectionPrinter) Sprintln

func (p SectionPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (SectionPrinter) WithBottomPadding

func (p SectionPrinter) WithBottomPadding(padding int) *SectionPrinter

WithBottomPadding returns a new SectionPrinter with a specific top padding.

func (SectionPrinter) WithIndentCharacter

func (p SectionPrinter) WithIndentCharacter(char string) *SectionPrinter

WithIndentCharacter returns a new SectionPrinter with a specific IndentCharacter.

func (SectionPrinter) WithLevel

func (p SectionPrinter) WithLevel(level int) *SectionPrinter

WithLevel returns a new SectionPrinter with a specific level.

func (SectionPrinter) WithStyle

func (p SectionPrinter) WithStyle(style *Style) *SectionPrinter

WithStyle returns a new SectionPrinter with a specific style.

func (SectionPrinter) WithTopPadding

func (p SectionPrinter) WithTopPadding(padding int) *SectionPrinter

WithTopPadding returns a new SectionPrinter with a specific top padding.

SpinnerPrinter is a loading animation, which can be used if the progress is unknown. It's an animation loop, which can have a text and supports throwing errors or warnings. A TextPrinter is used to display all outputs, after the SpinnerPrinter is done.

type SpinnerPrinter struct {
    Text           string
    Sequence       []string
    Style          *Style
    Delay          time.Duration
    MessageStyle   *Style
    SuccessPrinter TextPrinter
    FailPrinter    TextPrinter
    WarningPrinter TextPrinter
    RemoveWhenDone bool

    IsActive bool
    // contains filtered or unexported fields
}

func (*SpinnerPrinter) Fail

func (s *SpinnerPrinter) Fail(message ...interface{})

Fail displays the fail printer. If no message is given, the text of the SpinnerPrinter will be reused as the default message.

func (*SpinnerPrinter) GenericStart

func (s *SpinnerPrinter) GenericStart() (*LivePrinter, error)

GenericStart runs Start, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Start instead of this in your program.

func (*SpinnerPrinter) GenericStop

func (s *SpinnerPrinter) GenericStop() (*LivePrinter, error)

GenericStop runs Stop, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Stop instead of this in your program.

func (SpinnerPrinter) Start

func (s SpinnerPrinter) Start(text ...interface{}) (*SpinnerPrinter, error)

Start the SpinnerPrinter.

func (*SpinnerPrinter) Stop

func (s *SpinnerPrinter) Stop() error

Stop terminates the SpinnerPrinter immediately. The SpinnerPrinter will not resolve into anything.

func (*SpinnerPrinter) Success

func (s *SpinnerPrinter) Success(message ...interface{})

Success displays the success printer. If no message is given, the text of the SpinnerPrinter will be reused as the default message.

func (*SpinnerPrinter) UpdateText

func (s *SpinnerPrinter) UpdateText(text string)

UpdateText updates the message of the active SpinnerPrinter. Can be used live.

func (*SpinnerPrinter) Warning

func (s *SpinnerPrinter) Warning(message ...interface{})

Warning displays the warning printer. If no message is given, the text of the SpinnerPrinter will be reused as the default message.

func (SpinnerPrinter) WithDelay

func (s SpinnerPrinter) WithDelay(delay time.Duration) *SpinnerPrinter

WithDelay adds a delay to the SpinnerPrinter.

func (SpinnerPrinter) WithMessageStyle

func (s SpinnerPrinter) WithMessageStyle(style *Style) *SpinnerPrinter

WithMessageStyle adds a style to the SpinnerPrinter message.

func (SpinnerPrinter) WithRemoveWhenDone

func (s SpinnerPrinter) WithRemoveWhenDone(b ...bool) *SpinnerPrinter

WithRemoveWhenDone removes the SpinnerPrinter after it is done.

func (SpinnerPrinter) WithSequence

func (s SpinnerPrinter) WithSequence(sequence ...string) *SpinnerPrinter

WithSequence adds a sequence to the SpinnerPrinter.

func (SpinnerPrinter) WithStyle

func (s SpinnerPrinter) WithStyle(style *Style) *SpinnerPrinter

WithStyle adds a style to the SpinnerPrinter.

func (SpinnerPrinter) WithText

func (s SpinnerPrinter) WithText(text string) *SpinnerPrinter

WithText adds a text to the SpinnerPrinter.

type Style

Style is a collection of colors. Can include foreground, background and styling (eg. Bold, Underscore, etc.) colors.

type Style []Color
func NewStyle(colors ...Color) *Style

NewStyle returns a new Style. Accepts multiple colors.

func (Style) Add

func (s Style) Add(styles ...Style) Style

Add styles to the current Style.

func (Style) Code

func (s Style) Code() string

Code convert to code string. returns like "32;45;3".

func (Style) Print

func (s Style) Print(a ...interface{})

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Style.

func (Style) Printf

func (s Style) Printf(format string, a ...interface{})

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Style.

func (Style) Printfln

func (s Style) Printfln(format string, a ...interface{})

Printfln formats according to a format specifier and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Style.

func (Style) Println

func (s Style) Println(a ...interface{})

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Style.

func (Style) Sprint

func (s Style) Sprint(a ...interface{}) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string. Input will be colored with the parent Style.

func (Style) Sprintf

func (s Style) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string. Input will be colored with the parent Style.

func (Style) Sprintfln

func (s Style) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended. Input will be colored with the parent Style.

func (Style) Sprintln

func (s Style) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended. Input will be colored with the parent Style.

func (Style) String

func (s Style) String() string

String convert to code string. returns like "32;45;3".

TableData is the type that contains the data of a TablePrinter.

type TableData [][]string

TablePrinter is able to render tables.

type TablePrinter struct {
    Style          *Style
    HasHeader      bool
    HeaderStyle    *Style
    Separator      string
    SeparatorStyle *Style
    Data           TableData
}

func (TablePrinter) Render

func (p TablePrinter) Render() error

Render prints the TablePrinter to the terminal.

func (TablePrinter) Srender

func (p TablePrinter) Srender() (string, error)

Srender renders the TablePrinter as a string.

func (TablePrinter) WithCSVReader

func (p TablePrinter) WithCSVReader(reader *csv.Reader) *TablePrinter

WithCSVReader return a new TablePrinter with specified Data extracted from CSV.

func (TablePrinter) WithData

func (p TablePrinter) WithData(data [][]string) *TablePrinter

WithData returns a new TablePrinter with specific Data.

func (TablePrinter) WithHasHeader

func (p TablePrinter) WithHasHeader(b ...bool) *TablePrinter

WithHasHeader returns a new TablePrinter, where the first line is marked as a header.

func (TablePrinter) WithHeaderStyle

func (p TablePrinter) WithHeaderStyle(style *Style) *TablePrinter

WithHeaderStyle returns a new TablePrinter with a specific HeaderStyle.

func (TablePrinter) WithSeparator

func (p TablePrinter) WithSeparator(separator string) *TablePrinter

WithSeparator returns a new TablePrinter with a specific separator.

func (TablePrinter) WithSeparatorStyle

func (p TablePrinter) WithSeparatorStyle(style *Style) *TablePrinter

WithSeparatorStyle returns a new TablePrinter with a specific SeparatorStyle.

func (TablePrinter) WithStyle

func (p TablePrinter) WithStyle(style *Style) *TablePrinter

WithStyle returns a new TablePrinter with a specific Style.

TextPrinter contains methods to print formatted text to the console or return it as a string.

type TextPrinter interface {
    // Sprint formats using the default formats for its operands and returns the resulting string.
    // Spaces are added between operands when neither is a string.
    Sprint(a ...interface{}) string

    // Sprintln formats using the default formats for its operands and returns the resulting string.
    // Spaces are always added between operands and a newline is appended.
    Sprintln(a ...interface{}) string

    // Sprintf formats according to a format specifier and returns the resulting string.
    Sprintf(format string, a ...interface{}) string

    // Sprintfln formats according to a format specifier and returns the resulting string.
    // Spaces are always added between operands and a newline is appended.
    Sprintfln(format string, a ...interface{}) string

    // Print formats using the default formats for its operands and writes to standard output.
    // Spaces are added between operands when neither is a string.
    // It returns the number of bytes written and any write error encountered.
    Print(a ...interface{}) *TextPrinter

    // Println formats using the default formats for its operands and writes to standard output.
    // Spaces are always added between operands and a newline is appended.
    // It returns the number of bytes written and any write error encountered.
    Println(a ...interface{}) *TextPrinter

    // Printf formats according to a format specifier and writes to standard output.
    // It returns the number of bytes written and any write error encountered.
    Printf(format string, a ...interface{}) *TextPrinter

    // Printfln formats according to a format specifier and writes to standard output.
    // Spaces are always added between operands and a newline is appended.
    // It returns the number of bytes written and any write error encountered.
    Printfln(format string, a ...interface{}) *TextPrinter

    // PrintOnError prints every error which is not nil.
    // If every error is nil, nothing will be printed.
    // This can be used for simple error checking.
    PrintOnError(a ...interface{}) *TextPrinter
}

type Theme

Theme for PTerm. Theme contains every Style used in PTerm. You can create own themes for your application or use one of the existing themes.

type Theme struct {
    PrimaryStyle            Style
    SecondaryStyle          Style
    HighlightStyle          Style
    InfoMessageStyle        Style
    InfoPrefixStyle         Style
    SuccessMessageStyle     Style
    SuccessPrefixStyle      Style
    WarningMessageStyle     Style
    WarningPrefixStyle      Style
    ErrorMessageStyle       Style
    ErrorPrefixStyle        Style
    FatalMessageStyle       Style
    FatalPrefixStyle        Style
    DescriptionMessageStyle Style
    DescriptionPrefixStyle  Style
    ScopeStyle              Style
    ProgressbarBarStyle     Style
    ProgressbarTitleStyle   Style
    HeaderTextStyle         Style
    HeaderBackgroundStyle   Style
    SpinnerStyle            Style
    SpinnerTextStyle        Style
    TableStyle              Style
    TableHeaderStyle        Style
    TableSeparatorStyle     Style
    SectionStyle            Style
    BulletListTextStyle     Style
    BulletListBulletStyle   Style
    TreeStyle               Style
    TreeTextStyle           Style
    LetterStyle             Style
    DebugMessageStyle       Style
    DebugPrefixStyle        Style
    BoxStyle                Style
    BoxTextStyle            Style
    BarLabelStyle           Style
    BarStyle                Style
}

func (Theme) WithBarLabelStyle

func (t Theme) WithBarLabelStyle(style Style) Theme

WithBarLabelStyle returns a new theme with overridden value.

func (Theme) WithBarStyle

func (t Theme) WithBarStyle(style Style) Theme

WithBarStyle returns a new theme with overridden value.

func (Theme) WithBoxStyle

func (t Theme) WithBoxStyle(style Style) Theme

WithBoxStyle returns a new theme with overridden value.

func (Theme) WithBoxTextStyle

func (t Theme) WithBoxTextStyle(style Style) Theme

WithBoxTextStyle returns a new theme with overridden value.

func (t Theme) WithBulletListBulletStyle(style Style) Theme

WithBulletListBulletStyle returns a new theme with overridden value.

func (t Theme) WithBulletListTextStyle(style Style) Theme

WithBulletListTextStyle returns a new theme with overridden value.

func (t Theme) WithDebugMessageStyle(style Style) Theme

WithDebugMessageStyle returns a new theme with overridden value.

func (t Theme) WithDebugPrefixStyle(style Style) Theme

WithDebugPrefixStyle returns a new theme with overridden value.

func (t Theme) WithDescriptionMessageStyle(style Style) Theme

WithDescriptionMessageStyle returns a new theme with overridden value.

func (t Theme) WithDescriptionPrefixStyle(style Style) Theme

WithDescriptionPrefixStyle returns a new theme with overridden value.

func (t Theme) WithErrorMessageStyle(style Style) Theme

WithErrorMessageStyle returns a new theme with overridden value.

func (t Theme) WithErrorPrefixStyle(style Style) Theme

WithErrorPrefixStyle returns a new theme with overridden value.

func (t Theme) WithFatalMessageStyle(style Style) Theme

WithFatalMessageStyle returns a new theme with overridden value.

func (t Theme) WithFatalPrefixStyle(style Style) Theme

WithFatalPrefixStyle returns a new theme with overridden value.

func (Theme) WithHighlightStyle

func (t Theme) WithHighlightStyle(style Style) Theme

WithHighlightStyle returns a new theme with overridden value.

func (t Theme) WithInfoMessageStyle(style Style) Theme

WithInfoMessageStyle returns a new theme with overridden value.

func (Theme) WithInfoPrefixStyle

func (t Theme) WithInfoPrefixStyle(style Style) Theme

WithInfoPrefixStyle returns a new theme with overridden value.

func (Theme) WithLetterStyle

func (t Theme) WithLetterStyle(style Style) Theme

WithLetterStyle returns a new theme with overridden value.

func (Theme) WithPrimaryStyle

func (t Theme) WithPrimaryStyle(style Style) Theme

WithPrimaryStyle returns a new theme with overridden value.

func (Theme) WithSecondaryStyle

func (t Theme) WithSecondaryStyle(style Style) Theme

WithSecondaryStyle returns a new theme with overridden value.

func (t Theme) WithSuccessMessageStyle(style Style) Theme

WithSuccessMessageStyle returns a new theme with overridden value.

func (t Theme) WithSuccessPrefixStyle(style Style) Theme

WithSuccessPrefixStyle returns a new theme with overridden value.

func (Theme) WithTreeStyle

func (t Theme) WithTreeStyle(style Style) Theme

WithTreeStyle returns a new theme with overridden value.

func (Theme) WithTreeTextStyle

func (t Theme) WithTreeTextStyle(style Style) Theme

WithTreeTextStyle returns a new theme with overridden value.

func (t Theme) WithWarningMessageStyle(style Style) Theme

WithWarningMessageStyle returns a new theme with overridden value.

func (t Theme) WithWarningPrefixStyle(style Style) Theme

WithWarningPrefixStyle returns a new theme with overridden value.

TreeNode is used as items in a TreePrinter.

type TreeNode struct {
    Children []TreeNode
    Text     string
}
func NewTreeFromLeveledList(leveledListItems LeveledList) TreeNode

NewTreeFromLeveledList converts a TreeItems list to a TreeNode and returns it.

TreePrinter is able to render a list.

type TreePrinter struct {
    Root                 TreeNode
    TreeStyle            *Style
    TextStyle            *Style
    TopRightCornerString string
    TopRightDownString   string
    HorizontalString     string
    VerticalString       string
    RightDownLeftString  string
    Indent               int
}

func (TreePrinter) Render

func (p TreePrinter) Render() error

Render prints the list to the terminal.

func (TreePrinter) Srender

func (p TreePrinter) Srender() (string, error)

Srender renders the list as a string.

func (TreePrinter) WithHorizontalString

func (p TreePrinter) WithHorizontalString(s string) *TreePrinter

WithHorizontalString returns a new list with a specific HorizontalString.

func (TreePrinter) WithIndent

func (p TreePrinter) WithIndent(indent int) *TreePrinter

WithIndent returns a new list with a specific amount of spacing between the levels. Indent must be at least 1.

func (TreePrinter) WithRoot

func (p TreePrinter) WithRoot(root TreeNode) *TreePrinter

WithRoot returns a new list with a specific Root.

func (TreePrinter) WithTextStyle

func (p TreePrinter) WithTextStyle(style *Style) *TreePrinter

WithTextStyle returns a new list with a specific text style.

func (TreePrinter) WithTopRightCornerString

func (p TreePrinter) WithTopRightCornerString(s string) *TreePrinter

WithTopRightCornerString returns a new list with a specific TopRightCornerString.

func (p TreePrinter) WithTopRightDownStringOngoing(s string) *TreePrinter

WithTopRightDownStringOngoing returns a new list with a specific TopRightDownString.

func (TreePrinter) WithTreeStyle

func (p TreePrinter) WithTreeStyle(style *Style) *TreePrinter

WithTreeStyle returns a new list with a specific tree style.

func (TreePrinter) WithVerticalString

func (p TreePrinter) WithVerticalString(s string) *TreePrinter

WithVerticalString returns a new list with a specific VerticalString.

Generated by gomarkdoc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment