terminal

package
v0.0.0-...-9ebf03c Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetWidthAndHeight

func GetWidthAndHeight() (int, int)

Types

type Alignment

type Alignment int

Alignment represents the text alignment within a table cell.

const (
	AlignLeft Alignment = iota
	AlignCenter
	AlignRight
)

type Column

type Column struct {
	Header    string    // The header text for the column
	Field     string    // The field name to extract data from
	MinWidth  int       // The minimum width of the column
	MaxWidth  *int      // The maximum width of the column
	Wrap      bool      // Whether to wrap text in this column
	Alignment Alignment // The text alignment for this column
}

Column represents a single column in a table.

type Option

type Option struct {
	ID          interface{}
	Description string
}

type Table

type Table struct {
	Columns    []Column                 // The columns of the table
	Data       []map[string]interface{} // The data to be displayed in the table
	Percentage float64                  // The percentage of terminal width to use
	// contains filtered or unexported fields
}

Table represents a table to be rendered in the terminal.

func (*Table) AddColumn

func (t *Table) AddColumn(header, field string, minWidth int, maxWidth *int, wrap bool, alignment Alignment)

AddColumn adds a new column to the table.

func (*Table) AddRow

func (t *Table) AddRow(row map[string]interface{})

AddRow adds a new row of data to the table.

func (*Table) Render

func (t *Table) Render()

Render draws the table in the terminal.

type Terminal

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

func New

func New() *Terminal

func (*Terminal) NewTable

func (t *Terminal) NewTable(percentage float64) *Table

NewTable creates a new Table instance.

func (*Terminal) Prompt

func (t *Terminal) Prompt(prompt string) (string, error)

func (*Terminal) PromptConfirm

func (t *Terminal) PromptConfirm(prompt string) (bool, error)

func (*Terminal) PromptMultipleOptionsSelect

func (t *Terminal) PromptMultipleOptionsSelect(options map[interface{}]string) []Option

func (*Terminal) PromptOptionsSelect

func (t *Terminal) PromptOptionsSelect(options map[interface{}]string) Option

func (*Terminal) PromptSelect

func (t *Terminal) PromptSelect(prompt string, options []string) (int, string, error)

func (*Terminal) SetReader

func (t *Terminal) SetReader(reader io.Reader)

func (*Terminal) SetWriter

func (t *Terminal) SetWriter(writer io.Writer)

func (*Terminal) UpdateDimensions

func (t *Terminal) UpdateDimensions()

type TerminalInterface

type TerminalInterface interface {
	Prompt(prompt string) (string, error)
	PromptPassword(prompt string) (string, error)
	PromptConfirm(prompt string) (bool, error)
	PromptSelect(prompt string, options []string) (int, string, error)
	NewTable(percentage float64) *Table
}

Jump to

Keyboard shortcuts

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