Documentation and formatting
This commit is contained in:
26
utils/tui.js
26
utils/tui.js
@@ -88,7 +88,7 @@ export class FramingOptions {
|
|||||||
// Dark block: ▓ (U+2593)
|
// Dark block: ▓ (U+2593)
|
||||||
// Solid block: █ (U+2588)
|
// Solid block: █ (U+2588)
|
||||||
/** @type {string} Single character to use as filler inside the frame. */
|
/** @type {string} Single character to use as filler inside the frame. */
|
||||||
paddingChar = " "; // character used for padding inside the frame.
|
paddingChar = " ";
|
||||||
|
|
||||||
/** @type {string} Single character to use as filler outside the frame. */
|
/** @type {string} Single character to use as filler outside the frame. */
|
||||||
marginChar = " ";
|
marginChar = " ";
|
||||||
@@ -114,10 +114,7 @@ export class FramingOptions {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Do we have custom and valid frame chars?
|
// Do we have custom and valid frame chars?
|
||||||
if (
|
if (typeof o.frameChars === "string" && o.frameChars.length === FrameType.values.Double.length) {
|
||||||
typeof o.frameChars === "string" &&
|
|
||||||
o.frameChars.length === FrameType.values.Double.length
|
|
||||||
) {
|
|
||||||
result.frameChars = o.frameChars;
|
result.frameChars = o.frameChars;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -156,9 +153,7 @@ export function frameText(text, options) {
|
|||||||
|
|
||||||
if (typeof text !== "string") {
|
if (typeof text !== "string") {
|
||||||
console.debug(text);
|
console.debug(text);
|
||||||
throw new Error(
|
throw new Error(`text argument was neither an array or a string, it was a ${typeof text}`);
|
||||||
`text argument was neither an array or a string, it was a ${typeof text}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
@@ -176,12 +171,7 @@ export function frameText(text, options) {
|
|||||||
|
|
||||||
const frameThickness = 1; // always 1 for now.
|
const frameThickness = 1; // always 1 for now.
|
||||||
|
|
||||||
const outerLineLength =
|
const outerLineLength = 0 + innerLineLength + frameThickness * 2 + options.hPadding * 2 + options.hMargin * 2;
|
||||||
0 +
|
|
||||||
innerLineLength +
|
|
||||||
frameThickness * 2 +
|
|
||||||
options.hPadding * 2 +
|
|
||||||
options.hMargin * 2;
|
|
||||||
|
|
||||||
// get the frame characters from the frameType.
|
// get the frame characters from the frameType.
|
||||||
let [
|
let [
|
||||||
@@ -230,9 +220,7 @@ export function frameText(text, options) {
|
|||||||
// ( space, and what if we want to nest many )
|
// ( space, and what if we want to nest many )
|
||||||
// ( frames inside each other? )
|
// ( frames inside each other? )
|
||||||
//
|
//
|
||||||
output += (options.marginChar.repeat(outerLineLength) + "\n").repeat(
|
output += (options.marginChar.repeat(outerLineLength) + "\n").repeat(options.vMargin);
|
||||||
options.vMargin,
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// GENERATE THE TOP PART OF THE FRAME
|
// GENERATE THE TOP PART OF THE FRAME
|
||||||
@@ -326,9 +314,7 @@ export function frameText(text, options) {
|
|||||||
// ( space, and what if we want to nest many )
|
// ( space, and what if we want to nest many )
|
||||||
// ( frames inside each other? )
|
// ( frames inside each other? )
|
||||||
//
|
//
|
||||||
output += (options.marginChar.repeat(outerLineLength) + "\n").repeat(
|
output += (options.marginChar.repeat(outerLineLength) + "\n").repeat(options.vMargin);
|
||||||
options.vMargin,
|
|
||||||
);
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user