pretty

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 5 Imported by: 1

README

Pretty

Package pretty provides utilities for beautifying console output.

Progress

$ go run cmd/progress/main.go

2025/03/12 09:53:42 pretty: [=========================>                   ]  59%

Table

$ go run cmd/table/main.go

2025/09/09 10:34:44 pretty: City name Area Population Annual Rainfall
2025/09/09 10:34:44 pretty: -----------------------------------------
2025/09/09 10:34:44 pretty: Adelaide  1295    1158259           600.5
2025/09/09 10:34:44 pretty: Brisbane  5905    1857594          1146.4
2025/09/09 10:34:44 pretty: Darwin     112     120900          1714.7
2025/09/09 10:34:44 pretty: Hobart    1357     205556           619.5
2025/09/09 10:34:44 pretty: Melbourne 1566    3806092           646.9
2025/09/09 10:34:44 pretty: Perth     5386    1554769           869.4
2025/09/09 10:34:44 pretty: Sydney    2058    4336374          1214.8

Tree

$ go run cmd/tree/main.go

2025/09/08 16:39:26 pretty: .
2025/09/08 16:39:26 pretty: ├── README.md
2025/09/08 16:39:26 pretty: ├── cmd
2025/09/08 16:39:26 pretty: │   ├── progress
2025/09/08 16:39:26 pretty: │   │   └── main.go
2025/09/08 16:39:26 pretty: │   ├── table
2025/09/08 16:39:26 pretty: │   │   └── main.go
2025/09/08 16:39:26 pretty: │   └── tree
2025/09/08 16:39:26 pretty: │       └── main.go
2025/09/08 16:39:26 pretty: └── pretty.go

Documentation

Overview

Package pretty provides utilities for beautifying console output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Progress added in v1.0.3

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

Progress represents a progress bar in the terminal.

func NewProgress added in v1.0.3

func NewProgress() *Progress

NewProgress creates a new Progress instance.

func (*Progress) Print added in v1.0.5

func (p *Progress) Print(percent float64)

Update updates the progress bar to the specified percent (0 to 1).

type ProgressWriter added in v1.0.3

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

ProgressWriter is an io.Writer that updates a progress bar as data is written.

func NewProgressWriter added in v1.0.3

func NewProgressWriter(n uint64) *ProgressWriter

NewProgressWriter creates a new ProgressWriter for a task of the given size.

For example, to display progress while reading from a reader:

reader := io.TeeReader(io.LimitReader(os.Stdin, 1024), NewProgressWriter(1024))

Or to display progress while writing to a writer:

writer := io.MultiWriter(os.Stdout, NewProgressWriter(1024))

func (*ProgressWriter) Write added in v1.0.3

func (p *ProgressWriter) Write(b []byte) (int, error)

Write writes data to the ProgressWriter and updates the progress bar.

type Table added in v1.0.3

type Table struct {
	// Conf specifies the alignment for each column: "<" for left, ">" for right.
	// If conf has fewer entries than head, the remaining columns default to left alignment ("<").
	Conf []string
	// Head represents the head of the table.
	Head []string
	// Body represents the body of the table.
	Body [][]string
}

Table represents a table structure with a head and body.

func NewTable added in v1.0.3

func NewTable() *Table

NewTable creates a new Table instance.

func (*Table) Print added in v1.0.3

func (t *Table) Print()

Print prints the table to the console with proper alignment.

type Tree added in v1.0.3

type Tree struct {
	Name string
	Leaf []*Tree
}

Tree represents a node in a tree structure.

func NewTree added in v1.0.3

func NewTree(name string) *Tree

NewTree creates a new Tree node with the given name.

func (*Tree) Print added in v1.0.3

func (t *Tree) Print()

Print prints the tree structure starting from the root node.

Directories

Path Synopsis
cmd
progress command
table command
tree command

Jump to

Keyboard shortcuts

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