Module terminal.draw.line
Module for drawing lines.
Provides functions to create lines on a terminal screen.
Functions
horizontal (n[, char="─"]) | Draws a horizontal line and writes it to the terminal. |
title (title, width[, char="─"[, pre=""[, post=""[, type="right"[, title_attr]]]]]) | Draws a horizontal line with a title centered in it and writes it to the terminal. |
title_fmt (width[, title=""[, type="right"]]) | Formats a title for display in a title line. |
vertical (n[, char="│"[, lastcolumn]]) | Draws a vertical line and writes it to the terminal. |
Sequences
horizontal_seq (n[, char="─"]) | Creates a sequence to draw a horizontal line without writing it to the terminal. |
title_seq (width[, title=""[, char="─"[, pre=""[, post=""[, type="right"[, title_attr]]]]]]) | Creates a sequence to draw a horizontal line with a title centered in it without writing it to the terminal. |
vertical_seq (n[, char="│"[, lastcolumn]]) | Creates a sequence to draw a vertical line without writing it to the terminal. |
Functions
- horizontal (n[, char="─"])
-
Draws a horizontal line and writes it to the terminal.
Line is drawn left to right.
Returned sequence might be shorter than requested if the character is a multi-byte character
and the number of columns is not a multiple of the character width.
Parameters:
- n number number of columns to draw
- char string the character to draw (default "─")
Returns:
-
true
- title (title, width[, char="─"[, pre=""[, post=""[, type="right"[, title_attr]]]]])
-
Draws a horizontal line with a title centered in it and writes it to the terminal.
Line is drawn left to right. If the width is too small for the title, the title is truncated with "trailing
"..."
. If less than 4 characters are available for the title, the title is omitted alltogether.Parameters:
- title string the title to draw
- width number the total width of the line in columns
- char string the line-character to use (default "─")
- pre string the prefix for the title, eg. "┤ " (default "")
- post string the postfix for the title, eg. " ├" (default "")
- type string the type of truncation to apply, either "left", "right", or "drop", see title_fmt for details (default "right")
- title_attr
table
table of attributes for the title, eg.
{ fg = "red", bg = "blue" }
(optional)
Returns:
-
true
- title_fmt (width[, title=""[, type="right"]])
-
Formats a title for display in a title line.
Shortens it if necessary, adds ellipsis if necessary. "left" means truncate from the left,
"right" means truncate from the right, "drop" means drop the entire thing all at once.
Parameters:
- width number the available width for the title in columns
- title string the title to format (default "")
- type string the type of truncation to apply, either "left", "right", or "drop" (default "right")
Returns:
- string the formatted title, this can be an empty string if it doesn't fit
- number the size of the returned title in columns
- vertical (n[, char="│"[, lastcolumn]])
-
Draws a vertical line and writes it to the terminal.
Line is drawn top to bottom. Cursor is left to the right of the last character (so not below it).
Parameters:
- n number number of rows/lines to draw
- char string the character to draw (default "│")
- lastcolumn boolean whether to draw the last column of the terminal (optional)
Returns:
-
true
Sequences
- horizontal_seq (n[, char="─"])
-
Creates a sequence to draw a horizontal line without writing it to the terminal.
Line is drawn left to right.
Returned sequence might be shorter than requested if the character is a multi-byte character
and the number of columns is not a multiple of the character width.
Parameters:
- n number number of columns to draw
- char string the character to draw (default "─")
Returns:
-
string
ansi sequence to write to the terminal
- title_seq (width[, title=""[, char="─"[, pre=""[, post=""[, type="right"[, title_attr]]]]]])
-
Creates a sequence to draw a horizontal line with a title centered in it without writing it to the terminal.
Line is drawn left to right. If the width is too small for the title, the title is truncated.
If less than 4 characters are available for the title, the title is omitted alltogether.
Parameters:
- width number the total width of the line in columns
- title string the title to draw (if empty or nil, only the line is drawn) (default "")
- char string the line-character to use (default "─")
- pre string the prefix for the title, eg. "┤ " (default "")
- post string the postfix for the title, eg. " ├" (default "")
- type string the type of truncation to apply, either "left", "right", or "drop", see title_fmt for details (default "right")
- title_attr
table
table of attributes for the title, eg.
{ fg = "red", bg = "blue" }
(optional)
Returns:
- vertical_seq (n[, char="│"[, lastcolumn]])
-
Creates a sequence to draw a vertical line without writing it to the terminal.
Line is drawn top to bottom. Cursor is left to the right of the last character (so not below it).
Parameters:
- n number number of rows/lines to draw
- char string the character to draw (default "│")
- lastcolumn boolean whether to draw the last column of the terminal (optional)
Returns:
-
string
ansi sequence to write to the terminal