-
-
Notifications
You must be signed in to change notification settings - Fork 0
Module: draw block
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(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
topis not specified, usehTheme. - If
hThemeis not specified, usetheme. - If
themeis 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(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.
drawBlock() and drawFrame() are exported by name. drawBlock() is the default export.