terminal

package
v0.0.0-...-a99c618 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Log          = bdpan.GetLogger()
	StyleDefault = tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset)
	StyleSelect  = tcell.StyleDefault.Background(tcell.ColorDarkCyan).Foreground(tcell.ColorWhite)
)

Functions

func DrawLine

func DrawLine(s tcell.Screen, StartX, StartY int, style tcell.Style, text string)

绘制当行

func DrawText

func DrawText(s tcell.Screen, StartX, StartY, EndX, EndY int, style tcell.Style, text string) error

func FillString

func FillString(text string, width int) string

不够的部分使用空格填充

func OmitString

func OmitString(text string, maxWidth int) string

超出部分使用符号省略

Types

type Box

type Box struct {
	S            tcell.Screen
	StartX       int
	StartY       int
	EndX         int
	EndY         int
	Style        tcell.Style
	PaddingLeft  int
	PaddingRight int
}

func NewBox

func NewBox(s tcell.Screen, StartX, StartY, EndX, EndY int) *Box

func (*Box) Clean

func (b *Box) Clean() *Box

清除内容

func (*Box) Draw

func (b *Box) Draw()

func (*Box) DrawLineText

func (b *Box) DrawLineText(StartY int, style tcell.Style, text string)

绘制当行数据

func (*Box) DrawMultiLineText

func (b *Box) DrawMultiLineText(style tcell.Style, text []string)

绘制多行数据

func (*Box) DrawOneLineText

func (b *Box) DrawOneLineText(StartY int, style tcell.Style, text string)

绘制当行数据

func (*Box) DrawText

func (b *Box) DrawText(StartX, StartY int, style tcell.Style, text string)

绘制多行数据

func (*Box) FillOneLineText

func (b *Box) FillOneLineText(text string) string

一行的数据,不够的部分使用空格填充

func (Box) GetDrawRange

func (b Box) GetDrawRange() (StartX, StartY, EndX, EndY int)

可以绘制的返回

func (Box) Height

func (b Box) Height() int

高度

func (*Box) OmitOneLineText

func (b *Box) OmitOneLineText(text string) string

一行的数据,超出部分使用 ... 省略

func (*Box) SetPaddingLeft

func (b *Box) SetPaddingLeft(p int) *Box

func (Box) Width

func (b Box) Width() int

宽度

type Confirm

type Confirm struct {
	Box    *Box
	Text   string
	Ensure *ConfirmSelect
	Cancel *ConfirmSelect
	// contains filtered or unexported fields
}

func NewConfirm

func NewConfirm(t *Terminal, text string) *Confirm

func (*Confirm) Draw

func (c *Confirm) Draw() *Confirm

func (*Confirm) EnableCancel

func (c *Confirm) EnableCancel() *Confirm

func (*Confirm) EnableEnsure

func (c *Confirm) EnableEnsure() *Confirm

func (Confirm) IsEnsure

func (c Confirm) IsEnsure() bool

type ConfirmSelect

type ConfirmSelect struct {
	Text        string
	IsSelect    bool
	StyleSelect tcell.Style
}

func (ConfirmSelect) Style

func (s ConfirmSelect) Style() tcell.Style

type Help

type Help struct {
	Box   *Box
	Items []HelpItem
	// contains filtered or unexported fields
}

func NewHelp

func NewHelp(t *Terminal, items []HelpItem) *Help

func (*Help) Draw

func (h *Help) Draw() *Help

type HelpItem

type HelpItem struct {
	Runes     []rune
	Keys      []tcell.Key
	KeyString string
	Doc       string
}

func NewHelpItem

func NewHelpItem(r rune, doc string) HelpItem

func (HelpItem) AddKey

func (h HelpItem) AddKey(key tcell.Key) HelpItem

func (HelpItem) AddRune

func (h HelpItem) AddRune(r rune) HelpItem

func (HelpItem) SetKeyString

func (h HelpItem) SetKeyString(s string) HelpItem

func (HelpItem) String

func (h HelpItem) String() string

type List

type List struct {
	Box  *Box
	Data []string
	// contains filtered or unexported fields
}

func NewEmptyList

func NewEmptyList(t *Terminal, StartX, StartY, EndX, EndY int) *List

func NewList

func NewList(t *Terminal, StartX, StartY int, data []string) *List

func (*List) Draw

func (l *List) Draw() *List

func (*List) SetData

func (l *List) SetData(data []string) *List

func (*List) SetMaxWidth

func (l *List) SetMaxWidth() *List

func (*List) SetWidth

func (l *List) SetWidth(w int) *List

type Select

type Select struct {
	Box    *Box
	StartX int
	StartY int
	// MaxWidth  int
	// MaxHeight int
	Items []*SelectItem
	// 选中行的样式
	StyleSelect tcell.Style
	// 选中行索引
	SelectIndex int
	// 选中后的执行方法
	SelectFn func(*SelectItem)
	// 上下移动时光标固定的锚点
	AnchorIndex int
	// Items 为空时需要填充的数据
	EmptyFillText string
	LoadingText   string
	// contains filtered or unexported fields
}

func NewEmptySelect

func NewEmptySelect(t *Terminal, StartX, StartY, EndX, EndY int) *Select

func NewSelect

func NewSelect(t *Terminal, StartX, StartY int, items []*SelectItem) *Select

func (*Select) Draw

func (s *Select) Draw()

func (*Select) DrawLoading

func (s *Select) DrawLoading()

func (*Select) Filter

func (s *Select) Filter(filter string) *Select

func (*Select) GetDrawItems

func (s *Select) GetDrawItems(offset int) []*SelectItem

func (Select) GetSeleteItem

func (s Select) GetSeleteItem() *SelectItem

func (*Select) IsMoveEnd

func (s *Select) IsMoveEnd() bool

func (Select) Length

func (s Select) Length() int

func (*Select) MoveDownSelect

func (s *Select) MoveDownSelect(step int) (isChange bool)

func (*Select) MoveUpSelect

func (s *Select) MoveUpSelect(step int) (isChange bool)

func (*Select) SetAnchorIndex

func (s *Select) SetAnchorIndex(i int) *Select

func (*Select) SetEmptyFillText

func (s *Select) SetEmptyFillText(t string) *Select

func (*Select) SetItems

func (s *Select) SetItems(items []*SelectItem) *Select

func (*Select) SetLoadingText

func (s *Select) SetLoadingText(t string) *Select

func (*Select) SetSelectFn

func (s *Select) SetSelectFn(fn func(*SelectItem)) *Select

func (*Select) SetSelectIndex

func (s *Select) SetSelectIndex(i int) *Select

type SelectItem

type SelectItem struct {
	IsSelect bool
	Info     SelectItemInfo
}

type SelectItemInfo

type SelectItemInfo interface {
	String() string
	Name() string
}

type Terminal

type Terminal struct {
	S            tcell.Screen
	StyleDefault tcell.Style
}

func NewTerminal

func NewTerminal() (*Terminal, error)

func (*Terminal) DrawBox

func (t *Terminal) DrawBox(b Box) error

该方法会删除 建议使用 Box.Draw()

func (*Terminal) DrawLineText

func (t *Terminal) DrawLineText(StartX, StartY, MaxLineW int, style tcell.Style, text string) error

func (*Terminal) DrawOneLineText

func (t *Terminal) DrawOneLineText(StartY int, style tcell.Style, text string) error

func (*Terminal) DrawText

func (t *Terminal) DrawText(StartX, StartY, EndX, EndY int, style tcell.Style, text string) error

func (*Terminal) Exec

func (t *Terminal) Exec() error

func (*Terminal) NewBox

func (t *Terminal) NewBox(StartX, StartY, EndX, EndY int, Style tcell.Style) *Box

func (*Terminal) Quit

func (t *Terminal) Quit()

Jump to

Keyboard shortcuts

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