rty

package
v0.33.12 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const GROW = math.MaxInt32

Variables

View Source
var EmptyLayout = NewConcatLayout(DirVert)

Functions

func ANSIWriter

func ANSIWriter() *ansi

ANSIWriter returns an io.Writer which translates any ANSI escape codes written to it into tview color tags. Other escape codes don't have an effect and are simply removed. The translated text is written to the provided writer.

func InitScreenAndRun added in v0.1.0

func InitScreenAndRun(m *testing.M, screen *tcell.Screen)

unfortunately, tcell misbehaves if we try to make a new Screen for every test this function is intended for use from a `TestMain`, so that we can have a global Screen across all tests in the package

func IsEmpty added in v0.4.1

func IsEmpty(l Component) bool

Types

type Align added in v0.4.1

type Align int
const (
	AlignStart Align = iota
	AlignEnd
)

type Box

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

func NewBox

func NewBox(inner Component) *Box

makes a new box that tightly wraps its inner component

func NewGrowingBox added in v0.2.0

func NewGrowingBox() *Box

makes a box that will grow to fill its canvas

func NewGrowingWindow added in v0.7.11

func NewGrowingWindow() *Box

func NewWindow added in v0.7.11

func NewWindow(inner Component) *Box

func (*Box) Render

func (b *Box) Render(w Writer, width int, height int) error

func (*Box) SetInner

func (b *Box) SetInner(c Component)

func (*Box) SetTitle added in v0.1.0

func (b *Box) SetTitle(title string)

func (*Box) Size

func (b *Box) Size(width int, height int) (int, int, error)

type Canvas

type Canvas interface {
	Size() (int, int)
	SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style)
	Close() (int, int)
	GetContent(x, y int) (mainc rune, combc []rune, style tcell.Style, width int)
}

type ColorLayout

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

func (*ColorLayout) Render

func (l *ColorLayout) Render(w Writer, width int, height int) error

func (*ColorLayout) Size

func (l *ColorLayout) Size(width int, height int) (int, int, error)

type Component

type Component interface {
	Size(availWidth, availHeight int) (int, int, error)
	Render(w Writer, width, height int) error
}

Component renders onto a canvas

func Bg

func Bg(del Component, color tcell.Color) Component

func BgColoredString

func BgColoredString(s string, fg tcell.Color, bg tcell.Color) Component

func ColoredString

func ColoredString(s string, fg tcell.Color) Component

func Fg

func Fg(del Component, color tcell.Color) Component

func NewScrollingWrappingTextArea

func NewScrollingWrappingTextArea(name string, text string) Component

func TextString

func TextString(s string) Component

type ConcatLayout

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

func NewConcatLayout

func NewConcatLayout(dir Dir) *ConcatLayout

func NewLines

func NewLines() *ConcatLayout

func (*ConcatLayout) Add

func (l *ConcatLayout) Add(c Component) *ConcatLayout

func (*ConcatLayout) AddDynamic added in v0.2.0

func (l *ConcatLayout) AddDynamic(c Component) *ConcatLayout

A ConcatLayout element can be either fixed or dynamic. Fixed components are all given a chance at the full canvas. If they ask for too much in sum, things will break. Dynamic components get equal shares of whatever is left after the fixed components get theirs. NB: There is currently a bit of a murky line between ConcatLayout and FlexLayout.

func (*ConcatLayout) Render

func (l *ConcatLayout) Render(w Writer, width int, height int) error

func (*ConcatLayout) Size

func (l *ConcatLayout) Size(width, height int) (int, int, error)

type Dir

type Dir int
const (
	DirHor Dir = iota
	DirVert
)

type ElementScrollController

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

func (*ElementScrollController) Bottom added in v0.1.0

func (s *ElementScrollController) Bottom()

func (*ElementScrollController) Down added in v0.1.0

func (s *ElementScrollController) Down()

func (*ElementScrollController) GetSelectedChild

func (s *ElementScrollController) GetSelectedChild() string

func (*ElementScrollController) GetSelectedIndex

func (s *ElementScrollController) GetSelectedIndex() int

func (*ElementScrollController) Top added in v0.1.0

func (s *ElementScrollController) Top()

func (*ElementScrollController) Up added in v0.1.0

func (s *ElementScrollController) Up()

type ElementScrollLayout

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

func NewElementScrollLayout

func NewElementScrollLayout(name string) *ElementScrollLayout

func (*ElementScrollLayout) Add

func (l *ElementScrollLayout) Add(c Component)

func (*ElementScrollLayout) Render

func (l *ElementScrollLayout) Render(w Writer, width, height int) error

func (*ElementScrollLayout) RenderStateful

func (l *ElementScrollLayout) RenderStateful(w Writer, prevState interface{}, width, height int) (state interface{}, err error)

func (*ElementScrollLayout) Size

func (l *ElementScrollLayout) Size(width int, height int) (int, int, error)

type ElementScrollState

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

type ElementScroller

type ElementScroller interface {
	Up()
	Down()
	Top()
	Bottom()
	GetSelectedIndex() int
}

type ErrorHandler added in v0.14.0

type ErrorHandler interface {
	Errorf(format string, args ...interface{})
}

We want our tests to be able to handle errors.

But we don't want errors in RTY rendering to stop the rendering pipeline.

So we need a way to accumulate errors. By design, testing.T implements this interface.

type ErrorReporter added in v0.7.11

type ErrorReporter interface {
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Helper()
}

type FillerString added in v0.2.0

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

Fills a space by repeating a string

func NewFillerString added in v0.2.0

func NewFillerString(ch rune) *FillerString

func (*FillerString) Render added in v0.2.0

func (f *FillerString) Render(w Writer, width int, height int) error

func (*FillerString) Size added in v0.2.0

func (f *FillerString) Size(width int, height int) (int, int, error)

type FixedSizeLayout

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

FixedSizeLayout fixes a component to a size

func NewFixedSize

func NewFixedSize(del Component, width int, height int) *FixedSizeLayout

func (*FixedSizeLayout) Render

func (l *FixedSizeLayout) Render(w Writer, width int, height int) error

func (*FixedSizeLayout) Size

func (l *FixedSizeLayout) Size(width int, height int) (int, int, error)

type FlexLayout

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

FlexLayout lays out its sub-components.

func NewFlexLayout

func NewFlexLayout(dir Dir) *FlexLayout

func (*FlexLayout) Add

func (l *FlexLayout) Add(c Component) *FlexLayout

func (*FlexLayout) Render

func (l *FlexLayout) Render(w Writer, width, height int) error

func (*FlexLayout) Size

func (l *FlexLayout) Size(width int, height int) (int, int, error)

type InteractiveTester added in v0.1.0

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

func NewInteractiveTester added in v0.1.0

func NewInteractiveTester(t ErrorReporter, screen tcell.Screen) InteractiveTester

func (*InteractiveTester) Run added in v0.1.0

func (i *InteractiveTester) Run(name string, width int, height int, c Component)

func (*InteractiveTester) T added in v0.7.11

type Line

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

func NewLine

func NewLine() *Line

func OneLine added in v0.4.1

func OneLine(c Component) *Line

func (*Line) Add

func (l *Line) Add(c Component)

func (*Line) Render

func (l *Line) Render(w Writer, width int, height int) error

func (*Line) Size

func (l *Line) Size(width int, height int) (int, int, error)

type MaxLengthLayout added in v0.7.12

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

func NewMaxLengthLayout added in v0.7.12

func NewMaxLengthLayout(del Component, dir Dir, max int) MaxLengthLayout

func (MaxLengthLayout) Render added in v0.7.12

func (l MaxLengthLayout) Render(w Writer, width int, height int) error

func (MaxLengthLayout) Size added in v0.7.12

func (l MaxLengthLayout) Size(width int, height int) (int, int, error)

type MinLengthLayout added in v0.4.1

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

func NewMinLengthLayout added in v0.4.1

func NewMinLengthLayout(len int, dir Dir) *MinLengthLayout

func (*MinLengthLayout) Add added in v0.4.1

func (*MinLengthLayout) Render added in v0.4.1

func (ml *MinLengthLayout) Render(writer Writer, width int, height int) error

func (*MinLengthLayout) SetAlign added in v0.4.1

func (l *MinLengthLayout) SetAlign(val Align) *MinLengthLayout

func (*MinLengthLayout) Size added in v0.4.1

func (ml *MinLengthLayout) Size(width int, height int) (int, int, error)

type ModalLayout added in v0.1.0

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

func NewModalLayout added in v0.1.0

func NewModalLayout(bg Component, fg Component, fraction float64, fixed bool) *ModalLayout

fg will be rendered on top of bg if fixed is true, it will use using fraction/1 of the height and width of the screen if fixed is false, it will use whatever `fg` asks for, up to fraction/1 of width and height

func (*ModalLayout) Render added in v0.1.0

func (l *ModalLayout) Render(w Writer, width int, height int) error

func (*ModalLayout) Size added in v0.1.0

func (l *ModalLayout) Size(width int, height int) (int, int, error)

type RTY

type RTY interface {
	Render(c Component)

	// Register must be called before Render
	RegisterElementScroll(name string, children []string) (l *ElementScrollLayout, selectedChild string)

	// *Scroller must be called after Render (each call to Render invalidates previous Crollers)
	ElementScroller(name string) ElementScroller
	TextScroller(name string) TextScroller
}

func NewRTY

func NewRTY(screen tcell.Screen, handler ErrorHandler) RTY

type ScreenCanvas

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

func (*ScreenCanvas) Close

func (c *ScreenCanvas) Close() (int, int)

func (*ScreenCanvas) GetContent

func (c *ScreenCanvas) GetContent(x, y int) (mainc rune, combc []rune, style tcell.Style, width int)

func (*ScreenCanvas) SetContent

func (c *ScreenCanvas) SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style)

func (*ScreenCanvas) Size

func (c *ScreenCanvas) Size() (int, int)

type SkipErrorHandler added in v0.14.0

type SkipErrorHandler struct{}

func (SkipErrorHandler) Errorf added in v0.14.0

func (SkipErrorHandler) Errorf(format string, args ...interface{})

type StatefulComponent

type StatefulComponent interface {
	RenderStateful(w Writer, prevState interface{}, width, height int) (state interface{}, err error)
}

type StringBuilder

type StringBuilder interface {
	Text(string) StringBuilder
	Textf(string, ...interface{}) StringBuilder
	Fg(tcell.Color) StringBuilder
	Bg(tcell.Color) StringBuilder
	Build() Component
}

func NewStringBuilder

func NewStringBuilder() StringBuilder

type StringLayout

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

func (*StringLayout) Render

func (l *StringLayout) Render(w Writer, width int, height int) error

func (*StringLayout) Size

func (l *StringLayout) Size(availWidth int, availHeight int) (int, int, error)

type SubCanvas

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

func (*SubCanvas) Close

func (c *SubCanvas) Close() (int, int)

func (*SubCanvas) GetContent

func (c *SubCanvas) GetContent(x int, y int) (rune, []rune, tcell.Style, int)

func (*SubCanvas) SetContent

func (c *SubCanvas) SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style)

func (*SubCanvas) Size

func (c *SubCanvas) Size() (int, int)

type TailLayout added in v0.7.12

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

A tail layout renders the "end" of its contents rather than the beginning when the contents overflow the box.

func NewTailLayout added in v0.7.12

func NewTailLayout(del Component) TailLayout

func (TailLayout) Render added in v0.7.12

func (l TailLayout) Render(w Writer, width, height int) error

func (TailLayout) Size added in v0.7.12

func (l TailLayout) Size(width int, height int) (int, int, error)

type TempCanvas

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

func (*TempCanvas) Close

func (c *TempCanvas) Close() (int, int)

func (*TempCanvas) GetContent

func (c *TempCanvas) GetContent(x, y int) (mainc rune, combc []rune, style tcell.Style, width int)

func (*TempCanvas) SetContent

func (c *TempCanvas) SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style)

func (*TempCanvas) Size

func (c *TempCanvas) Size() (int, int)

type TextScrollController

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

func (*TextScrollController) Bottom added in v0.1.0

func (s *TextScrollController) Bottom()

func (*TextScrollController) Down

func (s *TextScrollController) Down()

func (*TextScrollController) SetFollow added in v0.1.0

func (s *TextScrollController) SetFollow(follow bool)

func (*TextScrollController) ToggleFollow

func (s *TextScrollController) ToggleFollow()

func (*TextScrollController) Top added in v0.1.0

func (s *TextScrollController) Top()

func (*TextScrollController) Up

func (s *TextScrollController) Up()

type TextScrollLayout

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

func NewTextScrollLayout

func NewTextScrollLayout(name string) *TextScrollLayout

func (*TextScrollLayout) Add

func (l *TextScrollLayout) Add(c Component)

func (*TextScrollLayout) Render

func (l *TextScrollLayout) Render(w Writer, width, height int) error

func (*TextScrollLayout) RenderStateful

func (l *TextScrollLayout) RenderStateful(w Writer, prevState interface{}, width, height int) (state interface{}, err error)

func (*TextScrollLayout) Size

func (l *TextScrollLayout) Size(width int, height int) (int, int, error)

type TextScrollState

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

type TextScroller

type TextScroller interface {
	Up()
	Down()
	Top()
	Bottom()

	ToggleFollow()
	SetFollow(following bool)
}

type Tokenizer added in v0.2.0

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

A tokenizer that breaks a string up by spaces.

Ideally, we'd use the table-based algorithm defined in: http://www.unicode.org/reports/tr14/ like this package does: https://godoc.org/github.com/gorilla/i18n/linebreak but I didn't find a good implementation of that algorithm in Go (the one above is half-implemented and doesn't work for the most basic things).

This is a half-assed implementation that should have a similar interface to a "real" implementation.

func NewTokenizer added in v0.2.0

func NewTokenizer(s string) *Tokenizer

func (*Tokenizer) Next added in v0.2.0

func (t *Tokenizer) Next() ([]rune, error)

type Writer

type Writer interface {
	SetContent(x int, y int, mainc rune, combc []rune)

	Divide(x, y, width, height int) (Writer, error)
	Foreground(c tcell.Color) Writer
	Background(c tcell.Color) Writer
	Invert() Writer
	Fill() (Writer, error)

	RenderChild(c Component) int

	RenderChildInTemp(c Component) Canvas
	Embed(src Canvas, srcY, srcHeight int) error

	RenderStateful(c StatefulComponent, name string)
}

Jump to

Keyboard shortcuts

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