cellbuf

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 9 Imported by: 3

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 Clear added in v0.0.6

func Clear(d Buffer, rects ...Rectangle)

Clear clears the canvas with space cells. If rect is not nil, it only clears the rectangle. Otherwise, it clears the whole canvas.

func Equal

func Equal(a, b Buffer) bool

Equal returns whether two grids are equal.

func Fill

func Fill(d Buffer, c *Cell, rects ...Rectangle)

Fill fills the canvas with the given cell. If rect is not nil, it only fills the rectangle. Otherwise, it fills the whole canvas.

func Height

func Height(s string) int

Height returns the height of a string.

func NewBuffer added in v0.0.6

func NewBuffer(width, height int) *buffer

NewBuffer returns a new buffer with the given width and height.

func Paint added in v0.0.6

func Paint(d Buffer, m Method, content string, rect *Rectangle) []int

Paint writes the given data to the canvas. If rect is not nil, it only writes to the rectangle. Otherwise, it writes to the whole canvas.

func Render

func Render(d Buffer, opts ...RenderOption) string

Render returns a string representation of the grid with ANSI escape sequences.

func RenderLine

func RenderLine(d Buffer, n int, opts ...RenderOption) (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 Buffer

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

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

	// Cell returns the cell at the given position. If the cell is out of
	// bounds, it returns nil.
	Cell(x, y int) *Cell

	// SetCell writes a cell to the grid at the given position. It returns true
	// if the cell was written successfully. If the cell is nil, a blank cell
	// is written.
	SetCell(x, y int, c *Cell) bool
}

Buffer represents a screen grid of cells.

type Cell

type Cell = vt.Cell

Cell represents a single cell in the terminal screen.

type Link = vt.Link

Link represents a hyperlink in the terminal screen.

func ConvertLink(h Link, p colorprofile.Profile) Link

Convert converts a hyperlink to respect the given color profile.

type Method added in v0.0.2

type Method uint8

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

const (
	WcWidth Method = iota
	GraphemeWidth
)

Display width modes.

type Position added in v0.0.6

type Position = vt.Position

Position represents an x, y position.

func Pos added in v0.0.6

func Pos(x, y int) Position

Pos is a shorthand for Position{X: x, Y: y}.

type Rectangle added in v0.0.6

type Rectangle = vt.Rectangle

Rectange represents a rectangle.

func Rect added in v0.0.6

func Rect(x, y, w, h int) Rectangle

Rect is a shorthand for Rectangle.

type RenderOption added in v0.0.6

type RenderOption func(*RenderOptions)

RenderOption is a function that configures a RenderOptions.

func WithRenderProfile added in v0.0.6

func WithRenderProfile(p colorprofile.Profile) RenderOption

WithRenderProfile sets the color profile to use when rendering the canvas.

type RenderOptions added in v0.0.6

type RenderOptions struct {
	// Profile is the color profile to use when rendering the canvas.
	Profile colorprofile.Profile
}

RenderOptions represents options for rendering a canvas.

type Resizable added in v0.0.6

type Resizable interface {
	// Resize resizes the buffer to the given width and height.
	Resize(width, height int)
}

Resizable is an interface for buffers that can be resized.

type Segment

type Segment = Cell

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

type Style

type Style = vt.Style

Style represents the Style of a cell.

func ConvertStyle added in v0.0.6

func ConvertStyle(s Style, p colorprofile.Profile) Style

Convert converts a style to respect the given color profile.

Jump to

Keyboard shortcuts

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