termstatus

package module
v0.0.0-...-eac3586 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-2-Clause Imports: 14 Imported by: 0

README

From https://github.com/restic/restic/tree/master/internal/ui/termstatus.

git remote add upstream [email protected]:restic/restic.git
git filter-repo --subdirectory-filter internal/ui/termstatus

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(tb testing.TB, condition bool, msg string, v ...interface{})

Assert fails the test if the condition is false.

func CanUpdateStatus

func CanUpdateStatus(fd uintptr) bool

CanUpdateStatus returns true if status lines can be printed, the process output is not redirected to a file or pipe.

func Equals

func Equals(tb testing.TB, exp, act interface{}, msgs ...string)

Equals fails the test if exp is not equal to act. msg is optional message to be printed, first param being format string and rest being arguments.

func IsProcessBackground

func IsProcessBackground(fd uintptr) bool

IsProcessBackground reports whether the current process is running in the background. fd must be a file descriptor for the terminal.

func OK

func OK(tb testing.TB, err error)

OK fails the test if an err is not nil.

func Quote

func Quote(line string) string

Quote lines with funny characters in them, meaning control chars, newlines, tabs, anything else non-printable and invalid UTF-8.

This is intended to produce a string that does not mess up the terminal rather than produce an unambiguous quoted string.

func Truncate

func Truncate(s string, w int) string

Truncate s to fit in width (number of terminal cells) w. If w is negative, returns the empty string.

func WrapStdio

func WrapStdio(term *Terminal) (stdout, stderr io.WriteCloser)

WrapStdio returns line-buffering replacements for os.Stdout and os.Stderr. On Close, the remaining bytes are written, followed by a line break.

Types

type Terminal

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

Terminal is used to write messages and display status lines which can be updated. When the output is redirected to a file, the status lines are not printed.

func New

func New(wr io.Writer, errWriter io.Writer, disableStatus bool) *Terminal

New returns a new Terminal for wr. A goroutine is started to update the terminal. It is terminated when ctx is cancelled. When wr is redirected to a file (e.g. via shell output redirection) or is just an io.Writer (not the open *os.File for stdout), no status lines are printed. The status lines and normal output (via Print/Printf) are written to wr, error messages are written to errWriter. If disableStatus is set to true, no status messages are printed even if the terminal supports it.

func (*Terminal) CanUpdateStatus

func (t *Terminal) CanUpdateStatus() bool

CanUpdateStatus return whether the status output is updated in place.

func (*Terminal) Error

func (t *Terminal) Error(line string)

Error writes an error to the terminal.

func (*Terminal) Print

func (t *Terminal) Print(line string)

Print writes a line to the terminal.

func (*Terminal) Run

func (t *Terminal) Run(ctx context.Context)

Run updates the screen. It should be run in a separate goroutine. When ctx is cancelled, the status lines are cleanly removed.

func (*Terminal) SetStatus

func (t *Terminal) SetStatus(lines []string)

SetStatus updates the status lines. The lines should not contain newlines; this method adds them. Pass nil or an empty array to remove the status lines.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳