ui

package
v0.0.0-...-25dfc2e Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTheme = Theme{
	"Normal":              tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
	"Button":              tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
	"InputField":          tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
	"MenuBar":             tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorDarkGray),
	"MenuBarFocused":      tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorLightGray),
	"Menu":                tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
	"MenuSelected":        tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
	"TabContainer":        tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
	"TabContainerFocused": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
	"TextEdit":            tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
	"TextEditSelected":    tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
	"Window":              tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorDarkGray),
	"WindowHeader":        tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
}

DefaultTheme uses only the first 16 colors present in most colored terminals.

Functions

func Clamp

func Clamp(v, a, b int) int

Clamp keeps `v` within `a` and `b` numerically. `a` must be smaller than `b`. Returns clamped `v`.

func DrawQuickCharStr

func DrawQuickCharStr(s tcell.Screen, x, y int, str string, quickCharIdx int, style tcell.Style) int

DrawQuickCharStr renders a string very similar to how DrawStr works, but stylizes the quick char (the rune at `quickCharIdx`) with an underline. Returned is the number of columns that were drawn to the screen.

func DrawRect

func DrawRect(s tcell.Screen, x, y, width, height int, char rune, style tcell.Style)

DrawRect renders a filled box at `x` and `y`, of size `width` and `height`. Will not call `Show()`.

func DrawRectOutline

func DrawRectOutline(s tcell.Screen, x, y, _width, _height int, ul, ur, bl, br, hor, vert rune, style tcell.Style)

DrawRectOutline draws only the outline of a rectangle, using `ul`, `ur`, `bl`, and `br` for the corner runes, and `hor` and `vert` for the horizontal and vertical runes, respectively.

func DrawRectOutlineDefault

func DrawRectOutlineDefault(s tcell.Screen, x, y, width, height int, style tcell.Style)

DrawRectOutlineDefault calls DrawRectOutline with the default edge runes.

func DrawStr

func DrawStr(s tcell.Screen, x, y int, str string, style tcell.Style) int

DrawStr will render each character of a string at `x` and `y`. Returned is the number of columns that were drawn to the screen.

func DrawWindow

func DrawWindow(s tcell.Screen, x, y, width, height int, title string, theme *Theme)

DrawWindow draws a window-like object at x and y as the top-left corner. This window has an optional title. The Theme values "WindowHeader" and "Window" are used.

func Max

func Max(a, b int) int

Max returns the larger integer.

func Min

func Min(a, b int) int

Min returns the smaller integer.

func QuickCharInString

func QuickCharInString(s string, idx int) rune

QuickCharInString is used for finding the "quick char" in a string. The rune is always made lowercase. A rune of value zero is returned if the index was less than zero, or greater or equal to, the number of runes in s.

Types

type Align

type Align uint8

Align defines the text alignment of a label.

const (
	// AlignLeft is the normal text alignment where text is aligned to the left
	// of its bounding box.
	AlignLeft Align = iota
	// AlignRight causes text to be aligned to the right of its bounding box.
	AlignRight
	// AlignJustify causes text to be left-aligned, but also spaced so that it
	// fits the entire box where it is being rendered.
	AlignJustify
)

type Button

type Button struct {
	Text     string
	Callback func()
	// contains filtered or unexported fields
}

func NewButton

func NewButton(text string, theme *Theme, callback func()) *Button

func (*Button) Draw

func (b *Button) Draw(s tcell.Screen)

func (*Button) GetMinSize

func (b *Button) GetMinSize() (int, int)

func (*Button) GetPos

func (c *Button) GetPos() (int, int)

func (*Button) GetSize

func (b *Button) GetSize() (int, int)

func (*Button) HandleEvent

func (b *Button) HandleEvent(event tcell.Event) bool

func (*Button) SetFocused

func (c *Button) SetFocused(v bool)

func (*Button) SetPos

func (c *Button) SetPos(x, y int)

func (*Button) SetSize

func (b *Button) SetSize(width, height int)

func (*Button) SetTheme

func (c *Button) SetTheme(theme *Theme)

type Component

type Component interface {
	// A component knows its position and size, which is used to draw itself in
	// its bounding rectangle.
	Draw(tcell.Screen)
	// Components can be focused, which may affect how it handles events or draws.
	// For example, when a button is focused, the Return key may be pressed to
	// activate the button.
	SetFocused(bool)
	// Applies the theme to the component and all of its children.
	SetTheme(*Theme)

	// Get position of the Component.
	GetPos() (x, y int)
	// Set position of the Component.
	SetPos(x, y int)

	// Returns the smallest size the Component can be.
	GetMinSize() (w, h int)
	// Get size of the Component.
	GetSize() (w, h int)
	// Set size of the component. If size is smaller than minimum, minimum is
	// used, instead.
	SetSize(w, h int)

	// HandleEvent tells the Component to handle the provided event. The Component
	// should only handle events if it is focused. An event can optionally be
	// handled. If an event is handled, the function should return true. If the
	// event went unhandled, the function should return false.
	HandleEvent(tcell.Event) bool
}

A Component refers generally to the behavior of a UI "component". Components include buttons, input fields, and labels. It is expected that after constructing a component, to call the SetPos() function, and possibly SetSize() as well.

Many components implement their own `New...()` function. In those constructor functions, it is good practice for that component to set its size to be its minimum size.

type FileSelectorDialog

type FileSelectorDialog struct {
	Title               string
	MustExist           bool           // Whether the dialog should have a user select an existing file.
	FilesChosenCallback func([]string) // Returns slice of filenames selected. nil if user canceled.
	// contains filtered or unexported fields
}

A FileSelectorDialog is a WindowContainer with an input and buttons for selecting files. It can be used to open zero or more existing files, or select one non-existant file (for saving).

func NewFileSelectorDialog

func NewFileSelectorDialog(screen *tcell.Screen, title string, mustExist bool, theme *Theme, filesChosenCallback func([]string), cancelCallback func()) *FileSelectorDialog

func (*FileSelectorDialog) Draw

func (d *FileSelectorDialog) Draw(s tcell.Screen)

func (*FileSelectorDialog) GetMinSize

func (d *FileSelectorDialog) GetMinSize() (int, int)

func (*FileSelectorDialog) GetPos

func (c *FileSelectorDialog) GetPos() (int, int)

func (*FileSelectorDialog) GetSize

func (c *FileSelectorDialog) GetSize() (int, int)

func (*FileSelectorDialog) HandleEvent

func (d *FileSelectorDialog) HandleEvent(event tcell.Event) bool

func (*FileSelectorDialog) SetCancelCallback

func (d *FileSelectorDialog) SetCancelCallback(callback func())

func (*FileSelectorDialog) SetFocused

func (d *FileSelectorDialog) SetFocused(v bool)

func (*FileSelectorDialog) SetPos

func (d *FileSelectorDialog) SetPos(x, y int)

func (*FileSelectorDialog) SetSize

func (d *FileSelectorDialog) SetSize(width, height int)

func (*FileSelectorDialog) SetTheme

func (d *FileSelectorDialog) SetTheme(theme *Theme)

type InputField

type InputField struct {
	Buffer []byte
	// contains filtered or unexported fields
}

An InputField is a single-line input box.

func NewInputField

func NewInputField(screen *tcell.Screen, placeholder []byte, style tcell.Style) *InputField

func (*InputField) Delete

func (f *InputField) Delete(forward bool)

func (*InputField) Draw

func (f *InputField) Draw(s tcell.Screen)

func (*InputField) GetCursorPos

func (f *InputField) GetCursorPos() int

func (*InputField) GetMinSize

func (c *InputField) GetMinSize() (int, int)

func (*InputField) GetPos

func (c *InputField) GetPos() (int, int)

func (*InputField) GetSize

func (c *InputField) GetSize() (int, int)

func (*InputField) HandleEvent

func (f *InputField) HandleEvent(event tcell.Event) bool

func (*InputField) Insert

func (f *InputField) Insert(contents []byte)

func (*InputField) SetCursorPos

func (f *InputField) SetCursorPos(offset int)

SetCursorPos sets the cursor position offset. Offset is clamped to possible values. The InputField is scrolled to show the new cursor position. The offset is in runes.

func (*InputField) SetFocused

func (f *InputField) SetFocused(v bool)

func (*InputField) SetPos

func (c *InputField) SetPos(x, y int)

func (*InputField) SetSize

func (c *InputField) SetSize(width, height int)

func (*InputField) SetStyle

func (f *InputField) SetStyle(style tcell.Style)

func (*InputField) SetTheme

func (c *InputField) SetTheme(theme *Theme)

func (*InputField) String

func (f *InputField) String() string

type Item

type Item interface {
	GetName() string
	// Returns a character/rune index of the name of the item.
	GetQuickCharIdx() int
	// A Shortcut is a string of the modifiers+key name of the action that must be pressed
	// to trigger the shortcut. For example: "Ctrl+Alt+X". The order of the modifiers is
	// very important. Letters are case-sensitive. See the KeyEvent.Name() function of tcell
	// for information. An empty string implies no shortcut.
	GetShortcut() string
}

Item is an interface implemented by ItemEntry and ItemMenu to be listed in Menus.

type ItemEntry

type ItemEntry struct {
	Name      string
	QuickChar int // Character/rune index of Name
	Shortcut  string
	Callback  func()
}

ItemEntry is a listing in a Menu with a name and callback.

func (*ItemEntry) GetName

func (i *ItemEntry) GetName() string

GetName returns the name of the ItemEntry.

func (*ItemEntry) GetQuickCharIdx

func (i *ItemEntry) GetQuickCharIdx() int

func (*ItemEntry) GetShortcut

func (i *ItemEntry) GetShortcut() string

type ItemSeparator

type ItemSeparator struct{}

An ItemSeparator is like a blank Item that cannot actually be selected. It is useful for separating items in a Menu.

func (*ItemSeparator) GetName

func (i *ItemSeparator) GetName() string

GetName returns an empty string.

func (*ItemSeparator) GetQuickCharIdx

func (i *ItemSeparator) GetQuickCharIdx() int

func (*ItemSeparator) GetShortcut

func (i *ItemSeparator) GetShortcut() string

type Label

type Label struct {
	Text      string
	Alignment Align
	// contains filtered or unexported fields
}

A Label is a component for rendering text. Text can be rendered easily without a Label, but this component forces the text to fit within its bounding box and allows for left-align, right-align, and justify.

func (*Label) GetMinSize

func (c *Label) GetMinSize() (int, int)

func (*Label) GetPos

func (c *Label) GetPos() (int, int)

func (*Label) GetSize

func (c *Label) GetSize() (int, int)

func (*Label) SetFocused

func (c *Label) SetFocused(v bool)

func (*Label) SetPos

func (c *Label) SetPos(x, y int)

func (*Label) SetSize

func (c *Label) SetSize(width, height int)

func (*Label) SetTheme

func (c *Label) SetTheme(theme *Theme)
type Menu struct {
	Name      string
	QuickChar int // Character/rune index of Name
	Items     []Item
	// contains filtered or unexported fields
}

A Menu contains one or more ItemEntry or ItemMenus.

func NewMenu

func NewMenu(name string, quickChar int, theme *Theme) *Menu

New creates a new Menu. `items` can be `nil`.

func (m *Menu) ActivateItemUnderCursor()
func (m *Menu) AddItem(item Item)
func (m *Menu) AddItems(items []Item)
func (m *Menu) CursorDown()
func (m *Menu) CursorUp()
func (m *Menu) Draw(s tcell.Screen)

Draw renders the Menu at its position.

func (m *Menu) GetMinSize() (int, int)
func (m *Menu) GetName() string

GetName returns the name of the Menu.

func (c *Menu) GetPos() (int, int)
func (m *Menu) GetQuickCharIdx() int
func (m *Menu) GetShortcut() string
func (m *Menu) GetSize() (int, int)

GetSize returns the size of the Menu.

func (m *Menu) HandleEvent(event tcell.Event) bool

HandleEvent will handle events for a Menu and may propogate them to sub-menus. Returns true if the event was handled.

func (m *Menu) SetFocused(v bool)

SetFocused does not do anything for a Menu.

func (c *Menu) SetPos(x, y int)
func (m *Menu) SetSize(width, height int)

SetSize sets the size of the Menu.

func (c *Menu) SetTheme(theme *Theme)
type MenuBar struct {
	// contains filtered or unexported fields
}

A MenuBar is a horizontal list of menus.

func NewMenuBar

func NewMenuBar(theme *Theme) *MenuBar
func (b *MenuBar) ActivateMenuUnderCursor()
func (b *MenuBar) AddMenu(menu *Menu)
func (b *MenuBar) CursorLeft()
func (b *MenuBar) CursorRight()
func (b *MenuBar) Draw(s tcell.Screen)

Draw renders the MenuBar and its sub-menus.

func (b *MenuBar) GetMenuXPos(idx int) int

GetMenuXPos returns the X position of the name of Menu at `idx` visually.

func (b *MenuBar) GetMinSize() (int, int)
func (c *MenuBar) GetPos() (int, int)
func (c *MenuBar) GetSize() (int, int)
func (b *MenuBar) HandleEvent(event tcell.Event) bool

HandleEvent will propogate events to sub-menus and returns true if any of them handled the event.

func (b *MenuBar) SetFocused(v bool)

SetFocused highlights the MenuBar and focuses any sub-menus.

func (c *MenuBar) SetPos(x, y int)
func (c *MenuBar) SetSize(width, height int)
func (c *MenuBar) SetTheme(theme *Theme)

type MessageDialog

type MessageDialog struct {
	Title    string
	Kind     MessageDialogKind
	Callback func(string)
	// contains filtered or unexported fields
}

func NewMessageDialog

func NewMessageDialog(title string, message string, kind MessageDialogKind, options []string, theme *Theme, callback func(string)) *MessageDialog

func (*MessageDialog) Draw

func (d *MessageDialog) Draw(s tcell.Screen)

func (*MessageDialog) GetMinSize

func (d *MessageDialog) GetMinSize() (int, int)

func (*MessageDialog) GetPos

func (c *MessageDialog) GetPos() (int, int)

func (*MessageDialog) GetSize

func (c *MessageDialog) GetSize() (int, int)

func (*MessageDialog) HandleEvent

func (d *MessageDialog) HandleEvent(event tcell.Event) bool

func (*MessageDialog) SetFocused

func (d *MessageDialog) SetFocused(v bool)

func (*MessageDialog) SetMessage

func (d *MessageDialog) SetMessage(message string)

func (*MessageDialog) SetPos

func (c *MessageDialog) SetPos(x, y int)

func (*MessageDialog) SetSize

func (d *MessageDialog) SetSize(width, height int)

func (*MessageDialog) SetTheme

func (d *MessageDialog) SetTheme(theme *Theme)

type MessageDialogKind

type MessageDialogKind uint8
const (
	MessageKindNormal MessageDialogKind = iota
	MessageKindWarning
	MessageKindError
)

type Panel

type Panel struct {
	Parent  *Panel
	Left    Component
	Right   Component
	SplitAt int
	Kind    PanelKind
	// contains filtered or unexported fields
}

A Panel represents a container for a split view between two items. The Kind tells how to interpret the Left and Right fields. The SplitAt is the column between 0 and width or height, representing the position of the split between the Left and Right, respectively.

If the Kind is equal to PanelKindEmpty, then both Left and Right are nil. If the Kind is equal to PanelKindSingle, then only Left has value,

and its value will NOT be of type Panel. The SplitAt will not be used,
as the Left will take up the whole space.

If the Kind is equal to PanelKindSplitVert, then both Left and Right will

have value, and they will both have to be of type Panel. The split will
be represented vertically, and the SplitAt spans 0 to height; top to bottom,
respectively.

If the Kind is equal to PanelKindSplitHor, then both Left and Right will

have value, and they will both have to be of type Panel. The split will
be represented horizontally, and the SplitAt spans 0 to width; left to right.

func (*Panel) Draw

func (p *Panel) Draw(s tcell.Screen)

func (*Panel) EachLeaf

func (p *Panel) EachLeaf(rightMost bool, f func(*Panel) bool)

EachLeaf visits the entire tree, and calls function `f` at each leaf Panel. If the function `f` returns true, then visiting stops. if `rtl` is true, the tree is traversed in right-most order. The default is to traverse in left-most order.

The caller of this function can safely assert that Panel's Kind is always either `PanelKindSingle` or `PanelKindEmpty`.

func (*Panel) GetMinSize

func (p *Panel) GetMinSize() (int, int)

GetMinSize returns the combined minimum sizes of the Panel's children.

func (*Panel) GetPos

func (c *Panel) GetPos() (int, int)

func (*Panel) GetSize

func (c *Panel) GetSize() (int, int)

func (*Panel) HandleEvent

func (p *Panel) HandleEvent(event tcell.Event) bool

HandleEvent propogates the event to all children, calling HandleEvent() on left-most items. As usual: returns true if handled, false if unhandled. This function relies on the behavior of the child Components to only handle events if they are focused.

func (*Panel) IsLeaf

func (p *Panel) IsLeaf() bool

IsLeaf returns whether the Panel is a leaf or not. A leaf is a panel with Kind `PanelKindEmpty` or `PanelKindSingle`.

func (*Panel) SetFocused

func (p *Panel) SetFocused(v bool)

SetFocused sets this Panel's Focused field to `v`. Then, if the Panel's Kind is PanelKindSingle, it sets its child (not a Panel) focused to `v`, also.

func (*Panel) SetPos

func (c *Panel) SetPos(x, y int)

func (*Panel) SetSize

func (p *Panel) SetSize(width, height int)

SetSize sets the Panel size to the given width, and height. It will not check against GetMinSize() because it may be costly to do so. SetSize clamps the Panel's SplitAt to be within the new size of the Panel.

func (*Panel) SetTheme

func (p *Panel) SetTheme(theme *Theme)

func (*Panel) UpdateSplits

func (p *Panel) UpdateSplits()

UpdateSplits uses the position and size of the Panel, along with its Weight and Kind, to appropriately size and place its children. It calls UpdateSplits() on its child Panels.

type PanelContainer

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

func NewPanelContainer

func NewPanelContainer(theme *Theme) *PanelContainer

func (*PanelContainer) ClearSelected

func (c *PanelContainer) ClearSelected() Component

ClearSelected makes the selected Panel empty, but does not delete it from the tree.

func (*PanelContainer) DeleteSelected

func (c *PanelContainer) DeleteSelected() Component

DeleteSelected deletes the selected Panel and returns its child Component. If the selected Panel is the root Panel, ClearSelected() is called, instead.

func (*PanelContainer) Draw

func (c *PanelContainer) Draw(s tcell.Screen)

func (*PanelContainer) FloatSelected

func (c *PanelContainer) FloatSelected()

FloatSelected makes the selected Panel floating. This function does not focus the newly floated Panel. To focus the floating panel, call SetFloatingFocused().

func (*PanelContainer) GetFloatingFocused

func (c *PanelContainer) GetFloatingFocused() bool

GetFloatingFocused returns true if a floating window is selected or focused.

func (*PanelContainer) GetMinSize

func (c *PanelContainer) GetMinSize() (int, int)

func (*PanelContainer) GetPos

func (c *PanelContainer) GetPos() (int, int)

func (*PanelContainer) GetSelected

func (c *PanelContainer) GetSelected() Component

func (*PanelContainer) GetSize

func (c *PanelContainer) GetSize() (int, int)

func (*PanelContainer) HandleEvent

func (c *PanelContainer) HandleEvent(event tcell.Event) bool

func (*PanelContainer) IsRootSelected

func (c *PanelContainer) IsRootSelected() bool

func (*PanelContainer) SelectNext

func (c *PanelContainer) SelectNext()

func (*PanelContainer) SelectPrev

func (c *PanelContainer) SelectPrev()

func (*PanelContainer) SetFloatingFocused

func (c *PanelContainer) SetFloatingFocused(v bool) bool

SetFloatingFocused sets whether the floating Panels are focused. When true, the current Panel will be unselected and the front floating Panel will become the new selected if there any floating windows. If false, the same, but the last selected non-floating Panel will become focused.

The returned boolean is whether floating windows were able to be focused. If there are no floating windows when trying to focus them, this will inevitably return false, for example.

func (*PanelContainer) SetFocused

func (c *PanelContainer) SetFocused(v bool)

func (*PanelContainer) SetPos

func (c *PanelContainer) SetPos(x, y int)

func (*PanelContainer) SetSelected

func (c *PanelContainer) SetSelected(item Component)

func (*PanelContainer) SetSize

func (c *PanelContainer) SetSize(width, height int)

func (*PanelContainer) SetTheme

func (c *PanelContainer) SetTheme(theme *Theme)

func (*PanelContainer) SplitSelected

func (c *PanelContainer) SplitSelected(kind SplitKind, item Component)

SplitSelected splits the selected Panel with the given Component `item`. The type of split (vertical or horizontal) is determined with the `kind`. If `item` is nil, the new Panel will be of kind empty.

func (*PanelContainer) SwapNeighborsSelected

func (c *PanelContainer) SwapNeighborsSelected()

SwapNeighborsSelected swaps two Left and Right child Panels of a vertical or horizontally split Panel. This is necessary to achieve a "split top" or "split left" effect, as Panels only split open to the bottom or right.

func (*PanelContainer) UnfloatSelected

func (c *PanelContainer) UnfloatSelected(kind SplitKind) bool

UnfloatSelected moves any selected floating Panel to the normal tree that is accessible in the standard focus mode. This function will cause focus to go to the normal tree if there are no remaining floating windows after the operation.

Like SetFloatingFocused(), the boolean returned is whether the PanelContainer is focusing floating windows after the operation.

type PanelKind

type PanelKind uint8

A PanelKind describes how to interpret the fields of a Panel.

const (
	PanelKindEmpty     PanelKind = iota
	PanelKindSingle              // Single item. Takes up all available space
	PanelKindSplitVert           // Items are above or below eachother
	PanelKindSplitHor            // Items are left or right of eachother
)

type SplitKind

type SplitKind uint8
const (
	SplitVertical SplitKind = SplitKind(PanelKindSplitVert) + iota
	SplitHorizontal
)

type Tab

type Tab struct {
	Name  string
	Child Component
}

A Tab is a child of a TabContainer; has a name and child Component.

type TabContainer

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

A TabContainer organizes children by showing only one of them at a time.

func NewTabContainer

func NewTabContainer(theme *Theme) *TabContainer

func (*TabContainer) AddTab

func (c *TabContainer) AddTab(name string, child Component)

func (*TabContainer) Draw

func (c *TabContainer) Draw(s tcell.Screen)

Draw will draws the border of the BoxContainer, then it draws its child component.

func (*TabContainer) FocusTab

func (c *TabContainer) FocusTab(idx int)

FocusTab sets the visible tab to the one at `idx`. FocusTab clamps `idx` between 0 and tab_count - 1. If no tabs are present, the function does nothing.

func (*TabContainer) GetMinSize

func (c *TabContainer) GetMinSize() (int, int)

func (*TabContainer) GetPos

func (c *TabContainer) GetPos() (int, int)

func (*TabContainer) GetSelectedTabIdx

func (c *TabContainer) GetSelectedTabIdx() int

func (*TabContainer) GetSize

func (c *TabContainer) GetSize() (int, int)

func (*TabContainer) GetTab

func (c *TabContainer) GetTab(idx int) *Tab

func (*TabContainer) GetTabCount

func (c *TabContainer) GetTabCount() int

func (*TabContainer) HandleEvent

func (c *TabContainer) HandleEvent(event tcell.Event) bool

HandleEvent forwards the event to the child Component and returns whether it was handled.

func (*TabContainer) RemoveTab

func (c *TabContainer) RemoveTab(idx int) bool

RemoveTab deletes the tab at `idx`. Returns true if the tab was found, false otherwise.

func (*TabContainer) SetFocused

func (c *TabContainer) SetFocused(v bool)

SetFocused calls SetFocused on the visible child Component.

func (*TabContainer) SetPos

func (c *TabContainer) SetPos(x, y int)

SetPos sets the position of the container and updates the child Component.

func (*TabContainer) SetSize

func (c *TabContainer) SetSize(width, height int)

SetSize sets the size of the container and updates the size of the child Component.

func (*TabContainer) SetTheme

func (c *TabContainer) SetTheme(theme *Theme)

SetTheme sets the theme.

type TextEdit

type TextEdit struct {
	Buffer      buffer.Buffer
	Highlighter *buffer.Highlighter
	LineNumbers bool   // Whether to render line numbers (and therefore the column)
	Dirty       bool   // Whether the buffer has been edited
	UseHardTabs bool   // When true, tabs are '\t'
	TabSize     int    // How many spaces to indent by
	IsCRLF      bool   // Whether the file's line endings are CRLF (\r\n) or LF (\n)
	FilePath    string // Will be empty if the file has not been saved yet
	// contains filtered or unexported fields
}

TextEdit is a field for line-based editing. It features syntax highlighting tools, is autocomplete ready, and contains the various information about content being edited.

func NewTextEdit

func NewTextEdit(screen *tcell.Screen, filePath string, contents []byte, theme *Theme) *TextEdit

New will initialize the buffer using the given 'contents'. If the 'filePath' or 'FilePath' is empty, it can be assumed that the TextEdit has no file association, or it is unsaved.

func (*TextEdit) ChangeLineDelimiters

func (t *TextEdit) ChangeLineDelimiters(crlf bool)

Changes a file's line delimiters. If `crlf` is true, then line delimiters are replaced with Windows CRLF (\r\n). If `crlf` is false, then line delimtiers are replaced with Unix LF (\n). The TextEdit `IsCRLF` variable is updated with the new value.

func (*TextEdit) Delete

func (t *TextEdit) Delete(forwards bool)

Delete with `forwards` false will backspace, destroying the character before the cursor, while Delete with `forwards` true will delete the character after (or on) the cursor. In insert mode, forwards is always true.

func (*TextEdit) Draw

func (t *TextEdit) Draw(s tcell.Screen)

Draw renders the TextEdit component.

func (*TextEdit) GetCursor

func (t *TextEdit) GetCursor() buffer.Cursor

func (*TextEdit) GetLineDelimiter

func (t *TextEdit) GetLineDelimiter() string

GetLineDelimiter returns "\r\n" for a CRLF buffer, or "\n" for an LF buffer.

func (*TextEdit) GetMinSize

func (c *TextEdit) GetMinSize() (int, int)

func (*TextEdit) GetPos

func (c *TextEdit) GetPos() (int, int)

func (*TextEdit) GetSelectedBytes

func (t *TextEdit) GetSelectedBytes() []byte

GetSelectedBytes returns a byte slice of the region of the buffer that is currently selected. If the returned string is empty, then nothing was selected. The slice returned may or may not be a copy of the buffer, so do not write to it.

func (*TextEdit) GetSize

func (c *TextEdit) GetSize() (int, int)

func (*TextEdit) HandleEvent

func (t *TextEdit) HandleEvent(event tcell.Event) bool

HandleEvent allows the TextEdit to handle `event` if it chooses, returns whether the TextEdit handled the event.

func (*TextEdit) Insert

func (t *TextEdit) Insert(contents string)

Writes `contents` at the cursor position. Line delimiters and tab character supported. Any other control characters will be printed. Overwrites any active selection.

func (*TextEdit) ScrollToCursor

func (t *TextEdit) ScrollToCursor()

Scroll the screen if the cursor is out of view.

func (*TextEdit) SetContents

func (t *TextEdit) SetContents(contents []byte)

SetContents applies the string to the internal buffer of the TextEdit component. The string is determined to be either CRLF or LF based on line-endings.

func (*TextEdit) SetCursor

func (t *TextEdit) SetCursor(newCursor buffer.Cursor)

func (*TextEdit) SetFocused

func (t *TextEdit) SetFocused(v bool)

SetFocused sets whether the TextEdit is focused. When focused, the cursor is set visible and its position is updated on every event.

func (*TextEdit) SetPos

func (c *TextEdit) SetPos(x, y int)

func (*TextEdit) SetSize

func (c *TextEdit) SetSize(width, height int)

func (*TextEdit) SetTheme

func (c *TextEdit) SetTheme(theme *Theme)

type Theme

type Theme map[string]tcell.Style

A Theme is a map of string names to styles. Themes can be passed by reference to components to set their styles. Some components will depend upon the basic keys, but most components may use keys specific to their component. If a theme value cannot be found, then the `DefaultTheme` value will be used, instead. An updated list of theme keys can be found on the default theme.

func (*Theme) GetOrDefault

func (theme *Theme) GetOrDefault(key string) tcell.Style

Jump to

Keyboard shortcuts

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