box_drawer

package
v0.0.0-...-84d6781 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HeavyCorners is the heavy corners of the box.
	HeavyCorners [4][]byte

	// LightCorners is the light corners of the box.
	LightCorners [4][]byte
)
View Source
var SD box_drawerT

SD is the namespace for SD-like functions.

Functions

This section is empty.

Types

type BoxBorderType

type BoxBorderType int

BoxBorderType is the type of the box border.

const (
	// BtNormal is the normal box border type.
	BtNormal BoxBorderType = iota

	// BtTriple is the triple box border type.
	BtTriple

	// BtQuadruple is the quadruple box border type.
	BtQuadruple

	// BtDouble is the double box border type.
	BtDouble

	// BtRounded is like BtNormal but with rounded corners.
	BtRounded
)

type BoxStyle

type BoxStyle struct {
	// LineType is the type of the line.
	LineType BoxBorderType

	// IsHeavy is whether the line is heavy or not.
	// Only applicable to BtNormal, BtTriple, and BtQuadruple.
	IsHeavy bool

	// Padding is the padding of the box.
	// [Top, Right, Bottom, Left]
	Padding [4]int
}

BoxStyle is the style of the box.

var (
	// DefaultBoxStyle is the default box style, that is, a padding of [1, 1, 1, 1] and
	// a line type of BtNormal (no heavy lines).
	DefaultBoxStyle BoxStyle
)

func NewBoxStyle

func NewBoxStyle(line_type BoxBorderType, is_heavy bool, padding [4]int) BoxStyle

NewBoxStyle creates a new box style.

Negative padding are set to 0.

Parameters:

  • line_type: The line type.
  • is_heavy: Whether the line is heavy or not.
  • padding: The padding of the box. [Top, Right, Bottom, Left]

Returns:

  • BoxStyle: The new box style.

func (BoxStyle) Apply

func (bs BoxStyle) Apply(w io.Writer, data []byte, tab_size int) (int, error)

Apply draws a box around a content that is specified in a table.

Format: If the content is [['H', 'e', 'l', 'l', 'o'], ['W', 'o', 'r', 'l', 'd']], the box will be:

┏━━━━━━━┓
┃ Hello ┃
┃ World ┃
┗━━━━━━━┛

Parameters:

  • w: The underlying io.Writer.
  • data: The content to draw the box around.
  • tab_size: The tab size.

Returns:

  • int: The number of bytes written.
  • error: An error if the content could not be processed.

Behaviors:

  • If the box style is nil, the default box style will be used.

Each string of the content represents a row in the box.

Errors:

  • common.ErrBadParam: If tab_size is not positive or if w is nil.
  • runes.ErrBadEncoding: If an invalid UTF-8 character is encountered.
  • runes.ErrAt: If '\r' is not followed by '\n' at the specified index. This error wraps ErrNotAsExpected.
  • any error returned by the underlying io.Writer.

func (BoxStyle) Corners

func (bs BoxStyle) Corners() [4][]byte

Corners gets the corners of the box.

Returns:

  • [4][]byte: The corners. [TopLeft, TopRight, BottomLeft, BottomRight]

func (BoxStyle) SideBorder

func (bs BoxStyle) SideBorder() []byte

SideBorder gets the side border of the box.

It also applies to the left border as they are the same.

Returns:

  • string: The side border.

func (BoxStyle) TopBorder

func (bs BoxStyle) TopBorder() []byte

TopBorder gets the top border of the box.

It also applies to the bottom border as they are the same.

Returns:

  • string: The top border.

Jump to

Keyboard shortcuts

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