tui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTextEditor

func NewTextEditor() (*Tile, *Tile, *Box)

Common layout patterns

Types

type Blank

type Blank struct {
}

Blank is most simply implement of Control. Blank is provide empty region, and not draw content, and not update.

func (Blank) Draw

func (b Blank) Draw(g *Graphics)

Draw is do nothinng.

func (Blank) IsFlexibleHeight

func (b Blank) IsFlexibleHeight() bool

MinimumSize returns false.

func (Blank) IsFlexibleWidth

func (b Blank) IsFlexibleWidth() bool

MinimumSize returns false.

func (Blank) Layout

func (b Blank) Layout(w int, h int)

Layout is do nothinng.

func (Blank) MinimumSize

func (b Blank) MinimumSize(width int, height int) (Width int, Height int)

MinimumSize returns zero.

func (Blank) Move

func (b Blank) Move(x int, y int)

Move is do nothinng.

func (Blank) Traverse

func (b Blank) Traverse(fm *FocusManager)

Traverse is do nothinng.

func (Blank) Update

func (b Blank) Update()

Update is do nothinng.

type Box

type Box struct {
	Controls []Control
	// contains filtered or unexported fields
}

Box is layout sub controls by horizontal or vertical.

func NewHBox

func NewHBox(controls ...Control) *Box

Box creation utilities

func NewVBox

func NewVBox(controls ...Control) *Box

func WithSeparators

func WithSeparators(orientation Orientation, controls ...Control) *Box

Layout composition helpers

func (*Box) Draw

func (b *Box) Draw(g *Graphics)

Draw is delegate to sub controls.

func (*Box) GetOrientation

func (b *Box) GetOrientation() Orientation

GetOrientation returns orientation.

func (*Box) Init

func (b *Box) Init(orientation Orientation)

Init is initialize Box.

func (*Box) IsFlexibleHeight

func (b *Box) IsFlexibleHeight() bool

IsFlexibleHeight returns true if have to any flexible height controls.

func (*Box) IsFlexibleWidth

func (b *Box) IsFlexibleWidth() bool

IsFlexibleWidth returns true if have to any flexible width controls.

func (*Box) Layout

func (b *Box) Layout(width int, height int)

Layout is arrangement sub controls into line by horizontal or vertical.

func (*Box) MinimumSize

func (b *Box) MinimumSize(width int, height int) (Width int, Height int)

MinimumSize is calculate minimum size in consideration flex. flexible controls assigned evenly divided size of subtract static size from total size.

func (*Box) Move

func (b *Box) Move(x int, y int)

Move is move the base point of Box.

func (*Box) Traverse

func (b *Box) Traverse(fm *FocusManager)

Traverse is register sub controls into FocusManager by the array order.

func (*Box) Update

func (b *Box) Update()

Update is delegate to sub controls.

type Card

type Card struct {
	Controls []Control
	Index    int
}

Card is delegate to the which one of sub controls. uses to switch content like tab pane.

func (*Card) Draw

func (c *Card) Draw(g *Graphics)

Draw is delegate to current delegate target

func (*Card) Init

func (c *Card) Init(controls []Control)

Init is initialize Card.

func (*Card) IsFlexibleHeight

func (c *Card) IsFlexibleHeight() bool

IsFlexibleHeight is delegate to current delegate target

func (*Card) IsFlexibleWidth

func (c *Card) IsFlexibleWidth() bool

IsFlexibleWidth is delegate to current delegate target

func (*Card) Layout

func (c *Card) Layout(w int, h int)

Layout is delegate to current delegate target

func (*Card) MinimumSize

func (c *Card) MinimumSize(width int, height int) (Width int, Height int)

MinimumSize is delegate to current delegate target

func (*Card) Move

func (c *Card) Move(x int, y int)

Move is delegate to current delegate target

func (*Card) Next

func (c *Card) Next()

Next is show next sub control.

func (*Card) Prev

func (c *Card) Prev()

Prev is show previous sub control.

func (*Card) Target

func (c *Card) Target() Control

Target returns current delegate target.

func (*Card) Traverse

func (c *Card) Traverse(fm *FocusManager)

Traverse is delegate to current delegate target

func (*Card) Update

func (c *Card) Update()

Update is delegate to current delegate target

type Center

type Center struct {
	Control Control
	Width   int
	Height  int
	// contains filtered or unexported fields
}

Center is Control for centering.

func WithCenter

func WithCenter(ctrl Control, width int, height int) *Center

Center wrapper

func (*Center) Draw

func (c *Center) Draw(g *Graphics)

Draw is delegate to sub control.

func (*Center) IsFlexibleHeight

func (c *Center) IsFlexibleHeight() bool

IsFlexibleHeight returns false.

func (*Center) IsFlexibleWidth

func (c *Center) IsFlexibleWidth() bool

IsFlexibleWidth returns false.

func (*Center) Layout

func (c *Center) Layout(width int, height int)

Layout is align center sub control to parent.

func (*Center) MinimumSize

func (c *Center) MinimumSize(width int, height int) (Width int, Height int)

MinimumSize is provide Control minimum size with margin.

func (*Center) Move

func (c *Center) Move(x int, y int)

Move is delegate to sub control.

func (*Center) Traverse

func (c *Center) Traverse(fm *FocusManager)

Traverse is delegate to sub control.

func (*Center) Update

func (c *Center) Update()

Update is delegate to sub control.

type Clip

type Clip struct {
	Graphics *Graphics
	X        int
	Y        int
	Width    int
	Height   int
}

Clip is clipping specified region in Graphics.

func (Clip) SetContent

func (c Clip) SetContent(x int, y int, primary rune, combining []rune, style tcell.Style)

SetContent is set a character to specified cell, if not already settled. TODO: refactor

func (Clip) SetCursor

func (c Clip) SetCursor(x int, y int, primary rune, combining []rune, style tcell.Style)

SetCursor is set a character to specified cell. TODO: refactor

type Control

type Control = base.Control

Control is re-export from base.Control.

type Event

type Event = base.Event

Event is re-export from base.Event.

type FocusManager

type FocusManager = base.FocusManager

FocusManager is re-export from base.FocusManager.

type Frame

type Frame struct {
	Control Control
	// contains filtered or unexported fields
}

Frame is decorate to sub control by ascii frame.

func WithFrame

func WithFrame(ctrl Control) *Frame

Frame wrapper

func (*Frame) Draw

func (fr *Frame) Draw(g *Graphics)

Draw is draw sub control with ascii frame.

func (*Frame) IsFlexibleHeight

func (fr *Frame) IsFlexibleHeight() bool

IsFlexibleHeight is delegate to sub control.

func (*Frame) IsFlexibleWidth

func (fr *Frame) IsFlexibleWidth() bool

IsFlexibleWidth is delegate to sub control.

func (*Frame) Layout

func (fr *Frame) Layout(width int, height int)

Layout is offset the sub control by ascii frame.

func (*Frame) MinimumSize

func (fr *Frame) MinimumSize(width int, height int) (Width int, Height int)

func (*Frame) Move

func (fr *Frame) Move(x int, y int)

Move is move the base point of Frame.

func (*Frame) Traverse

func (fr *Frame) Traverse(fm *FocusManager)

Traverse is delegate to sub control.

func (*Frame) Update

func (fr *Frame) Update()

Update is delegate to sub control.

type Graphics

type Graphics = base.Graphics

Graphics is re-export from base.Graphics.

type Grid

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

Grid is layout sub controls into by lattice.

func NewGrid

func NewGrid(rows, cols int) *Grid

Grid utilities

func (*Grid) Draw

func (g *Grid) Draw(gg *Graphics)

Draw is delegate to sub controls.

func (*Grid) HeightTable

func (g *Grid) HeightTable(h int) []int

HeightTable returns height table by rows.

func (*Grid) Init

func (g *Grid) Init(rowCount int, columnCount int)

Init is initialize Grid.

func (*Grid) IsFlexibleHeight

func (g *Grid) IsFlexibleHeight() bool

IsFlexibleHeight returns false.

func (*Grid) IsFlexibleWidth

func (g *Grid) IsFlexibleWidth() bool

IsFlexibleWidth returns true.

func (*Grid) Layout

func (g *Grid) Layout(w int, h int)

Layout is layout sub controls into by lattice.

func (*Grid) MaxStaticHeight

func (g *Grid) MaxStaticHeight(row int) int

MaxStaticHeight returns maximum static height of specified column.

func (*Grid) MaxStaticWidth

func (g *Grid) MaxStaticWidth(column int) int

MaxStaticWidth returns maximum static width of specified column.

func (*Grid) MinimumSize

func (g *Grid) MinimumSize(width int, height int) (Width int, Height int)

MinimumSize returns size with border.

func (*Grid) Move

func (g *Grid) Move(x int, y int)

Move is move the base point of Grid.

func (*Grid) SetControl

func (g *Grid) SetControl(row int, column int, ctrl Control) *GridCell

SetControl is set the Control at specified cell.

func (*Grid) SetTile

func (g *Grid) SetTile(row int, column int, staticWidth int, staticHeight int, presenter TextPresenter) *GridCell

SetTile is set the Tile at specified cell.

func (*Grid) StaticColumns

func (g *Grid) StaticColumns(row int) int

StaticColumns returns count of columns have to static width.

func (*Grid) StaticRows

func (g *Grid) StaticRows(column int) int

StaticRows returns count of rows have to static height.

func (*Grid) StaticSize

func (g *Grid) StaticSize() (Width int, Height int)

StaticSize returns static size. the static size is total size of not flexible controls.

func (*Grid) Traverse

func (g *Grid) Traverse(fm *FocusManager)

Traverse is register sub controls into FocusManager by the array order.

func (*Grid) Update

func (g *Grid) Update()

Update is delegate to sub controls.

type GridCell

type GridCell struct {
	Control      Control
	StaticWidth  int
	StaticHeight int
	Width        int
	Height       int
}

GridCell is information of cell of grid.

type Layer

type Layer = base.Layer

Layer is re-export from base.Layer.

type Orientation

type Orientation int

Orientation is representation layout orientation by Horizontal either Vertical.

const (
	Horizontal Orientation = iota
	Vertical
)

type RepaintMessage

type RepaintMessage struct {
}

type Stack

type Stack struct {
	Layers []Layer
	Top    int
}

Stack is stack of layer.

func (*Stack) Draw

func (st *Stack) Draw(g *Graphics)

Draw is draw all layers or draw top layer only, if top layer's ClearBackground is true.

func (*Stack) Init

func (st *Stack) Init()

Init is initialize Stack.

func (*Stack) Layout

func (st *Stack) Layout(width int, height int)

Layout is layout all layers.

func (*Stack) MinimumSize

func (st *Stack) MinimumSize(width int, height int) (Width int, Height int)

MinimumSize returns maximum of minimum size of each layers.

func (*Stack) Traverse

func (st *Stack) Traverse(fm *FocusManager)

Traverse is delegate to top layer.

func (*Stack) Update

func (st *Stack) Update()

Update is update all layers or update top layer only, if top layer's ClearBackground is true.

type TextBox

type TextBox struct {
	Document   *model.Document
	X          int
	Y          int
	Width      int
	Height     int
	ShowCursor bool
	// contains filtered or unexported fields
}

TextBox is editable text widget. TextBox has region of rect, rendering text within that range. long line is always wrap at right end of region.

func (*TextBox) BreakIter

func (tb *TextBox) BreakIter() iter.Seq[presenter.Segment]

BreakIter returns segment array by line, in consideration a wrap.

func (*TextBox) CursorPosition

func (tb *TextBox) CursorPosition() (X int, Y int, Rune rune, Combine []rune)

CursorPosition returns position of cursor. TODO: refactor

func (*TextBox) CursorReset

func (tb *TextBox) CursorReset()

CursorReset is reset cursor position and scroll.

func (*TextBox) CursorUpdate

func (tb *TextBox) CursorUpdate()

CursorUpdate is scroll to until cursor visible

func (*TextBox) Draw

func (tb *TextBox) Draw(g *Graphics)

Draw is render content.

func (*TextBox) GetDocument

func (tb *TextBox) GetDocument() *model.Document

GetDocument returns Document.

func (*TextBox) GetHeight

func (tb *TextBox) GetHeight() int

GetHeight returns height of TextBox region.

func (*TextBox) GetScrollX

func (tb *TextBox) GetScrollX() int

GetScrollX returns scroll amount by horizontal.

func (*TextBox) GetScrollY

func (tb *TextBox) GetScrollY() int

GetScrollY returns scroll amount by vertical.

func (*TextBox) GetWidth

func (tb *TextBox) GetWidth() int

GetWidth returns width of TextBox region.

func (*TextBox) Init

func (tb *TextBox) Init()

Init is initialize TextBox.

func (*TextBox) TextClear

func (tb *TextBox) TextClear()

TextClear is do reset to content.

func (*TextBox) TextFrame

func (tb *TextBox) TextFrame()

TextFrame is print a frame of TextBox region.

func (*TextBox) TextHorizontal

func (tb *TextBox) TextHorizontal()

TextHorizontal is print horizontal line.

func (*TextBox) TextVertical

func (tb *TextBox) TextVertical()

TextVertical is print vertical line.

func (*TextBox) WrappedLineCount

func (tb *TextBox) WrappedLineCount() int

WrappedLineCount returns count of lines, in consideration a wrap.

type TextPresenter

type TextPresenter interface {
	// Present is set shown content to View.
	Present(view presenter.View)

	// Handle is process a event.
	Handle(view presenter.View, ev tcell.Event)

	// ShowCursor returns true if should be show cursor.
	ShowCursor() bool

	// IsFocusable returns true if should be capture the focus.
	IsFocusable() bool
}

TextPresenter is show fancy content through TextBox object. in example, show frame by text, show tree by text, etc. in addition, TextPresenter is define event process. input a string when event, or change selected item, or something.

type Tile

type Tile struct {
	TextBox       *TextBox
	TextPresenter TextPresenter

	MinimumWidth   int
	MinimumHeight  int
	FlexibleWidth  bool
	FlexibleHeight bool
}

Tile is implement of Control for TextBox.

func NewCenteredLabelTile

func NewCenteredLabelTile(text string) *Tile

func NewCustomListTile

func NewCustomListTile(items []string, cursorChar rune, prefix string) *Tile

func NewEditTile

func NewEditTile() *Tile

func NewFileTree

func NewFileTree(rootDir string, onFileOpen func(string)) *Tile

func NewFixedTile

func NewFixedTile(presenter TextPresenter, width, height int) *Tile

func NewFlexTile

func NewFlexTile(presenter TextPresenter) *Tile

func NewHorizontalSeparator

func NewHorizontalSeparator() *Tile

func NewLabelTile

func NewLabelTile(text string) *Tile

func NewListTile

func NewListTile(items []string) *Tile

func NewTile

func NewTile(presenter TextPresenter) *Tile

Tile creation utilities

func NewVerticalSeparator

func NewVerticalSeparator() *Tile

Separator utilities

func (*Tile) Draw

func (t *Tile) Draw(g *Graphics)

Draw is delegate to TextBox.

func (*Tile) Focus

func (t *Tile) Focus(on bool)

Focus is switch cursor visibility as needed.

func (*Tile) Handle

func (t *Tile) Handle(ev Event)

Handle is delegate to TextPresenter.

func (*Tile) Init

func (t *Tile) Init()

Init is initialize Tile.

func (*Tile) IsFlexibleHeight

func (t *Tile) IsFlexibleHeight() bool

IsFlexibleHeight returns Tile fields to direct.

func (*Tile) IsFlexibleWidth

func (t *Tile) IsFlexibleWidth() bool

IsFlexibleWidth returns Tile fields to direct.

func (*Tile) Layout

func (t *Tile) Layout(w int, h int)

Layout is resize the TextBox.

func (*Tile) MinimumSize

func (t *Tile) MinimumSize(width int, height int) (Width int, Height int)

MinimumSize returns Tile fields to direct.

func (*Tile) Move

func (t *Tile) Move(x int, y int)

Move is move the TextBox.

func (*Tile) Traverse

func (t *Tile) Traverse(fm *FocusManager)

Traverse is register TextBox to FocusManager.

func (*Tile) Update

func (t *Tile) Update()

Update is delegate to TextPresenter.

type Window

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

Window is basic implementation of base.Runtime

func (*Window) BeginBackground

func (w *Window) BeginBackground()

BeginBackground is increment number of background tasks. Runtime is ignore events while zero than bigger of number of background tasks.

func (*Window) Blit

func (w *Window) Blit(width int, height int)

Blit is render the layer into terminal.

func (*Window) DoInBackground

func (w *Window) DoInBackground() bool

DoInBackground returns true if number of background tasks is zero than bigger.

func (*Window) EndBackground

func (w *Window) EndBackground()

EndBackground is decrement number of background tasks.

func (*Window) FocusNext

func (w *Window) FocusNext()

FocusNext is move focus to next.

func (*Window) FocusPrev

func (w *Window) FocusPrev()

FocusPrev is move focus to previous.

func (*Window) GetLayerCount

func (w *Window) GetLayerCount() int

GetLayerCount returns count of layers.

func (*Window) Handle

func (w *Window) Handle(ev Event)

Handle is process the event by focused control.

func (*Window) Init

func (w *Window) Init(s tcell.Screen, width int, height int)

Init is initialize Window.

func (*Window) Pop

func (w *Window) Pop(returnCode int)

Pop is pop the layer from stack.

func (*Window) Push

func (w *Window) Push(layer Layer)

Push is push the layer to stack.

func (*Window) Repaint

func (w *Window) Repaint()

Repaint is do request rerender terminal.

func (*Window) Resize

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

Resize is resize layers.

func (*Window) Top

func (w *Window) Top() Control

Top returns Control of top layer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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