ui

package
v0.0.0-...-947b840 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Colors = struct {
	NONE   Color
	RESET  Color
	GREEN  Color
	RED    Color
	YELLOW Color
	BLUE   Color
}{
	NONE:   colorNone,
	RESET:  color.New(color.Reset).SprintFunc(),
	GREEN:  color.New(color.FgHiGreen).SprintFunc(),
	RED:    color.New(color.FgHiRed).SprintFunc(),
	YELLOW: color.New(color.FgHiYellow).SprintFunc(),
	BLUE:   color.New(color.FgHiCyan).SprintFunc(),
}

Functions

func Ask

func Ask(msg ...string) error

func AutoApprove

func AutoApprove() bool

func Debug

func Debug() bool

func HasColor

func HasColor() bool

func Print

func Print(level Level, msg ...any)

func PrintBlockE

func PrintBlockE(errs ...error)

func Printf

func Printf(level Level, format string, args ...any)

func Println

func Println(level Level, msg ...any)

func Streams

func Streams() streams.Streams

Types

type Block

type Block interface {
	Format(streams.OutputStream, Color) string
}

type Color

type Color func(a ...interface{}) string

type Content

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

func NewErrorLine

func NewErrorLine(title string, lines ...string) Content

NewErrorLine contains a title and lines to be printed within a block. When formatted, a colored title is printed in the same line as title.

func NewErrorSection

func NewErrorSection(title string, lines ...string) Content

NewErrorSection contains a title and lines to be printed within a block. When formatted, a colored title and lines are printed each in a new line. Lines are also additionally indented.

type ErrorBlock

type ErrorBlock interface {
	Block
	Error() string
	Severity() Level
}

func NewErrorBlock

func NewErrorBlock(level Level, content []Content) ErrorBlock

type Level

type Level uint8
const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
)

type Lines

type Lines []string

func Format

func Format(o streams.OutputStream, str string, indent, startAt int) (Lines, int)

format formats given string into multiple lines that fit the width (columns) of the output stream. Argument startAt defines where in the current row should the string be printed from.

It returns formatted lines and index of the current column.

type Ui

type Ui interface {
	Ask(msg ...string) error
	Print(level Level, msg ...any)
	Printf(level Level, format string, args ...any)
	Println(level Level, msg ...any)
	PrintBlockE(err ...error)

	Streams() streams.Streams

	HasColor() bool
	Debug() bool
	AutoApprove() bool
}

func GlobalUi

func GlobalUi(opts ...UiOptions) Ui

type UiMock

type UiMock interface {
	Ui

	WriteStdin(t *testing.T, content string)
	ReadStdout(t *testing.T) string
	ReadStderr(t *testing.T) string
}

func MockGlobalTerminalUi

func MockGlobalTerminalUi(t *testing.T, uiOptions ...UiOptions) UiMock

func MockGlobalUi

func MockGlobalUi(t *testing.T, uiOptions ...UiOptions) UiMock

func MockTerminalUi

func MockTerminalUi(t *testing.T, uiOptions ...UiOptions) UiMock

func MockUi

func MockUi(t *testing.T, uiOptions ...UiOptions) UiMock

type UiOptions

type UiOptions struct {
	NoColor     bool
	Debug       bool
	AutoApprove bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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