util

package
v0.0.0-...-c186bf4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsoleBell

func ConsoleBell()

ConsoleBell emits the default terminal bell sound.

func FormatDuration

func FormatDuration(t time.Duration) string

FormatDuration returns a human friendly string representing the given duration (ie: 1.23 s).

func Min

func Min[T constraints.Ordered](a, b T) T

Min returns the lesser of the two comparable values.

func WrapLine

func WrapLine(text string, width int) (string, int)

WrapLine inserts newlines so that the given text contains at most width characters per line. The newly wrapped string and the number of lines are returned. This function does not consider existing newline characters in the given text; wse WrapText instead if that's the case.

func WrapText

func WrapText(text string, width int) (string, int)

WrapText inserts newlines so that the given text contains at most width characters per line. The newly wrapped string and the number of lines are returned. Empty strings are considered to be on one line. If the text contains newlines, each line will be considered separately. This function does not consider words; it strictly wraps only on characters.

Types

type BuildMeta

type BuildMeta struct {
	Version string
	Commit  string
	Date    string
}

BuildMeta contains information about the current app build level.

func NewBuildMeta

func NewBuildMeta(version string, commit string, date string) *BuildMeta

NewBuildMeta returns an instance of BuildMeta populated with build metadata.

type FocusDirection

type FocusDirection int
const (
	FocusUp FocusDirection = iota
	FocusDown
	FocusLeft
	FocusRight
)

type FocusFilterResult

type FocusFilterResult int
const (
	// FocusPreHandlePropagate indicates the event should be propagated up the focus chain.
	FocusPreHandlePropagate FocusFilterResult = iota
	// FocusPreHandleIgnore indicates the event should not be handled at all.
	FocusPreHandleIgnore
	// FocusPreHandleProcess indicates the event should be handled by the current focus manager as usual.
	FocusPreHandleProcess
)

type FocusManager

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

FocusManager is a utility that manages and handles changing focus amongst a set of primitives. An optional parent may be passed that will receive focus when the escape key is pressed.

func NewFocusManager

func NewFocusManager(sender any, application *tview.Application, dispatcher *events.EventDispatcher, parent tview.Primitive, primitives ...tview.Primitive) *FocusManager

NewFocusManager creates a new instance of FocusManager to manage the given set of primitives.

func (*FocusManager) AddArrowNavigation

func (f *FocusManager) AddArrowNavigation(directions ...FocusDirection)

AddArrowNavigation enables dispatching a directional navigation event if the given arrow key event(s) are received while the parent primitive has focus.

func (*FocusManager) HandleKeyEvent

func (f *FocusManager) HandleKeyEvent(event *tcell.EventKey) *tcell.EventKey

HandleKeyEvent processes a keyboard event and changes which primitive is focused.

func (*FocusManager) ParentHasFocus

func (f *FocusManager) ParentHasFocus() bool

ParentHasFocus returns true if the parent primitive currently has focus, false if not.

func (*FocusManager) SetFilter

func (f *FocusManager) SetFilter(filter FocusManagerFilterHandler)

SetFilter sets the function to invoke that determines if a key event should be processed.

func (*FocusManager) SetHandler

func (f *FocusManager) SetHandler(handler FocusManagerHandler)

SetHandler sets the function to invoke when the FocusManager does not handle a key event. This can be useful for chaining instances of FocusManager and other key event handlers.

func (*FocusManager) SetLenientArrowNavigation

func (f *FocusManager) SetLenientArrowNavigation()

SetLenientArrowNavigation allows arrow navigation to occur without requiring the parent primitive to have focus.

func (*FocusManager) SetName

func (f *FocusManager) SetName(name string)

SetName sets the name of the focus manager to distinguish it from others.

func (*FocusManager) SetPrimitives

func (f *FocusManager) SetPrimitives(primitives ...tview.Primitive)

SetPrimitives sets the primitives that should receive focus. This will replace any previously configured primitives.

type FocusManagerFilterHandler

type FocusManagerFilterHandler func(event *tcell.EventKey) FocusFilterResult

type FocusManagerHandler

type FocusManagerHandler func(event *tcell.EventKey) *tcell.EventKey

Jump to

Keyboard shortcuts

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