raster

package
v0.0.0-...-b1976e4 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2017 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Overview

Package raster implements text buffering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElideText

func ElideText(s string, width int) string

ElideText elide a string as necessary.

func FormatText

func FormatText(s string) string

FormatText formats special characters like code points below 32.

TODO(maruel): This must add coloring too.

TODO(maruel): Improve performance for the common case (no special character).

TODO(maruel): Handles special unicode whitespaces. Since the editor is meant for mono-space font, all except U+0020 and \t should be escaped. https://en.wikipedia.org/wiki/Whitespace_character

Types

type Buffer

type Buffer struct {
	Width  int
	Height int
	Stride int
	Cells  CellStride
}

Buffer represents a buffer of Cells.

The Cells slice can be shared across multiple Buffer when using SubBuffer(). Width Height are guaranteed to be either both zero or non-zero.

func NewBuffer

func NewBuffer(width, height int) *Buffer

NewBuffer creates a fresh new buffer.

func (*Buffer) Blit

func (b *Buffer) Blit(src *Buffer)

Blit copies src into b.

To copy a section of a buffer, use SubBuffer() first. Areas that falls either outside of src or of b are ignored.

func (*Buffer) Cell

func (b *Buffer) Cell(X, Y int) *Cell

Cell returns the pointer to a specific character cell.

If the position is outside the buffer, an empty temporary cell is returned.

func (*Buffer) DrawString

func (b *Buffer) DrawString(s string, X, Y int, f CellFormat)

DrawString draws a string into the buffer.

Text will be automatically elided if necessary.

func (*Buffer) Fill

func (b *Buffer) Fill(cell Cell)

Fill fills a buffer with a Cell.

To fill a section of a buffer, use SubBuffer() first.

func (*Buffer) Line

func (b *Buffer) Line(Y int) CellStride

Line returns a single line in the buffer.

If the requested line number if outside the buffer, an empty slice is returned.

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) SubBuffer

func (b *Buffer) SubBuffer(r Rect) *Buffer

SubBuffer returns a Buffer representing a section of the buffer, sharing the same cells.

type Cell

type Cell struct {
	R rune
	F CellFormat
}

Cell represents the properties of a single character on screen.

Some properties are ignored on different terminals.

func MakeCell

func MakeCell(R rune, Fg, Bg colors.RGB) Cell

MakeCell is a shorthand to return a Cell.

type CellFormat

type CellFormat struct {
	Fg        colors.RGB
	Bg        colors.RGB
	Italic    bool
	Underline bool
	Blinking  bool
}

CellFormat describes all the properties of a single cell on screen.

func (CellFormat) Empty

func (c CellFormat) Empty() bool

Empty reports whether the CellFormat is black on black. In that case it doesn't matter if it's italic or underlined.

type CellStride

type CellStride []Cell

CellStride is a slice of cells.

func (CellStride) Formats

func (c CellStride) Formats() []CellFormat

Formats returns cells format as a slice.

func (CellStride) Runes

func (c CellStride) Runes() []rune

Runes returns runes as a slice.

type Rect

type Rect struct {
	X, Y, Width, Height int
}

Rect is highly inspired by image.Rectangle but uses more standard origin + size instead of two points. It makes the usage much simpler. It implements a small subset of image.Rectangle.

Negative values are invalid.

func (Rect) Empty

func (r Rect) Empty() bool

Empty reports whether the rectangle area is 0.

func (Rect) In

func (r Rect) In(s Rect) bool

In reports whether every point in r is in s.

Jump to

Keyboard shortcuts

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