cli

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ansi allows for advanced terminal text manipulation.

Index

Constants

This section is empty.

Variables

View Source
var (
	Black      = AnsiColor{false, 30}
	BoldBlack  = AnsiColor{true, 30}
	Red        = AnsiColor{false, 31}
	BoldRed    = AnsiColor{true, 31}
	Green      = AnsiColor{false, 32}
	BoldGreen  = AnsiColor{true, 32}
	Yellow     = AnsiColor{false, 33}
	BoldYellow = AnsiColor{true, 33}
	Blue       = AnsiColor{false, 34}
	BoldBlue   = AnsiColor{true, 34}
	Purple     = AnsiColor{false, 35}
	BoldPurple = AnsiColor{true, 35}
	Cyan       = AnsiColor{false, 36}
	BoldCyan   = AnsiColor{true, 36}
	White      = AnsiColor{false, 37}
	BoldWhite  = AnsiColor{true, 37}
	Default    = AnsiColor{false, 39}

	Bold         = AnsiColor{false, 1}
	NotBold      = AnsiColor{false, 22}
	Underline    = AnsiColor{false, 4}
	NotUnderline = AnsiColor{false, 24}
	Reversed     = AnsiColor{false, 7}
	NotReversed  = AnsiColor{false, 27}
)

Functions

func Confirm

func Confirm(message string) bool

Confirm asks the user for yes/no confirmation.

func Fprint

func Fprint(output io.Writer, col AnsiColor, s ...any)

Fprint is a replacement for fmt.Fprint, which accepts an AnsiColor as the first argument.

func Fprintf

func Fprintf(output io.Writer, col AnsiColor, s string, args ...any)

Fprintf is a replacement for fmt.Fprintf, which accepts an AnsiColor as the first argument.

func Fprintln

func Fprintln(output io.Writer, col AnsiColor, s ...any)

Fprintln is a replacement for fmt.Fprintln, which accepts an AnsiColor as the first argument.

func IsBold

func IsBold() bool

func IsReversed

func IsReversed() bool

func IsUnderline

func IsUnderline() bool

func Print

func Print(col AnsiColor, s ...any)

Print is a replacement for fmt.Print, which accepts an AnsiColor as the first argument.

func Printf

func Printf(col AnsiColor, s string, args ...any)

Printf is a replacement for fmt.Printf, which accepts an AnsiColor as the first argument.

func Println

func Println(col AnsiColor, s ...any)

Println is a replacement for fmt.Println, which accepts an AnsiColor as the first argument.

func Prompt

func Prompt(message string) string

Prompt displays a message and returns the user input.

func PromptPassword

func PromptPassword(message string) string

PromptPassword securely asks for a hidden input (e.g. password).

func PromptWithDefault

func PromptWithDefault(message, defaultValue string) string

PromptWithDefault returns the user input or a default if Enter is pressed.

func ResetAll

func ResetAll()

ResetAll resets all properties to default.

func SetAll

func SetAll(fg, bg AnsiColor, bold, underline, reversed bool)

SetAll sets the foreground, background, bold, underline and reversed properties at once.

func SetBg

func SetBg(bg AnsiColor)

SetBg sets the background text color.

func SetBold

func SetBold(bold bool)

SetBold sets the text to be bold or not.

func SetFg

func SetFg(fg AnsiColor)

SetFg sets the foreground text color.

func SetReversed

func SetReversed(reversed bool)

SetReversed sets the text to be reversed or not.

func SetUnderline

func SetUnderline(underline bool)

SetUnderline sets the text to be underlined or not.

Types

type AnsiColor

type AnsiColor struct {
	// contains filtered or unexported fields
}

func GetBgColor

func GetBgColor() AnsiColor

func GetFgColor

func GetFgColor() AnsiColor

Add these functions to cli.go

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table represents a simple text-based table.

func NewTable

func NewTable(headers ...string) *Table

NewTable creates a new table with headers.

func (*Table) AddRow

func (t *Table) AddRow(columns ...string)

AddRow appends a row of data to the table.

func (*Table) Render

func (t *Table) Render()

Render prints the formatted table to stdout.

func (*Table) SetBorder

func (t *Table) SetBorder(enabled bool)

SetBorder enables or disables table borders like MySQL CLI.

func (*Table) SetPadding

func (t *Table) SetPadding(p int)

SetPadding allows customizing the spacing between columns.

Jump to

Keyboard shortcuts

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