Documentation
¶
Overview ¶
Package draw provides functions that draw lines, shapes, etc on 2-D terminal like canvases.
Index ¶
- Constants
- func Border(c *canvas.Canvas, border image.Rectangle, opts ...BorderOption) error
- func BrailleLine(bc *braille.Canvas, start, end image.Point, opts ...BrailleLineOption) error
- func HVLines(c *canvas.Canvas, lines []HVLine, opts ...HVLineOption) error
- func Rectangle(c *canvas.Canvas, r image.Rectangle, opts ...RectangleOption) error
- func Text(c *canvas.Canvas, text string, start image.Point, opts ...TextOption) error
- func TrimText(text string, maxCells int, om OverrunMode) (string, error)
- type BorderOption
- type BrailleLineOption
- type HVLine
- type HVLineOption
- type LineStyle
- type OverrunMode
- type RectangleOption
- type TextOption
Constants ¶
const DefaultBorderLineStyle = LineStyleLight
DefaultBorderLineStyle is the default value for the BorderLineStyle option.
const DefaultHVLineStyle = LineStyleLight
DefaultHVLineStyle is the default value for the HVLineStyle option.
const DefaultRectChar = ' '
DefaultRectChar is the default value for the RectChar option.
Variables ¶
This section is empty.
Functions ¶
func BrailleLine ¶ added in v0.3.0
BrailleLine draws an approximated line segment on the braille canvas between the two provided points. Both start and end must be valid points within the canvas. Start and end can be the same point in which case only one pixel will be set on the braille canvas. The start or end coordinates must not be negative.
func HVLines ¶ added in v0.3.0
func HVLines(c *canvas.Canvas, lines []HVLine, opts ...HVLineOption) error
HVLines draws horizontal or vertical lines. Handles drawing of the correct characters for locations where any two lines cross (e.g. a corner, a T shape or a cross). Each line must be at least two cells long. Both start and end must be on the same horizontal (same X coordinate) or same vertical (same Y coordinate) line.
Types ¶
type BorderOption ¶
type BorderOption interface {
// contains filtered or unexported methods
}
BorderOption is used to provide options to Border().
func BorderCellOpts ¶
func BorderCellOpts(opts ...cell.Option) BorderOption
BorderCellOpts sets options on the cells that create the border.
func BorderLineStyle ¶
func BorderLineStyle(ls LineStyle) BorderOption
BorderLineStyle sets the style of the line used to draw the border.
func BorderTitle ¶
func BorderTitle(title string, overrun OverrunMode, opts ...cell.Option) BorderOption
BorderTitle sets a title for the border.
func BorderTitleAlign ¶
func BorderTitleAlign(h align.Horizontal) BorderOption
BorderTitleAlign configures the horizontal alignment for the title.
type BrailleLineOption ¶ added in v0.3.0
type BrailleLineOption interface {
// contains filtered or unexported methods
}
BrailleLineOption is used to provide options to BrailleLine().
func BrailleLineCellOpts ¶ added in v0.3.0
func BrailleLineCellOpts(cOpts ...cell.Option) BrailleLineOption
BrailleLineCellOpts sets options on the cells that contain the line.
type HVLine ¶ added in v0.3.0
type HVLine struct {
// Start is the cell where the line starts.
Start image.Point
// End is the cell where the line ends.
End image.Point
}
HVLine represents one horizontal or vertical line.
type HVLineOption ¶ added in v0.3.0
type HVLineOption interface {
// contains filtered or unexported methods
}
HVLineOption is used to provide options to HVLine().
func HVLineCellOpts ¶ added in v0.3.0
func HVLineCellOpts(cOpts ...cell.Option) HVLineOption
HVLineCellOpts sets options on the cells that contain the line.
func HVLineStyle ¶ added in v0.3.0
func HVLineStyle(ls LineStyle) HVLineOption
HVLineStyle sets the style of the line. Defaults to DefaultHVLineStyle.
type OverrunMode ¶
type OverrunMode int
OverrunMode represents
const ( // OverrunModeStrict verifies that the drawn value fits the canvas and // returns an error if it doesn't. OverrunModeStrict OverrunMode = iota // OverrunModeTrim trims the part of the text that doesn't fit. OverrunModeTrim // OverrunModeThreeDot trims the text and places the horizontal ellipsis // '…' character at the end. OverrunModeThreeDot )
type RectangleOption ¶
type RectangleOption interface {
// contains filtered or unexported methods
}
RectangleOption is used to provide options to the Rectangle function.
func RectCellOpts ¶
func RectCellOpts(opts ...cell.Option) RectangleOption
RectCellOpts sets options on the cells that create the rectangle.
func RectChar ¶
func RectChar(c rune) RectangleOption
RectChar sets the character used in each of the cells of the rectangle.
type TextOption ¶
type TextOption interface {
// contains filtered or unexported methods
}
TextOption is used to provide options to Text().
func TextCellOpts ¶
func TextCellOpts(opts ...cell.Option) TextOption
TextCellOpts sets options on the cells that contain the text.
func TextMaxX ¶
func TextMaxX(x int) TextOption
TextMaxX sets a limit on the X coordinate (column) of the drawn text. The X coordinate of all cells used by the text must be within start.X <= X < TextMaxX. If not provided, the width of the canvas is used as TextMaxX.
func TextOverrunMode ¶
func TextOverrunMode(om OverrunMode) TextOption
TextOverrunMode indicates what to do with text that overruns the TextMaxX() or the width of the canvas if TextMaxX() isn't specified. Defaults to OverrunModeStrict.