console

package
v0.1.0-rc.10 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuzzyMultiSelector

func FuzzyMultiSelector(question string, items []string, stdin io.Reader, terminal TerminalInterface) []string

FuzzyMultiSelector is used to create a selector with multiple items.

func FuzzySelector

func FuzzySelector(question string, items []string, stdin io.Reader, terminal TerminalInterface) string

FuzzySelector is used to create a selector. If terminal is nil, we will default to goterm.

func FuzzyTableMultiSelector

func FuzzyTableMultiSelector(question string, columns []string, items [][]string,
	stdin io.Reader, terminal TerminalInterface) [][]string

FuzzyTableMultiSelector is used to create a selector with a table and multiple items.

func FuzzyTableSelector

func FuzzyTableSelector(question string, columns []string, items [][]string,
	stdin io.Reader, terminal TerminalInterface) []string

FuzzyTableSelector is used to create a selector with a table.

func MultiInput

func MultiInput(fields []InputField, stdin io.Reader, terminal TerminalInterface) []string

MultiInput is used to format multiple input slots to the display.

func Question

func Question(question string, blankAcceptable bool, bufferedStdin stringReader, stdout io.Writer) string

Question is used to define a basic console question.

Types

type InputField

type InputField struct {
	// Optional defines if the field can be blank.
	Optional bool `json:"optional"`

	// Name defines the input boxes name.
	Name string `json:"name"`

	// Description defines the input boxes description.
	Description string `json:"description"`
}

InputField is used to define a field which users can input text into.

type MockTerminal

type MockTerminal struct {
	Buffer bytes.Buffer

	CustomWidth  int
	ExitSignaled bool
}

MockTerminal is used to define a terminal mock for unit tests.

func (*MockTerminal) BufferInputs

func (m *MockTerminal) BufferInputs() bool

BufferInputs implements TerminalInterface.

func (*MockTerminal) Clear

func (m *MockTerminal) Clear()

Clear implements TerminalInterface.

func (*MockTerminal) Flush

func (m *MockTerminal) Flush()

Flush implements TerminalInterface.

func (*MockTerminal) Height

func (m *MockTerminal) Height() int

Height implements TerminalInterface.

func (*MockTerminal) MakeRaw

func (m *MockTerminal) MakeRaw() error

MakeRaw implements TerminalInterface.

func (*MockTerminal) Print

func (m *MockTerminal) Print(items ...interface{}) (int, error)

Print implements TerminalInterface.

func (*MockTerminal) Println

func (m *MockTerminal) Println(items ...interface{}) (int, error)

Println implements TerminalInterface.

func (*MockTerminal) SignalInterrupt

func (m *MockTerminal) SignalInterrupt()

SignalInterrupt implements TerminalInterface.

func (*MockTerminal) Sync

func (m *MockTerminal) Sync(s string) error

Sync implements TerminalInterface.

func (*MockTerminal) Unraw

func (m *MockTerminal) Unraw() error

Unraw implements TerminalInterface.

func (*MockTerminal) Width

func (m *MockTerminal) Width() int

Width implements TerminalInterface.

type StdinDripFeeder

type StdinDripFeeder struct {
	T *testing.T

	Inputs [][]byte
	Index  int
}

StdinDripFeeder is used to define a io.Reader designed to drip feed in different inputs.

func (*StdinDripFeeder) Read

func (s *StdinDripFeeder) Read(b []byte) (int, error)

Read implements io.Reader.

type TerminalInterface

type TerminalInterface interface {
	Height() int
	Width() int
	Print(items ...interface{}) (int, error)
	Sync(s string) error
	Println(items ...interface{}) (int, error)
	Clear()
	Flush()
	SignalInterrupt()
	MakeRaw() error
	Unraw() error
	BufferInputs() bool
}

TerminalInterface defines a interface for a compatible terminal. Used for unit testing.

Jump to

Keyboard shortcuts

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