widget

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package widget provides base user interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteBytes

func DeleteBytes(s []byte, offset, length int) []byte

DeleteBytes deletes bytes in offset position by length.

func EventToString

func EventToString(ev *tcell.EventKey) string

EventToString converts the keyboard intput event to string. A meta key input event returns prefixed `M-'.

func Fini

func Fini()

Fini finishes the tcell screen.

func HideCursor

func HideCursor()

HideCursor hides the cursor.

func Init

func Init()

Init initializes the tcell screen.

func InsertBytes

func InsertBytes(s, data []byte, offset int) []byte

InsertBytes inserts data to offset position.

func IsNil

func IsNil(w Widget) bool

IsNil returns whether nil widget.

func PollEvent

func PollEvent() tcell.Event

PollEvent polls input events.

func SetBorder

func SetBorder(v, h, ul, ur, ll, lr rune)

SetBorder sets window border runes.

func SetCells

func SetCells(x, y int, s string, style tcell.Style) (pos int)

SetCells sets a string to cells in a window and returns the last x position.

func Show

func Show()

Show setted cells.

func ShowCursor

func ShowCursor(x, y int)

ShowCursor shows the cursor at x, y.

func Size

func Size() (width, height int)

Size returns the tcell screen width and height.

func TruncLeft

func TruncLeft(s string, w int, head string) string

TruncLeft truncates a string with w cells for the left.

Types

type BorderStyle

type BorderStyle int

BorderStyle is a window border style.

const (
	// AllBorder is a style draws all lines and corners.
	AllBorder BorderStyle = iota
	// ULBorder is a style draws upper and lower lines.
	ULBorder
	// NoBorder dose not draw borders.
	NoBorder
)

type Drawer

type Drawer interface {
	Name() string
	Draw(x, y, width int, focus bool)
}

Drawer describes drawring for list box contents.

type Extmap

type Extmap map[string]map[string]func()

Extmap represents callback functions for the widget input event on specified conditions.

type Keymap

type Keymap map[string]func()

Keymap represents callback functions for the widget input event.

type ListBox

type ListBox struct {
	*Window
	// contains filtered or unexported fields
}

ListBox is a scrollable window listing contents.

func NewListBox

func NewListBox(x, y, width, height int, title string) *ListBox

NewListBox creates a new list box specified coordinates and sizes.

func (*ListBox) AdjustCursor

func (b *ListBox) AdjustCursor()

AdjustCursor adjusts the cursor within range of upper and lower.

func (*ListBox) AdjustOffset

func (b *ListBox) AdjustOffset()

AdjustOffset adjusts the offset within range of upper and lower.

func (*ListBox) AppendHighlightString

func (b *ListBox) AppendHighlightString(s, highlight string)

AppendHighlightString appends a new highlighted content by the string to the end.

func (*ListBox) AppendList

func (b *ListBox) AppendList(e ...Drawer)

AppendList appends new contents to the end.

func (*ListBox) AppendString

func (b *ListBox) AppendString(s ...string)

AppendString appends new contents by strings to the end.

func (*ListBox) ClearList

func (b *ListBox) ClearList()

ClearList empties the list.

func (*ListBox) Column

func (b *ListBox) Column() int

Column returns the column of the list box.

func (*ListBox) ColumnAdjustContentsWidth

func (b *ListBox) ColumnAdjustContentsWidth()

ColumnAdjustContentsWidth adjusts the column by list box constent widths. Fit to the widest content.

func (*ListBox) CurrentContent

func (b *ListBox) CurrentContent() Drawer

CurrentContent gets the content on the cursor.

func (*ListBox) Cursor

func (b *ListBox) Cursor() int

Cursor returns the current position of contents.

func (*ListBox) CursorDown

func (b *ListBox) CursorDown()

CursorDown moves the cursor to the down.

func (*ListBox) CursorToLeft

func (b *ListBox) CursorToLeft()

CursorToLeft moves the cursor to the left.

func (*ListBox) CursorToRight

func (b *ListBox) CursorToRight()

CursorToRight moves the cursor to the right.

func (*ListBox) CursorUp

func (b *ListBox) CursorUp()

CursorUp moves the cursor to the up.

func (*ListBox) Draw

func (b *ListBox) Draw()

Draw list box with title and scrollbar.

func (*ListBox) IndexByName

func (b *ListBox) IndexByName(name string) int

IndexByName returns the index to match content name.

func (*ListBox) IsEmpty

func (b *ListBox) IsEmpty() bool

IsEmpty reports whether the list empty.

func (*ListBox) Len

func (b *ListBox) Len() int

func (*ListBox) Less

func (b *ListBox) Less(i, j int) bool

func (*ListBox) List

func (b *ListBox) List() []Drawer

List returns contents in the list box.

func (*ListBox) Lower

func (b *ListBox) Lower() int

Lower returns a lower bound that the cursor can move.

func (*ListBox) MoveBottom

func (b *ListBox) MoveBottom()

MoveBottom moves cursor to index of upper list.

func (*ListBox) MoveCursor

func (b *ListBox) MoveCursor(amount int)

MoveCursor moves the cursor.

func (*ListBox) MoveTop

func (b *ListBox) MoveTop()

MoveTop moves cursor to index of lower list.

func (*ListBox) Offset

func (b *ListBox) Offset() int

Offset returns a top position to display.

func (*ListBox) PageDown

func (b *ListBox) PageDown()

PageDown moves cursor to next page.

func (*ListBox) PageUp

func (b *ListBox) PageUp()

PageUp moves cursor to previous page.

func (*ListBox) Scroll

func (b *ListBox) Scroll(amount int)

Scroll scrolls the list box.

func (*ListBox) ScrollRate

func (b *ListBox) ScrollRate() string

ScrollRate returns rate of offset.

func (*ListBox) SetColumn

func (b *ListBox) SetColumn(n int)

SetColumn sets the column.

func (*ListBox) SetCursor

func (b *ListBox) SetCursor(x int)

SetCursor sets the cursor.

func (*ListBox) SetCursorByName

func (b *ListBox) SetCursorByName(name string)

SetCursorByName sets the cursor by the content name.

func (*ListBox) SetList

func (b *ListBox) SetList(l []Drawer)

SetList sets contents to the list box.

func (*ListBox) SetLower

func (b *ListBox) SetLower(lb int)

SetLower sets the lower.

func (*ListBox) SetOffsetCenteredCursor

func (b *ListBox) SetOffsetCenteredCursor()

SetOffsetCenteredCursor sets the offset so that centred cursor.

func (*ListBox) SetTitle

func (b *ListBox) SetTitle(s string)

SetTitle sets the list box title.

func (*ListBox) Swap

func (b *ListBox) Swap(i, j int)

func (*ListBox) Title

func (b *ListBox) Title() string

Title returns the list box title.

func (*ListBox) Upper

func (b *ListBox) Upper() int

Upper returns an upper bound that the cursor can move.

type ProgressGauge

type ProgressGauge struct {
	*Window
	// contains filtered or unexported fields
}

ProgressGauge is a progress bar changing with time.

func NewProgressGauge

func NewProgressGauge(x, y, width, height int) *ProgressGauge

NewProgressGauge returns a new progress gauge specified coordinates and sizes.

func (*ProgressGauge) Draw

func (b *ProgressGauge) Draw()

Draw the progress gauge from start time to now and estimated time of arrival.

func (*ProgressGauge) Finish

func (b *ProgressGauge) Finish()

Finish the progress.

func (*ProgressGauge) IsFinished

func (b *ProgressGauge) IsFinished() bool

IsFinished reports whether finished.

func (*ProgressGauge) Start

func (b *ProgressGauge) Start(maxval float64)

Start the timer from now.

func (*ProgressGauge) Update

func (b *ProgressGauge) Update(value float64)

Update the current value.

type TextBox

type TextBox struct {
	*Window

	Edithook func()
	// contains filtered or unexported fields
}

TextBox is editable text box.

func NewTextBox

func NewTextBox(x, y, width, height int) *TextBox

NewTextBox returns the text box of specified size and coordinates.

func (*TextBox) BackwardChar

func (b *TextBox) BackwardChar()

BackwardChar move backwards the editing cursor only a character.

func (*TextBox) BackwardWord

func (b *TextBox) BackwardWord()

BackwardWord move backwards the editing cursor only a word.

func (*TextBox) Cursor

func (b *TextBox) Cursor() int

Cursor returns the editting visualized position.

func (*TextBox) DeleteBackwardChar

func (b *TextBox) DeleteBackwardChar()

DeleteBackwardChar deletes a character on backward of editing cursor.

func (*TextBox) DeleteBackwardWord

func (b *TextBox) DeleteBackwardWord()

DeleteBackwardWord deletes a word on backward of editing cursor.

func (*TextBox) DeleteChar

func (b *TextBox) DeleteChar()

DeleteChar deletes a character on editing cursor.

func (*TextBox) DeleteForwardWord

func (b *TextBox) DeleteForwardWord()

DeleteForwardWord deletes a word on forward of editing cursor.

func (*TextBox) ForwardChar

func (b *TextBox) ForwardChar()

ForwardChar move forwards the editing cursor only a character.

func (*TextBox) ForwardWord

func (b *TextBox) ForwardWord()

ForwardWord move forwards the editing cursor only a word.

func (*TextBox) InsertChar

func (b *TextBox) InsertChar(r rune)

InsertChar inserts a character to position on editing cursor.

func (*TextBox) InsertString

func (b *TextBox) InsertString(str string)

InsertString inserts string to position on editing cursor.

func (*TextBox) KillLine

func (b *TextBox) KillLine()

KillLine deletes text on backward of editing cursor in line.

func (*TextBox) KillLineAll

func (b *TextBox) KillLineAll()

KillLineAll deletes text in line.

func (*TextBox) MoveBottom

func (b *TextBox) MoveBottom()

MoveBottom sets cursor position to the bottom.

func (*TextBox) MoveCursor

func (b *TextBox) MoveCursor(offset int)

MoveCursor moves editing cursor.

func (*TextBox) MoveTop

func (b *TextBox) MoveTop()

MoveTop sets cursor position to the top.

func (*TextBox) SetText

func (b *TextBox) SetText(text string)

SetText replaces the new text.

func (*TextBox) String

func (b *TextBox) String() string

String returns the text as string.

func (*TextBox) TextAfterCursor

func (b *TextBox) TextAfterCursor() string

TextAfterCursor returns the text after the cursor.

func (*TextBox) TextBeforeCursor

func (b *TextBox) TextBeforeCursor() string

TextBeforeCursor returns the text before the cursor.

func (*TextBox) WidthTextAfterCursor

func (b *TextBox) WidthTextAfterCursor() int

WidthTextAfterCursor returns width of text after the cursor.

func (*TextBox) WidthTextBeforeCursor

func (b *TextBox) WidthTextBeforeCursor() int

WidthTextBeforeCursor returns width of text before the cursor.

type Widget

type Widget interface {
	// Viewer and controller
	Draw()            // sets cells to the terminal
	Input(key string) // the key event control

	// Connector
	Next() Widget // retruns a next widget for drawing and input
	Disconnect()  // disconnect reference to the next widget for exiting

	// Window
	Width() int
	Height() int
	LeftTop() (x, y int)
	RightBottom() (x, y int)
	LeftBottom() (x, y int)
	RightTop() (x, y int)
	Resize(x, y, width, height int)
	ResizeRelative(x, y, width, height int)
}

Widget describes a window manager in CUI.

func Nil

func Nil() Widget

Nil returns widget represent of nil.

type Window

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

Window represents a quadrangular on coordinates of x and y.

func NewWindow

func NewWindow(x, y, width, height int) *Window

NewWindow creates a new window specified coordinates and sizes.

func (*Window) Border

func (w *Window) Border()

Border draws a rectangular frame.

func (*Window) BorderLR

func (w *Window) BorderLR()

BorderLR draws left and right frames.

func (*Window) BorderStyle

func (w *Window) BorderStyle() BorderStyle

BorderStyle returns the border style.

func (*Window) BorderUL

func (w *Window) BorderUL()

BorderUL draws upper and lower frames.

func (*Window) Clear

func (w *Window) Clear()

Clear the window with blanks.

func (*Window) Draw

func (w *Window) Draw()

Draw the window to cells.

func (*Window) Height

func (w *Window) Height() int

Height returns the window height.

func (*Window) LeftBottom

func (w *Window) LeftBottom() (x, y int)

LeftBottom returns left bottom coordinates of the window.

func (*Window) LeftTop

func (w *Window) LeftTop() (x, y int)

LeftTop returns left top coordinates of the window.

func (*Window) Resize

func (w *Window) Resize(x, y, width, height int)

Resize the window to coordinates and sizes.

func (*Window) ResizeRelative

func (w *Window) ResizeRelative(x, y, width, height int)

ResizeRelative resizes relative to current sizes.

func (*Window) RightBottom

func (w *Window) RightBottom() (x, y int)

RightBottom returns right bottom coordinates of the window.

func (*Window) RightTop

func (w *Window) RightTop() (x, y int)

RightTop returns right top coordinates of the window.

func (*Window) SetBorderStyle

func (w *Window) SetBorderStyle(style BorderStyle)

SetBorderStyle sets the border style.

func (*Window) Width

func (w *Window) Width() int

Width returns the window width.

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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