Table

package
v0.3.23 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmptyRuneCell is a rune that represents an empty cell.
	EmptyRuneCell rune = '\000'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ColoredElement

type ColoredElement[T Colorer] struct {
	// contains filtered or unexported fields
}

ColoredElement represents an element that can be colored.

func NewColoredElement

func NewColoredElement[T Colorer](elem T, style tcell.Style) *ColoredElement[T]

NewColoredElement creates a new ColoredElement with the given element and style.

Parameters:

  • elem: The element of the color.
  • style: The style of the color.

Returns:

  • *ColoredElement: The new ColoredElement.

func (*ColoredElement[T]) Apply

func (ce *ColoredElement[T]) Apply(width, height int) ([][]*ColoredUnit, error)

Apply applies the color to the element.

Parameters:

  • width: The width of the element.
  • height: The height of the element.

Returns:

  • [][]*ColoredUnit: The colored element.
  • error: An error if the element could not be colored.

Behaviors:

  • Always assume that the width and height are greater than 0. No need to check for this.
  • Errors are only for critical issues, such as the element not being able to be colored. However, out of bounds or other issues should not error. Instead, the element should be colored as much as possible before unable to be colored.

func (*ColoredElement[T]) Draw

func (ce *ColoredElement[T]) Draw(table *DrawTable, x, y *int) error

Draw is a method of cdd.TableDrawer that draws the unit to the table at the given x and y coordinates.

Parameters:

  • table: The table to draw the unit to.
  • x: The x coordinate to draw the unit at.
  • y: The y coordinate to draw the unit at.

Returns:

  • error: An error of type *ers.ErrInvalidParameter if the table is nil.

Behaviors:

  • Any value that would be drawn outside of the table is not drawn.
  • Assumes that the table is not nil.

type ColoredText

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

ColoredText is a unit that represents a colored text.

func NewColoredText

func NewColoredText(bgStyle tcell.Style) *ColoredText

NewColoredText creates a new colored text with the given background color.

Parameters:

  • bgStyle: The background color of the colored text.

Returns:

  • *ColoredText: The new colored text.

func (*ColoredText) Append

func (ct *ColoredText) Append(elem TableDrawer)

Append appends the given text to the colored text with the given style.

Parameters:

  • elem: The text to append.
  • style: The style of the text.

func (*ColoredText) Draw

func (ct *ColoredText) Draw(table *DrawTable, x, y *int) error

Draw is a method of cdd.TableDrawer that draws the unit to the table at the given x and y coordinates.

Parameters:

  • table: The table to draw the unit to.
  • x: The x coordinate to draw the unit at.
  • y: The y coordinate to draw the unit at.

Returns:

  • error: An error of type *ers.ErrInvalidParameter if the table is nil.

Behaviors:

  • Any value that would be drawn outside of the table is not drawn.
  • Assumes that the table is not nil.

type ColoredUnit

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

ColoredUnit represents a unit that contains a single color.

func NewColoredUnit

func NewColoredUnit(content rune, style tcell.Style) *ColoredUnit

NewColoredUnit creates a new ColorUnit with the given content and style.

Parameters:

  • content: The content of the color.
  • style: The style of the color.

Returns:

  • *ColoredUnit: The new ColoredUnit.

func (*ColoredUnit) GetContent

func (cu *ColoredUnit) GetContent() rune

GetContent returns the content of the color.

Returns:

  • rune: The content of the color.

func (*ColoredUnit) GetStyle

func (cu *ColoredUnit) GetStyle() tcell.Style

GetStyle returns the style of the color.

Returns:

  • tcell.Style: The style of the color.

func (*ColoredUnit) Runes

func (cu *ColoredUnit) Runes(width, height int) ([][]rune, error)

Runes returns the content of the color as a 2D slice of runes given the size of the table.

Parameters:

  • width: The width of the table.
  • height: The height of the table.

Returns:

  • [][]rune: The content of the color as a 2D slice of runes.
  • error: An error if the content could not be converted to runes.

Behaviors:

  • Always assume that the width and height are greater than 0. No need to check for

type Colorer

type Colorer interface {
	// Runes returns the content of the unit as a 2D slice of runes
	// given the size of the table.
	//
	// Parameters:
	//   - width: The width of the table.
	//   - height: The height of the table.
	//
	// Returns:
	//   - [][]rune: The content of the unit as a 2D slice of runes.
	//   - error: An error if the content could not be converted to runes.
	//
	// Behaviors:
	//   - Always assume that the width and height are greater than 0. No need to check for
	//     this.
	//   - Errors are only for critical issues, such as the content not being able to be
	//     converted to runes. However, out of bounds or other issues should not error.
	//     Instead, the content should be drawn as much as possible before unable to be
	//     drawn.
	Runes(width, height int) ([][]rune, error)
}

type DrawTable

type DrawTable struct {
	*cdt.Table[*ColoredUnit]
}

DrawTable represents a table of cells that can be drawn to the screen.

func NewDrawTable

func NewDrawTable(width, height int) *DrawTable

NewDrawTable creates a new DrawTable with the given width and height.

Parameters:

  • width: The width of the drawTable.
  • height: The height of the drawTable.

Returns:

  • *DrawTable: The new drawTable.

Behaviors:

  • If the width or height is negative, the absolute value is used.

func (*DrawTable) GetLines

func (dt *DrawTable) GetLines() []string

GetLines returns each line of the drawTable as a string.

Returns:

  • []string: The lines of the drawTable.

Behaviors:

  • Any nil cells in the drawTable are represented by a space character.
  • The last line may not be full width.

func (*DrawTable) WriteLineAt

func (dt *DrawTable) WriteLineAt(x, y *int, line string, style tcell.Style, isHorizontal bool)

WriteLineAt writes a string to the drawTable at the given coordinates.

Parameters:

  • x: The x-coordinate of the starting cell.
  • y: The y-coordinate of the starting cell.
  • line: The string to write to the drawTable.
  • style: The style of the string.
  • isHorizontal: A boolean that determines if the string should be written horizontally or vertically.

Behaviors:

  • This is just a convenience function that converts the string to a sequence of cells and calls WriteHorizontalSequence or WriteVerticalSequence.
  • x and y are updated to the next available cell after the line is written.

type TableDrawer

type TableDrawer interface {
	// Draw is a method of cdd.TableDrawer that draws the unit to the table at the given x and y
	// coordinates.
	//
	// Parameters:
	//   - table: The table to draw the unit to.
	//   - x: The x coordinate to draw the unit at.
	//   - y: The y coordinate to draw the unit at.
	//
	// Returns:
	//   - error: An error of type *ers.ErrInvalidParameter if the table is nil.
	//
	// Behaviors:
	//   - Any value that would be drawn outside of the table is not drawn.
	//   - Assumes that the table is not nil.
	Draw(table *DrawTable, x, y *int) error

	Colorer
}

Jump to

Keyboard shortcuts

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