Documentation
¶
Index ¶
- Constants
- Variables
- func Clear(s CellBuffer)
- func ClearRect(s CellBuffer, rect Rectangle)
- func Fill(s CellBuffer, c *Cell)
- func FillRect(s CellBuffer, c *Cell, rect Rectangle)
- func Height(s string) int
- func ReadLink(p []byte, link *Link)
- func ReadStyle(params ansi.Params, pen *Style)
- func ReadStyleColor(params ansi.Params, c *color.Color) int
- func Render(d CellBuffer) string
- func RenderLine(d CellBuffer, n int) (w int, line string)
- func SetContent(s CellBuffer, str string)
- func SetContentRect(s CellBuffer, str string, rect Rectangle)
- func Wrap(s string, limit int, breakpoints string) string
- type AttrMask
- type Buffer
- func (b *Buffer) Bounds() Rectangle
- func (b *Buffer) Cell(x int, y int) *Cell
- func (b *Buffer) Clear()
- func (b *Buffer) ClearRect(rect Rectangle)
- func (b *Buffer) DeleteCell(x, y, n int, c *Cell)
- func (b *Buffer) DeleteCellRect(x, y, n int, c *Cell, rect Rectangle)
- func (b *Buffer) DeleteLine(y, n int, c *Cell)
- func (b *Buffer) DeleteLineRect(y, n int, c *Cell, rect Rectangle)
- func (b *Buffer) Fill(c *Cell)
- func (b *Buffer) FillRect(c *Cell, rect Rectangle)
- func (b *Buffer) Height() int
- func (b *Buffer) InsertCell(x, y, n int, c *Cell)
- func (b *Buffer) InsertCellRect(x, y, n int, c *Cell, rect Rectangle)
- func (b *Buffer) InsertLine(y, n int, c *Cell)
- func (b *Buffer) InsertLineRect(y, n int, c *Cell, rect Rectangle)
- func (b *Buffer) Line(y int) Line
- func (b *Buffer) Resize(width int, height int)
- func (b *Buffer) SetCell(x, y int, c *Cell) bool
- func (b *Buffer) String() (s string)
- func (b *Buffer) Width() int
- type Cell
- type CellBuffer
- type Cursor
- type Line
- type Link
- type Position
- type Rectangle
- type Screen
- func (s *Screen) Bounds() Rectangle
- func (s *Screen) Cell(x int, y int) *Cell
- func (s *Screen) Clear() bool
- func (s *Screen) ClearRect(r Rectangle) bool
- func (s *Screen) Close() (err error)
- func (s *Screen) EnterAltScreen()
- func (s *Screen) ExitAltScreen()
- func (s *Screen) Fill(cell *Cell) bool
- func (s *Screen) FillRect(cell *Cell, r Rectangle) bool
- func (s *Screen) Flush() (err error)
- func (s *Screen) Height() int
- func (s *Screen) HideCursor()
- func (s *Screen) InsertAbove(str string)
- func (s *Screen) MoveTo(x, y int)
- func (s *Screen) Redraw()
- func (s *Screen) Render()
- func (s *Screen) Resize(width, height int) bool
- func (s *Screen) SetCell(x int, y int, cell *Cell) (v bool)
- func (s *Screen) SetColorProfile(p colorprofile.Profile)
- func (s *Screen) SetMethod(method ansi.Method)
- func (s *Screen) SetRelativeCursor(v bool)
- func (s *Screen) ShowCursor()
- func (s *Screen) UseBackspaces(v bool)
- func (s *Screen) UseHardTabs(v bool)
- func (s *Screen) Width() int
- type ScreenOptions
- type ScreenWriter
- func (s *ScreenWriter) Print(str string, v ...interface{})
- func (s *ScreenWriter) PrintAt(x, y int, str string, v ...interface{})
- func (s *ScreenWriter) PrintCrop(str string, tail string)
- func (s *ScreenWriter) PrintCropAt(x, y int, str string, tail string)
- func (s *ScreenWriter) SetContent(str string)
- func (s *ScreenWriter) SetContentRect(str string, rect Rectangle)
- func (s *ScreenWriter) Write(p []byte) (n int, err error)
- type Style
- func (s *Style) Background(c ansi.Color) *Style
- func (s *Style) Bold(v bool) *Style
- func (s *Style) Clear() bool
- func (s *Style) Conceal(v bool) *Style
- func (s Style) DiffSequence(o Style) string
- func (s *Style) Empty() bool
- func (s *Style) Equal(o *Style) bool
- func (s *Style) Faint(v bool) *Style
- func (s *Style) Foreground(c ansi.Color) *Style
- func (s *Style) Italic(v bool) *Style
- func (s *Style) RapidBlink(v bool) *Style
- func (s *Style) Reset() *Style
- func (s *Style) Reverse(v bool) *Style
- func (s Style) Sequence() string
- func (s *Style) SlowBlink(v bool) *Style
- func (s *Style) Strikethrough(v bool) *Style
- func (s *Style) Underline(v bool) *Style
- func (s *Style) UnderlineColor(c ansi.Color) *Style
- func (s *Style) UnderlineStyle(style UnderlineStyle) *Style
- type TabStops
- type UnderlineStyle
Constants ¶
const ( NoUnderline = ansi.NoUnderlineStyle SingleUnderline = ansi.SingleUnderlineStyle DoubleUnderline = ansi.DoubleUnderlineStyle CurlyUnderline = ansi.CurlyUnderlineStyle DottedUnderline = ansi.DottedUnderlineStyle DashedUnderline = ansi.DashedUnderlineStyle )
These are the available underline styles.
const DefaultTabInterval = 8
DefaultTabInterval is the default tab interval.
Variables ¶
var ( // BlankCell is a cell with a single space, width of 1, and no style or link. BlankCell = Cell{Rune: ' ', Width: 1} // EmptyCell is just an empty cell used for comparisons and as a placeholder // for wide cells. EmptyCell = Cell{} )
var ErrInvalidDimensions = errors.New("invalid dimensions")
ErrInvalidDimensions is returned when the dimensions of a window are invalid for the operation.
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(s CellBuffer)
Clear clears the cell buffer with blank cells.
func ClearRect ¶ added in v0.0.12
func ClearRect(s CellBuffer, rect Rectangle)
ClearRect clears the rectangle within the cell buffer with blank cells.
func FillRect ¶ added in v0.0.12
func FillRect(s CellBuffer, c *Cell, rect Rectangle)
FillRect fills the rectangle within the cell buffer with the given cell. This will not fill cells outside the bounds of the cell buffer.
func ReadStyle ¶ added in v0.0.7
ReadStyle reads a Select Graphic Rendition (SGR) escape sequences from a list of parameters.
func ReadStyleColor ¶ added in v0.0.7
ReadStyleColor reads a color from a list of parameters. See ansi.ReadStyleColor for more information.
func Render ¶
func Render(d CellBuffer) string
Render returns a string representation of the grid with ANSI escape sequences.
func RenderLine ¶
func RenderLine(d CellBuffer, 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.
func SetContent ¶ added in v0.0.2
func SetContent(s CellBuffer, str string)
SetContent clears the cell buffer with blank cells, and sets the given string as its content. If the height or width of the string exceeds the height or width of the cell buffer, it will be truncated.
func SetContentRect ¶ added in v0.0.12
func SetContentRect(s CellBuffer, str string, rect Rectangle)
SetContentRect clears the rectangle within the cell buffer with blank cells, and sets the given string as its content. If the height or width of the string exceeds the height or width of the cell buffer, it will be truncated.
func Wrap ¶ added in v0.0.12
Wrap returns a string that is wrapped to the specified limit applying any ANSI escape sequences in the string. It tries to wrap the string at word boundaries, but will break words if necessary.
The breakpoints string is a list of characters that are considered breakpoints for word wrapping. A hyphen (-) is always considered a breakpoint.
Note: breakpoints must be a string of 1-cell wide rune characters.
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.
type Buffer ¶
type Buffer struct { // Lines holds the lines of the buffer. Lines []Line }
Buffer is a 2D grid of cells representing a screen or terminal.
func NewBuffer ¶ added in v0.0.6
NewBuffer creates a new buffer with the given width and height. This is a convenience function that initializes a new buffer and resizes it.
func (*Buffer) Clear ¶ added in v0.0.7
func (b *Buffer) Clear()
Clear clears the buffer with space cells and rectangle.
func (*Buffer) ClearRect ¶ added in v0.0.7
ClearRect clears the buffer with space cells within the specified rectangles. Only cells within the rectangle's bounds are affected.
func (*Buffer) DeleteCell ¶ added in v0.0.7
DeleteCell deletes cells at the given position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it deletes cells in the entire buffer. This follows terminal ansi.DCH behavior.
func (*Buffer) DeleteCellRect ¶ added in v0.0.7
DeleteCellRect deletes cells at the given position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's bounds are affected, following terminal ansi.DCH behavior.
func (*Buffer) DeleteLine ¶ added in v0.0.7
DeleteLine deletes n lines at the given line position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it deletes lines in the entire buffer.
func (*Buffer) DeleteLineRect ¶ added in v0.0.7
DeleteLineRect deletes lines at the given line position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's bounds are affected. Lines are shifted up within the bounds and new blank lines are created at the bottom. This follows terminal ansi.DL behavior.
func (*Buffer) FillRect ¶ added in v0.0.7
FillRect fills the buffer with the given cell and rectangle.
func (*Buffer) InsertCell ¶ added in v0.0.7
InsertCell inserts new cells at the given position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it inserts cells in the entire buffer. This follows terminal ansi.ICH behavior.
func (*Buffer) InsertCellRect ¶ added in v0.0.7
InsertCellRect inserts new cells at the given position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's bounds are affected, following terminal ansi.ICH behavior.
func (*Buffer) InsertLine ¶ added in v0.0.7
InsertLine inserts n lines at the given line position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it inserts lines in the entire buffer. Only cells within the rectangle's horizontal bounds are affected. Lines are pushed out of the rectangle bounds and lost. This follows terminal ansi.IL behavior. It returns the pushed out lines.
func (*Buffer) InsertLineRect ¶ added in v0.0.7
InsertLineRect inserts new lines at the given line position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's horizontal bounds are affected. Lines are pushed out of the rectangle bounds and lost. This follows terminal ansi.IL behavior.
func (*Buffer) Line ¶ added in v0.0.7
Line returns a pointer to the line at the given y position. If the line does not exist, it returns nil.
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 // Comb is the combining runes of the cell. This is nil if the cell is a // single rune or if it's a zero width cell that is part of a wider cell. Comb []rune // Width is the mono-space width of the grapheme cluster. Width int // Rune is the main rune of the cell. This is zero if the cell is part of a // wider cell. Rune rune }
Cell represents a single cell in the terminal screen.
func NewCell ¶ added in v0.0.7
NewCell returns a new cell. This is a convenience function that initializes a new cell with the given content. The cell's width is determined by the content using runewidth.RuneWidth. This will only account for the first combined rune in the content. If the content is empty, it will return an empty cell with a width of 0.
func NewCellString ¶ added in v0.0.7
NewCellString returns a new cell with the given string content. This is a convenience function that initializes a new cell with the given content. The cell's width is determined by the content using runewidth.StringWidth. This will only use the first combined rune in the string. If the string is empty, it will return an empty cell with a width of 0.
func NewGraphemeCell ¶ added in v0.0.7
NewGraphemeCell returns a new cell. This is a convenience function that initializes a new cell with the given content. The cell's width is determined by the content using uniseg.FirstGraphemeClusterInString. This is used when the content is a grapheme cluster i.e. a sequence of runes that form a single visual unit. This will only return the first grapheme cluster in the string. If the string is empty, it will return an empty cell with a width of 0.
func (*Cell) Append ¶ added in v0.0.9
Append appends runes to the cell without changing the width. This is useful when we want to use the cell to store escape sequences or other runes that don't affect the width of the cell.
func (*Cell) Blank ¶ added in v0.0.7
Blank makes the cell a blank cell by setting the rune to a space, comb to nil, and the width to 1.
func (*Cell) Clear ¶ added in v0.0.7
Clear returns whether the cell consists of only attributes that don't affect appearance of a space character.
func (Cell) Empty ¶
Empty returns whether the cell is an empty cell. An empty cell is a cell with a width of 0, a rune of 0, and no combining runes.
type CellBuffer ¶ added in v0.0.12
type CellBuffer interface { // Cell returns the cell at the given position. Cell(x, y int) *Cell // SetCell sets the cell at the given position to the given cell. It // returns whether the cell was set successfully. SetCell(x, y int, c *Cell) bool // Bounds returns the bounds of the cell buffer. Bounds() Rectangle }
CellBuffer is a cell buffer that represents a set of cells in a screen or a grid.
type Line ¶ added in v0.0.7
type Line []*Cell
Line represents a line in the terminal. A nil cell represents an blank cell, a cell with a space character and a width of 1. If a cell has no content and a width of 0, it is a placeholder for a wide cell.
func (Line) At ¶ added in v0.0.7
At returns the cell at the given x position. If the cell does not exist, it returns nil.
func (Line) Set ¶ added in v0.0.7
Set sets the cell at the given x position. If a wide cell is given, it will set the cell and the following cells to EmptyCell. It returns true if the cell was set.
type Link ¶
Link represents a hyperlink in the terminal screen.
func ConvertLink ¶ added in v0.0.6
func ConvertLink(h Link, p colorprofile.Profile) Link
Convert converts a hyperlink to respect the given color profile.
type Screen ¶ added in v0.0.2
type Screen struct {
// contains filtered or unexported fields
}
Screen represents the terminal screen.
func NewScreen ¶ added in v0.0.7
func NewScreen(w io.Writer, width, height int, opts *ScreenOptions) (s *Screen)
NewScreen creates a new Screen.
func (*Screen) Clear ¶ added in v0.0.7
Clear clears the screen with blank cells. This is a convenience method for Screen.Fill with a nil cell.
func (*Screen) ClearRect ¶ added in v0.0.7
ClearRect clears the given rectangle with blank cells. This is a convenience method for Screen.FillRect with a nil cell.
func (*Screen) EnterAltScreen ¶ added in v0.0.7
func (s *Screen) EnterAltScreen()
EnterAltScreen enters the alternate screen buffer.
func (*Screen) ExitAltScreen ¶ added in v0.0.7
func (s *Screen) ExitAltScreen()
ExitAltScreen exits the alternate screen buffer.
func (*Screen) HideCursor ¶ added in v0.0.7
func (s *Screen) HideCursor()
HideCursor hides the cursor.
func (*Screen) InsertAbove ¶ added in v0.0.7
InsertAbove inserts string above the screen. The inserted string is not managed by the screen. This does nothing when alternate screen mode is enabled.
func (*Screen) Redraw ¶ added in v0.0.9
func (s *Screen) Redraw()
Redraw forces a full redraw of the screen.
func (*Screen) Render ¶ added in v0.0.7
func (s *Screen) Render()
Render renders changes of the screen to the internal buffer. Call Screen.Flush to flush pending changes to the screen.
func (*Screen) SetColorProfile ¶ added in v0.0.7
func (s *Screen) SetColorProfile(p colorprofile.Profile)
SetColorProfile sets the color profile to use when writing to the screen.
func (*Screen) SetMethod ¶ added in v0.0.7
SetMethod sets the method used to calculate the width of cells.
func (*Screen) SetRelativeCursor ¶ added in v0.0.7
SetRelativeCursor sets whether to use relative cursor movements.
func (*Screen) ShowCursor ¶ added in v0.0.7
func (s *Screen) ShowCursor()
ShowCursor shows the cursor.
func (*Screen) UseBackspaces ¶ added in v0.0.11
UseBackspaces sets whether to use backspace characters to move the cursor.
func (*Screen) UseHardTabs ¶ added in v0.0.7
UseHardTabs sets whether to use hard tabs to optimize cursor movements.
type ScreenOptions ¶ added in v0.0.7
type ScreenOptions struct { // Term is the terminal type to use when writing to the screen. When empty, // `$TERM` is used from [os.Getenv]. Term string // Profile is the color profile to use when writing to the screen. Profile colorprofile.Profile // RelativeCursor is whether to use relative cursor movements. This is // useful when alt-screen is not used or when using inline mode. RelativeCursor bool // AltScreen is whether to use the alternate screen buffer. AltScreen bool // ShowCursor is whether to show the cursor. ShowCursor bool // HardTabs is whether to use hard tabs to optimize cursor movements. HardTabs bool // Backspace is whether to use backspace characters to move the cursor. Backspace bool }
ScreenOptions are options for the screen.
type ScreenWriter ¶ added in v0.0.11
type ScreenWriter struct {
*Screen
}
ScreenWriter represents a writer that writes to a Screen parsing ANSI escape sequences and Unicode characters and converting them into cells that can be written to a cell Buffer.
func NewScreenWriter ¶ added in v0.0.11
func NewScreenWriter(s *Screen) *ScreenWriter
NewScreenWriter creates a new ScreenWriter that writes to the given Screen. This is a convenience function for creating a ScreenWriter.
func (*ScreenWriter) Print ¶ added in v0.0.11
func (s *ScreenWriter) Print(str string, v ...interface{})
Print prints the string at the current cursor position. It will wrap the string to the width of the screen if it exceeds the width of the screen. This will recognize ANSI ansi.SGR style and ansi.SetHyperlink escape sequences.
func (*ScreenWriter) PrintAt ¶ added in v0.0.11
func (s *ScreenWriter) PrintAt(x, y int, str string, v ...interface{})
PrintAt prints the string at the given position. It will wrap the string to the width of the screen if it exceeds the width of the screen. This will recognize ANSI ansi.SGR style and ansi.SetHyperlink escape sequences.
func (*ScreenWriter) PrintCrop ¶ added in v0.0.11
func (s *ScreenWriter) PrintCrop(str string, tail string)
PrintCrop prints the string at the current cursor position and truncates the text if it exceeds the width of the screen. Use tail to specify a string to append if the string is truncated. This will recognize ANSI ansi.SGR style and ansi.SetHyperlink escape sequences.
func (*ScreenWriter) PrintCropAt ¶ added in v0.0.11
func (s *ScreenWriter) PrintCropAt(x, y int, str string, tail string)
PrintCropAt prints the string at the given position and truncates the text if it exceeds the width of the screen. Use tail to specify a string to append if the string is truncated. This will recognize ANSI ansi.SGR style and ansi.SetHyperlink escape sequences.
func (*ScreenWriter) SetContent ¶ added in v0.0.11
func (s *ScreenWriter) SetContent(str string)
SetContent clears the screen with blank cells, and sets the given string as its content. If the height or width of the string exceeds the height or width of the screen, it will be truncated.
This will recognize ANSI ansi.SGR style and ansi.SetHyperlink escape sequences.
func (*ScreenWriter) SetContentRect ¶ added in v0.0.11
func (s *ScreenWriter) SetContentRect(str string, rect Rectangle)
SetContentRect clears the rectangle within the screen with blank cells, and sets the given string as its content. If the height or width of the string exceeds the height or width of the screen, it will be truncated.
This will recognize ANSI ansi.SGR style and ansi.SetHyperlink escape sequences.
func (*ScreenWriter) Write ¶ added in v0.0.11
func (s *ScreenWriter) Write(p []byte) (n int, err error)
Write writes the given bytes to the screen. This will recognize ANSI ansi.SGR style and ansi.SetHyperlink escape sequences.
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 ConvertStyle ¶ added in v0.0.6
func ConvertStyle(s Style, p colorprofile.Profile) Style
Convert converts a style to respect the given color profile.
func (*Style) Background ¶
Background sets the background color.
func (*Style) Clear ¶ added in v0.0.7
Clear returns whether the style consists of only attributes that don't affect appearance of a space character.
func (Style) DiffSequence ¶
DiffSequence returns the ANSI sequence that sets the style as a diff from another style.
func (*Style) Foreground ¶
Foreground sets the foreground color.
func (*Style) RapidBlink ¶
RapidBlink sets the rapid blink attribute.
func (*Style) Strikethrough ¶
Strikethrough sets the strikethrough attribute.
func (*Style) Underline ¶
Underline sets the underline attribute. This is a syntactic sugar for UnderlineStyle.
func (*Style) UnderlineColor ¶
UnderlineColor sets the underline color.
func (*Style) UnderlineStyle ¶
func (s *Style) UnderlineStyle(style UnderlineStyle) *Style
UnderlineStyle sets the underline style.
type TabStops ¶ added in v0.0.7
type TabStops struct {
// contains filtered or unexported fields
}
TabStops represents horizontal line tab stops.
func DefaultTabStops ¶ added in v0.0.7
DefaultTabStops creates a new set of tab stops with the default interval.
func NewTabStops ¶ added in v0.0.7
NewTabStops creates a new set of tab stops from a number of columns and an interval.
func (TabStops) Find ¶ added in v0.0.7
Find returns the prev/next tab stop before/after the given column and delta. If delta is positive, it returns the next tab stop after the given column. If delta is negative, it returns the previous tab stop before the given column. If delta is zero, it returns the given column.
type UnderlineStyle ¶
type UnderlineStyle = ansi.UnderlineStyle
UnderlineStyle is the style of underline to use for text.