Module: draw block - uhop/console-toolkit GitHub Wiki
The draw-block.js module provides
the drawBlock()
function, which draws a rectangle, and its cousin drawFrame()
function,
which draws a frame. Both functions use a theme.
import {drawBlock, drawFrame} from 'console-toolkit/draw-block.js';
Technically, they draw a frame using a block theme, then fill the interior with some symbol.
If the symbol is not specified, drawBlock()
will use the value supplied by the theme, while
drawFrame()
will use space (
).
drawBlock()
Function drawBlock(width, height, blockTheme, options)
draws a rectangle of given dimensions using
the specified theme. The options
argument is an object with the following properties:
top
— the sub-theme to use for the top side of the rectangle. The default value is1
.bottom
— the sub-theme to use for the bottom side of the rectangle. The default value is1
.left
— the sub-theme to use for the left side of the rectangle. The default value is1
.right
— the sub-theme to use for the right side of the rectangle. The default value is1
.vTheme
— the sub-theme to use for the vertical sides of the rectangle. The default value is1
.hTheme
— the sub-theme to use for the horizontal sides of the rectangle. The default value is1
.theme
— the sub-theme to use for the entire rectangle. The default value is1
.symbol
— the symbol to use to fill the interior of the rectangle. The default value is space (' ').
The algorithm to assign the sub-themes is as follows:
- If
top
is not specified, usehTheme
. - If
hTheme
is not specified, usetheme
. - If
theme
is not specified, use1
.
The same algorithm is used for bottom
. left
and right
are similar but use vTheme
in
the calculation chain.
If symbol
is not specified the f
property of the blockTheme
is used. If it is not specified
by the theme space (
) is used.
The return value is a Box
object with the rectangle drawn.
drawFrame()
Function drawFrame(width, height, frameTheme, options)
draws a frame of given dimensions using
the specified theme. The options
argument is the same as for drawBlock()
.
The difference between drawFrame()
and drawBlock()
is that drawFrame()
draws a frame
and forces to use space (
) for the interior of the frame, if symbol
was not specified
in the options
argument.
Exports
drawBlock()
and drawFrame()
are exported by name. drawBlock()
is the default export.