cellbuf

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfBounds = errors.New("out of bounds")

ErrOutOfBounds is returned when the given x, y position is out of bounds.

Functions

func Equal

func Equal(a, b Grid) bool

Equal returns whether two grids are equal.

func Fill

func Fill(g Grid, c Cell)

Fill fills the grid with the given cell.

func Height

func Height(s string) int

Height returns the height of a string.

func Render

func Render(g Grid) string

Render returns a string representation of the grid with ANSI escape sequences. Use ansi.Strip to remove them.

func RenderLine

func RenderLine(g Grid, n int) (w int, line string)

RenderLine returns a string representation of the yth line of the grid along with the width of the line.

Types

type AttrMask

type AttrMask uint8

AttrMask is a bitmask for text attributes that can change the look of text. These attributes can be combined to create different styles.

const (
	BoldAttr AttrMask = 1 << iota
	FaintAttr
	ItalicAttr
	SlowBlinkAttr
	RapidBlinkAttr
	ReverseAttr
	ConcealAttr
	StrikethroughAttr

	ResetAttr AttrMask = 0
)

These are the available text attributes that can be combined to create different styles.

type Buffer

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

Buffer is a 2D grid of cells representing a screen or terminal.

func (*Buffer) At

func (b *Buffer) At(x, y int) (Cell, error)

At returns the cell at the given x, y position.

func (*Buffer) Clone

func (b *Buffer) Clone() *Buffer

Clone returns a deep copy of the buffer.

func (*Buffer) Height

func (b *Buffer) Height() int

Height returns the height of the buffer.

func (*Buffer) Resize

func (b *Buffer) Resize(width, height int)

Resize resizes the buffer to the given width and height. It grows the buffer if necessary and fills the new cells with space cells. Otherwise, it truncates the buffer.

func (*Buffer) Set

func (b *Buffer) Set(x, y int, c Cell) (v bool)

Set sets the cell at the given x, y position.

func (*Buffer) Width

func (b *Buffer) Width() int

Width returns the width of the buffer.

type Cell

type Cell struct {
	// The style of the cell. Nil style means no style. Zero value prints a
	// reset sequence.
	Style Style

	// Link is the hyperlink of the cell.
	Link Link

	// Content is the string representation of the cell as a grapheme cluster.
	Content string

	// Width is the mono-space width of the grapheme cluster.
	Width int
}

Cell represents a single cell in the terminal screen.

func (Cell) Empty

func (c Cell) Empty() bool

Empty returns whether the cell is empty.

func (Cell) Equal

func (c Cell) Equal(o Cell) bool

Equal returns whether the cell is equal to the other cell.

func (*Cell) Reset

func (c *Cell) Reset()

Reset resets the cell to the default state zero value.

type Grid

type Grid interface {
	// Width returns the width of the grid.
	Width() int

	// Height returns the height of the grid.
	Height() int

	// Set writes a cell to the grid at the given position. It returns true if
	// the cell was written successfully.
	Set(x, y int, c Cell) bool

	// At returns the cell at the given position.
	At(x, y int) (Cell, error)

	// Resize resizes the grid to the given width and height.
	Resize(width, height int)
}

Grid represents an interface for a grid of cells that can be written to and read from.

type Link struct {
	URL   string
	URLID string
}

Link represents a hyperlink in the terminal screen.

func (Link) Empty

func (h Link) Empty() bool

Empty returns whether the hyperlink is empty.

func (Link) Equal

func (h Link) Equal(o Link) bool

Equal returns whether the hyperlink is equal to the other hyperlink.

func (*Link) Reset

func (h *Link) Reset()

Reset resets the hyperlink to the default state zero value.

func (Link) String

func (h Link) String() string

String returns a string representation of the hyperlink.

type Segment

type Segment = Cell

Segment represents a continuous segment of cells with the same style attributes and hyperlink.

type Style

type Style struct {
	Fg      ansi.Color
	Bg      ansi.Color
	Ul      ansi.Color
	Attrs   AttrMask
	UlStyle UnderlineStyle
}

Style represents the Style of a cell.

func (*Style) Background

func (s *Style) Background(c ansi.Color) *Style

Background sets the background color.

func (*Style) Bold

func (s *Style) Bold(v bool) *Style

Bold sets the bold attribute.

func (*Style) Conceal

func (s *Style) Conceal(v bool) *Style

Conceal sets the conceal attribute.

func (Style) DiffSequence

func (s Style) DiffSequence(o Style) string

DiffSequence returns the ANSI sequence that sets the style as a diff from another style.

func (*Style) Empty

func (s *Style) Empty() bool

Empty returns true if the style is empty.

func (Style) Equal

func (s Style) Equal(o Style) bool

Equal returns true if the style is equal to the other style.

func (*Style) Faint

func (s *Style) Faint(v bool) *Style

Faint sets the faint attribute.

func (*Style) Foreground

func (s *Style) Foreground(c ansi.Color) *Style

Foreground sets the foreground color.

func (*Style) Italic

func (s *Style) Italic(v bool) *Style

Italic sets the italic attribute.

func (s *Style) RapidBlink(v bool) *Style

RapidBlink sets the rapid blink attribute.

func (*Style) Reset

func (s *Style) Reset() *Style

Reset resets the style to default.

func (*Style) Reverse

func (s *Style) Reverse(v bool) *Style

Reverse sets the reverse attribute.

func (Style) Sequence

func (s Style) Sequence() string

Sequence returns the ANSI sequence that sets the style.

func (s *Style) SlowBlink(v bool) *Style

SlowBlink sets the slow blink attribute.

func (*Style) Strikethrough

func (s *Style) Strikethrough(v bool) *Style

Strikethrough sets the strikethrough attribute.

func (*Style) Underline

func (s *Style) Underline(v bool) *Style

Underline sets the underline attribute. This is a syntactic sugar for UnderlineStyle.

func (*Style) UnderlineColor

func (s *Style) UnderlineColor(c ansi.Color) *Style

UnderlineColor sets the underline color.

func (*Style) UnderlineStyle

func (s *Style) UnderlineStyle(style UnderlineStyle) *Style

UnderlineStyle sets the underline style.

type UnderlineStyle

type UnderlineStyle uint8

UnderlineStyle is the style of underline to use for text.

const (
	NoUnderline UnderlineStyle = iota
	SingleUnderline
	DoubleUnderline
	CurlyUnderline
	DottedUnderline
	DashedUnderline
)

These are the available underline styles.

func (UnderlineStyle) String

func (u UnderlineStyle) String() string

String returns a string representation of the underline style.

type WidthMethod

type WidthMethod uint8

WidthMethod is a type that represents the how the renderer should calculate the display width of cells.

const (
	WcWidth WidthMethod = iota
	GraphemeWidth
)

Display width modes.

func (WidthMethod) SetContent

func (m WidthMethod) SetContent(g Grid, content string) []int

SetContent writes the given data to the grid starting from the first cell.

func (WidthMethod) SetContentAt

func (m WidthMethod) SetContentAt(b Grid, c string, x, y, w, h int) []int

SetContentAt writes the given data to the grid starting from the given position and with the given width and height.

Jump to

Keyboard shortcuts

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