ui

package
v0.0.0-...-d996d1d Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package ui provides user interface functionalities.

Index

Constants

View Source
const DurationThreshold = 1 * time.Second

DurationThreshold is a threshold to show event time only if duration is higher than this threshold. b/294443556

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats duration in "X.XXs", "XmXX.XXs" or "XhXmXX.XXs".

func Init

func Init()

Init initializes the stdout settings.

func IsTerminal

func IsTerminal() bool

IsTerminal returns whether currently using a terminal UI.

func Restore

func Restore()

Restore restores the stdout settings.

func SGR

func SGR(n SGRCode, s string) string

SGR formats s in SGR (select graphic rendition).

func StripANSIEscapeCodes

func StripANSIEscapeCodes(s string) string

StripANSIEscapeCodes strips ANSI escape codes.

Types

type LogUI

type LogUI struct{}

LogUI is a log-based UI.

func (LogUI) NewSpinner

func (LogUI) NewSpinner() spinner

NewSpinner returns an implementation of ui.spinner.

func (LogUI) PrintLines

func (LogUI) PrintLines(msgs ...string)

PrintLines implements the ui.ui interface. Because a log-based UI cannot support erasing previous lines, msgs will be printed as-is.

type SGRCode

type SGRCode int

https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters

const (
	Bold SGRCode = iota
	Red
	Green
	Yellow
	BackgroundRed
	Reset
)

func (SGRCode) String

func (s SGRCode) String() string

type TermUI

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

TermUI is a terminal-based UI.

func (*TermUI) Height

func (t *TermUI) Height() int

func (TermUI) NewSpinner

func (TermUI) NewSpinner() spinner

NewSpinner returns a terminal-based spinner.

func (*TermUI) PrintLines

func (t *TermUI) PrintLines(msgs ...string)

PrintLines implements the ui.ui interface. msg not including \n will fit on one terminal line, by eliding middle for long msg. msg including \n will print as is. If msgs starts with \n, it will print from the current line. Otherwise, it will replace the last N lines, where N is number of msgs that don't start with \n.

func (*TermUI) Width

func (t *TermUI) Width() int

type UI

type UI interface {
	// PrintLines prints message lines.
	// If msgs starts with \n, it will print from the current line.
	// Otherwise, it will replaces the last N lines, where N is len(msgs).
	PrintLines(msgs ...string)
	// NewSpinner returns a new spinner.
	NewSpinner() spinner
}

UI is a user interface.

var Default UI

Default holds the default UI interface. Making changes to this variable after init is undefined behavior. UI implementations are currently not expected to handle being changed.

Jump to

Keyboard shortcuts

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