ui

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 16 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedTags = supportedTagsRegexp()

SupportedTags maps supported tags to a tcell.Attribute

Functions

func Blue

func Blue(text string) string

Blue blues the given string

func Cyan

func Cyan(text string) string

Cyan cyans the given string

func EventChannel

func EventChannel() (<-chan tcell.Event, chan struct{})

EventChannel returns a channel on which termbox's events are published.

func NewList

func NewList(theme *ColorTheme) *termui.List

NewList returns a new list using the given ColorTheme

func NewPar

func NewPar(s string, theme *ColorTheme) *termui.Paragraph

NewPar creates a new termui paragraph with the given content and with a look and feel based on the given theme.

func Red

func Red(text string) string

Red reddens the given string

func Tokenize

func Tokenize(str string, regex *regexp.Regexp) []string

Tokenize works just like strings.Split() except the resulting array includes the delimiters. For example, the "<green>Hello, <red>world!</>" string when tokenized by tags produces the following:

[0] "<green>"
[1] "Hello, "
[2] "<red>"
[3] "world!"
[4] "</>"

func White

func White(text string) string

White whites the given string

func Yellow

func Yellow(text string) string

Yellow yellows the given string

Types

type Color

type Color uint32

Color representation

const (
	Grey     Color = Color233
	Grey2    Color = Color244
	Darkgrey Color = Color232
)

Colors

const (
	ColorBlack Color = iota
	ColorMaroon
	ColorGreen
	ColorOlive
	ColorNavy
	ColorPurple
	ColorTeal
	ColorSilver
	ColorGray
	ColorRed
	ColorLime
	ColorYellow
	ColorBlue
	ColorFuchsia
	ColorAqua
	ColorWhite
	Color16
	Color17
	Color18
	Color19
	Color20
	Color21
	Color22
	Color23
	Color24
	Color25
	Color26
	Color27
	Color28
	Color29
	Color30
	Color31
	Color32
	Color33
	Color34
	Color35
	Color36
	Color37
	Color38
	Color39
	Color40
	Color41
	Color42
	Color43
	Color44
	Color45
	Color46
	Color47
	Color48
	Color49
	Color50
	Color51
	Color52
	Color53
	Color54
	Color55
	Color56
	Color57
	Color58
	Color59
	Color60
	Color61
	Color62
	Color63
	Color64
	Color65
	Color66
	Color67
	Color68
	Color69
	Color70
	Color71
	Color72
	Color73
	Color74
	Color75
	Color76
	Color77
	Color78
	Color79
	Color80
	Color81
	Color82
	Color83
	Color84
	Color85
	Color86
	Color87
	Color88
	Color89
	Color90
	Color91
	Color92
	Color93
	Color94
	Color95
	Color96
	Color97
	Color98
	Color99
	Color100
	Color101
	Color102
	Color103
	Color104
	Color105
	Color106
	Color107
	Color108
	Color109
	Color110
	Color111
	Color112
	Color113
	Color114
	Color115
	Color116
	Color117
	Color118
	Color119
	Color120
	Color121
	Color122
	Color123
	Color124
	Color125
	Color126
	Color127
	Color128
	Color129
	Color130
	Color131
	Color132
	Color133
	Color134
	Color135
	Color136
	Color137
	Color138
	Color139
	Color140
	Color141
	Color142
	Color143
	Color144
	Color145
	Color146
	Color147
	Color148
	Color149
	Color150
	Color151
	Color152
	Color153
	Color154
	Color155
	Color156
	Color157
	Color158
	Color159
	Color160
	Color161
	Color162
	Color163
	Color164
	Color165
	Color166
	Color167
	Color168
	Color169
	Color170
	Color171
	Color172
	Color173
	Color174
	Color175
	Color176
	Color177
	Color178
	Color179
	Color180
	Color181
	Color182
	Color183
	Color184
	Color185
	Color186
	Color187
	Color188
	Color189
	Color190
	Color191
	Color192
	Color193
	Color194
	Color195
	Color196
	Color197
	Color198
	Color199
	Color200
	Color201
	Color202
	Color203
	Color204
	Color205
	Color206
	Color207
	Color208
	Color209
	Color210
	Color211
	Color212
	Color213
	Color214
	Color215
	Color216
	Color217
	Color218
	Color219
	Color220
	Color221
	Color222
	Color223
	Color224
	Color225
	Color226
	Color227
	Color228
	Color229
	Color230
	Color231
	Color232
	Color233
	Color234
	Color235
	Color236
	Color237
	Color238
	Color239
	Color240
	Color241
	Color242
	Color243
	Color244
	Color245
	Color246
	Color247
	Color248
	Color249
	Color250
	Color251
	Color252
	Color253
	Color254
	Color255
	ColorAliceBlue
	ColorAntiqueWhite
	ColorAquaMarine
	ColorAzure
	ColorBeige
	ColorBisque
	ColorBlanchedAlmond
	ColorBlueViolet
	ColorBrown
	ColorBurlyWood
	ColorCadetBlue
	ColorChartreuse
	ColorChocolate
	ColorCoral
	ColorCornflowerBlue
	ColorCornsilk
	ColorCrimson
	ColorDarkBlue
	ColorDarkCyan
	ColorDarkGoldenrod
	ColorDarkGray
	ColorDarkGreen
	ColorDarkKhaki
	ColorDarkMagenta
	ColorDarkOliveGreen
	ColorDarkOrange
	ColorDarkOrchid
	ColorDarkRed
	ColorDarkSalmon
	ColorDarkSeaGreen
	ColorDarkSlateBlue
	ColorDarkSlateGray
	ColorDarkTurquoise
	ColorDarkViolet
	ColorDeepPink
	ColorDeepSkyBlue
	ColorDimGray
	ColorDodgerBlue
	ColorFireBrick
	ColorFloralWhite
	ColorForestGreen
	ColorGainsboro
	ColorGhostWhite
	ColorGold
	ColorGoldenrod
	ColorGreenYellow
	ColorHoneydew
	ColorHotPink
	ColorIndianRed
	ColorIndigo
	ColorIvory
	ColorKhaki
	ColorLavender
	ColorLavenderBlush
	ColorLawnGreen
	ColorLemonChiffon
	ColorLightBlue
	ColorLightCoral
	ColorLightCyan
	ColorLightGoldenrodYellow
	ColorLightGray
	ColorLightGreen
	ColorLightPink
	ColorLightSalmon
	ColorLightSeaGreen
	ColorLightSkyBlue
	ColorLightSlateGray
	ColorLightSteelBlue
	ColorLightYellow
	ColorLimeGreen
	ColorLinen
	ColorMediumAquamarine
	ColorMediumBlue
	ColorMediumOrchid
	ColorMediumPurple
	ColorMediumSeaGreen
	ColorMediumSlateBlue
	ColorMediumSpringGreen
	ColorMediumTurquoise
	ColorMediumVioletRed
	ColorMidnightBlue
	ColorMintCream
	ColorMistyRose
	ColorMoccasin
	ColorNavajoWhite
	ColorOldLace
	ColorOliveDrab
	ColorOrange
	ColorOrangeRed
	ColorOrchid
	ColorPaleGoldenrod
	ColorPaleGreen
	ColorPaleTurquoise
	ColorPaleVioletRed
	ColorPapayaWhip
	ColorPeachPuff
	ColorPeru
	ColorPink
	ColorPlum
	ColorPowderBlue
	ColorRebeccaPurple
	ColorRosyBrown
	ColorRoyalBlue
	ColorSaddleBrown
	ColorSalmon
	ColorSandyBrown
	ColorSeaGreen
	ColorSeashell
	ColorSienna
	ColorSkyblue
	ColorSlateBlue
	ColorSlateGray
	ColorSnow
	ColorSpringGreen
	ColorSteelBlue
	ColorTan
	ColorThistle
	ColorTomato
	ColorTurquoise
	ColorViolet
	ColorWheat
	ColorWhiteSmoke
	ColorYellowGreen
)

First 256 entries correspond to Colors from the color palette as defined by the standard https://en.wikipedia.org/wiki/ANSI_escape_code#Colors. Order is important. Below that, a few colors from the TrueColor palette are defined.

func ColorFromName

func ColorFromName(name string) Color

ColorFromName returns the Color that corresponds to the given color name

type ColorTheme

type ColorTheme struct {
	Fg           Color
	Bg           Color
	DarkBg       Color
	Prompt       Color
	Key          Color
	Current      Color
	CurrentMatch Color
	Spinner      Color
	Info         Color
	Cursor       Color
	Selected     Color
	Header       Color
	Footer       Color
	ListItem     Color
	CursorLineBg Color
}

ColorTheme represents a color theme

type Cursor

type Cursor struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cursor represents the cursor position on the screen

func NewCursor

func NewCursor() *Cursor

NewCursor creates a new unlimited cursor at position 0.

func (*Cursor) Bottom

func (cursor *Cursor) Bottom()

Bottom moves the cursor to the bottom, if max is not set this a noop

func (*Cursor) Max

func (cursor *Cursor) Max(max int)

Max sets the max position allowed to this cursor

func (*Cursor) MovingDown

func (cursor *Cursor) MovingDown() bool

MovingDown returns true if the cursor is moving downwards after the last movement.

func (*Cursor) Position

func (cursor *Cursor) Position() int

Position tells on which screen pos the cursor is

func (*Cursor) Reset

func (cursor *Cursor) Reset()

Reset sets the cursor to its initial state (position 0, direction downwards).

func (*Cursor) ScrollCursorDown

func (cursor *Cursor) ScrollCursorDown()

ScrollCursorDown moves the cursor to the pos below the current one

func (*Cursor) ScrollCursorUp

func (cursor *Cursor) ScrollCursorUp()

ScrollCursorUp moves the cursor to the pos above the current one

func (*Cursor) ScrollTo

func (cursor *Cursor) ScrollTo(pos int)

ScrollTo moves the cursor to the given pos

func (*Cursor) String

func (cursor *Cursor) String() string

func (*Cursor) Top

func (cursor *Cursor) Top()

Top moves the cursor to the top

type Dimensions

type Dimensions struct {
	Height, Width int
}

Dimensions is the width and height of a ui element.

type EventSource

type EventSource struct {
	Events               <-chan *tcell.EventKey
	EventHandledCallback func(*tcell.EventKey) error
}

EventSource defines a source of keypress events.

type ExpiringMessageWidget

type ExpiringMessageWidget struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ExpiringMessageWidget shows some text for an amount time then clears itself

func NewExpiringMessageWidget

func NewExpiringMessageWidget(y int, screen *Screen) *ExpiringMessageWidget

NewExpiringMessageWidget creates a new ExpiringMessageWidget struct

func (*ExpiringMessageWidget) Message

func (s *ExpiringMessageWidget) Message(msg string, clearDelay time.Duration)

Message sets the message to show for the given duration

func (*ExpiringMessageWidget) Pause

func (s *ExpiringMessageWidget) Pause()

Pause pauses this widget from showing any output, setting a new status message will activate it again

func (*ExpiringMessageWidget) Render

func (s *ExpiringMessageWidget) Render()

Render renders the status message

type Focusable

type Focusable interface {
	Focus(events <-chan *tcell.EventKey, done func()) error
}

Focusable define ui elements that can focus

type InputBox

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

InputBox captures user input

func NewInputBox

func NewInputBox(x, y int, prompt string, output chan<- string, keyboardQueue chan *tcell.EventKey, theme *ColorTheme, screen *Screen) *InputBox

NewInputBox creates an input box, located at position x,y in the screen.

func (*InputBox) AdjustVOffset

func (eb *InputBox) AdjustVOffset(width int)

AdjustVOffset adjusts line visual offset to a proper value depending on width

func (*InputBox) CursorX

func (eb *InputBox) CursorX() int

CursorX Please, keep in mind that cursor depends on the value of lineVOffset, which is being set on Draw() call, so.. call this method after Draw() one.

func (*InputBox) Delete

func (eb *InputBox) Delete()

Delete deletes the content of the inputbox

func (*InputBox) DeleteRuneBackward

func (eb *InputBox) DeleteRuneBackward()

DeleteRuneBackward deletes a rune moving the cursor backwards

func (*InputBox) DeleteRuneForward

func (eb *InputBox) DeleteRuneForward()

DeleteRuneForward deletes a rune and moving the cursor forward

func (*InputBox) DeleteTheRestOfTheLine

func (eb *InputBox) DeleteTheRestOfTheLine()

DeleteTheRestOfTheLine deletes the conent of the line where the cursor is from the cursor position until the end of the line

func (*InputBox) Draw

func (eb *InputBox) Draw(x, y, w, h int)

Draw draws the InputBox in the given location

func (*InputBox) Focus

func (eb *InputBox) Focus()

Focus is set on the inputbox, it starts handling terminal events and responding to user actions.

func (*InputBox) InsertRune

func (eb *InputBox) InsertRune(r rune)

InsertRune adds the given rune to the inputbox

func (*InputBox) MoveCursorOneRuneBackward

func (eb *InputBox) MoveCursorOneRuneBackward()

MoveCursorOneRuneBackward moves the cursor one rune backwards

func (*InputBox) MoveCursorOneRuneForward

func (eb *InputBox) MoveCursorOneRuneForward()

MoveCursorOneRuneForward moves the cursor one rune forward

func (*InputBox) MoveCursorTo

func (eb *InputBox) MoveCursorTo(boffset int)

MoveCursorTo moves the cursor

func (*InputBox) MoveCursorToBeginningOfTheLine

func (eb *InputBox) MoveCursorToBeginningOfTheLine()

MoveCursorToBeginningOfTheLine moves the cursor to the beginning of the line

func (*InputBox) MoveCursorToEndOfTheLine

func (eb *InputBox) MoveCursorToEndOfTheLine()

MoveCursorToEndOfTheLine moves the cursor to the end of the line

func (*InputBox) RuneBeforeCursor

func (eb *InputBox) RuneBeforeCursor() (rune, int)

RuneBeforeCursor returns the rune from the inputbox placed before the cursor

func (*InputBox) RuneUnderCursor

func (eb *InputBox) RuneUnderCursor() (rune, int)

RuneUnderCursor returns the rune from the inputbox where the cursor is

func (*InputBox) String

func (eb *InputBox) String() string

String returns the inputbox content as a string

type Key

type Key struct {
	KeyCodes []rune
	Keys     []tcell.Key
	HelpText string
}

Key represents a keyboard key Not in use.

type Less

type Less struct {
	*View

	sync.Mutex
	// contains filtered or unexported fields
}

Less is a View specialization with less-like behavior and characteristics, meaning: * The cursor is always shown at the bottom of the screen. * Navigation is done using less keybindings. * Basic search is supported.

func NewLess

func NewLess(theme *ColorTheme) *Less

NewLess creates a view that partially simulates less.

func (*Less) Focus

func (less *Less) Focus(events <-chan *tcell.EventKey) error

Focus sets the view as active, so it starts handling terminal events and user actions

func (*Less) ScrollDown

func (less *Less) ScrollDown()

ScrollDown moves the cursor down one line

func (*Less) ScrollPageDown

func (less *Less) ScrollPageDown()

ScrollPageDown moves the buffer position down by the length of the screen, at the end of buffer it also moves the cursor position to the bottom of the screen

func (*Less) ScrollPageUp

func (less *Less) ScrollPageUp()

ScrollPageUp moves the buffer position up by the length of the screen, at the beginning of buffer it also moves the cursor position to the beginning of the screen

func (*Less) ScrollToBottom

func (less *Less) ScrollToBottom()

ScrollToBottom moves the cursor to the bottom of the view buffer

func (*Less) ScrollToTop

func (less *Less) ScrollToTop()

ScrollToTop moves the cursor to the top of the view buffer

func (*Less) ScrollUp

func (less *Less) ScrollUp()

ScrollUp moves the cursor up one line

type Markup

type Markup struct {
	Foreground termbox.Attribute
	Background termbox.Attribute
	// contains filtered or unexported fields
}

Markup implements some minimalistic text formatting conventions that get translated to Termbox colors and attributes. To colorize a string wrap it in <color-name>...</> tags. Unlike HTML each tag sets a new color whereas the </> tag changes color back to default. For example:

<green>Hello, <red>world!</>

func NewMarkup

func NewMarkup(theme *ColorTheme) *Markup

NewMarkup creates a markup processor that uses the given theme for default colors.

func (*Markup) IsTag

func (markup *Markup) IsTag(str string) bool

IsTag returns true when the given string looks like markup tag. When the tag name matches one of the markup-supported tags it gets translated to relevant Termbox attributes and colors.

type Screen

type Screen struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Screen is where text is rendered

var ActiveScreen *Screen

ActiveScreen is the currently active screen

func NewScreen

func NewScreen(theme *ColorTheme) (*Screen, error)

NewScreen creates a new Screen and sets the ActiveScreen

func (*Screen) Clear

func (screen *Screen) Clear() *Screen

Clear makes the entire screen blank using default background color.

func (*Screen) ClearAndFlush

func (screen *Screen) ClearAndFlush() *Screen

ClearAndFlush cleares the screen and then flushes internal buffers

func (*Screen) Close

func (screen *Screen) Close() *Screen

Close gets called upon program termination to close

func (*Screen) Closing

func (screen *Screen) Closing() bool

Closing returns true if this this screen is closing

func (*Screen) ColorTheme

func (screen *Screen) ColorTheme(theme *ColorTheme) *Screen

ColorTheme changes the color theme of the screen to the given one.

func (*Screen) Cursor

func (screen *Screen) Cursor() *Cursor

Cursor returns the screen cursor

func (*Screen) Dimensions

func (screen *Screen) Dimensions() *Dimensions

Dimensions returns the screen dimensions

func (*Screen) Fill

func (screen *Screen) Fill(x, y, w, h int, r rune)

Fill fills the squared portion of the screen delimited by the given positions with the provided rune. It uses this screen style.

func (*Screen) Flush

func (screen *Screen) Flush() *Screen

Flush makes all the content visible on the display.

func (*Screen) HideCursor

func (screen *Screen) HideCursor()

HideCursor hides the cursor.

func (*Screen) Render

func (screen *Screen) Render(row int, str string)

Render renders the given content starting from the given row

func (*Screen) RenderAtColumn

func (screen *Screen) RenderAtColumn(column, initialRow int, str string)

RenderAtColumn renders the given content starting from the given row at the given column

func (*Screen) RenderBufferer

func (screen *Screen) RenderBufferer(bs ...termui.Bufferer)

RenderBufferer renders all Bufferer in the given order from left to right, right could overlap on left ones. This allows usage of termui widgets.

func (*Screen) RenderLine

func (screen *Screen) RenderLine(x int, y int, str string)

RenderLine renders the given string, removing markup elements, at the given location.

func (*Screen) RenderRune

func (screen *Screen) RenderRune(x, y int, r rune)

RenderRune renders the given rune on the given pos

func (*Screen) Resize

func (screen *Screen) Resize()

Resize resizes this screen

func (*Screen) ShowCursor

func (screen *Screen) ShowCursor(x, y int)

ShowCursor shows the cursor on the given position

func (*Screen) Sync

func (screen *Screen) Sync() *Screen

Sync is like flsuh but it ensures that whatever internal states are synchronized before flushing content to the screen.

type ScreenTextRenderer

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

ScreenTextRenderer renders text on a screen

func NewRenderer

func NewRenderer(s styledRuneRenderer) ScreenTextRenderer

NewRenderer creates ScreenTextRenderer

func (ScreenTextRenderer) On

func (renderer ScreenTextRenderer) On(x, y int) ScreenTextRenderer

On returns a renderer that will start rendering on the given positions of the screen.

func (ScreenTextRenderer) Render

func (renderer ScreenTextRenderer) Render(s string) int

Render renders the given text on this renderer screen

func (ScreenTextRenderer) WithStyle

func (renderer ScreenTextRenderer) WithStyle(style tcell.Style) ScreenTextRenderer

WithStyle returns a renderer that will use the provided style on rendering

func (ScreenTextRenderer) WithWidth

func (renderer ScreenTextRenderer) WithWidth(w int) ScreenTextRenderer

WithWidth returns a renderer with its width set

type TextRenderer

type TextRenderer interface {
	Render(string) int
}

TextRenderer renders text

type View

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

A View is a region of the screen where text can be rendered. It maintains its own internal buffer and cursor position.

func NewMarkupView

func NewMarkupView(name string, x0, y0, x1, y1 int, showCursor bool, theme *ColorTheme) *View

NewMarkupView returns a new View with markup support

func NewView

func NewView(name string, x0, y0, x1, y1 int, showCursor bool, theme *ColorTheme) *View

NewView returns a new View

func (*View) Clear

func (v *View) Clear()

Clear empties the view's internal buffer.

func (*View) Cursor

func (v *View) Cursor() (x, y int)

Cursor returns the cursor position of the view.

func (*View) CursorDown

func (v *View) CursorDown()

CursorDown moves the cursor down one line

func (*View) CursorToBottom

func (v *View) CursorToBottom()

CursorToBottom moves the cursor to the bottom of the view buffer

func (*View) CursorToTop

func (v *View) CursorToTop()

CursorToTop moves the cursor to the top of the view buffer

func (*View) CursorUp

func (v *View) CursorUp()

CursorUp moves the cursor up one line

func (*View) Line

func (v *View) Line(y int) (string, error)

Line returns a string with the line of the view's internal buffer at the position corresponding to the point (x, y).

func (*View) MarkupSupport

func (v *View) MarkupSupport()

MarkupSupport sets markup support in the view

func (*View) Name

func (v *View) Name() string

Name returns the name of the view.

func (*View) PageDown

func (v *View) PageDown()

PageDown moves the buffer position down by the length of the screen, at the end of buffer it also moves the cursor position to the bottom of the screen

func (*View) PageUp

func (v *View) PageUp()

PageUp moves the buffer position up by the length of the screen, at the beginning of buffer it also moves the cursor position to the beginning of the screen

func (*View) Position

func (v *View) Position() (x, y int)

Position returns the position in the view buffer.

func (*View) ViewSize

func (v *View) ViewSize() (width, height int)

ViewSize returns the width and the height of the View.

func (*View) Word

func (v *View) Word(x, y int) (string, error)

Word returns a string with the word of the view's internal buffer at the position corresponding to the point (x, y).

func (*View) Write

func (v *View) Write(p []byte) (n int, err error)

Write appends a byte slice into the view's internal buffer, as defined by the io.Writer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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