UNPKG

console-gui-tools

Version:

A simple library to draw option menu, text popup or other widgets and layout on a Node.js console.

197 lines 7.1 kB
import { BackgroundColorName, ForegroundColorName } from "chalk"; /** * @typedef {string} HEX - The type of the HEX color. * @example const hexColor = "#FF0000" * * @typedef {string} RGB - The type of the RGB color. * @example const rgbColor = "rgb(255, 0, 0)" */ export type HEX = `#${string}`; export type RGB = `rgb(${number}, ${number}, ${number})` | `rgb(${number},${number},${number})`; /** * @description The type containing all the possible styles for the text. * * @typedef {Object} StyleObject * @prop {chalk.ForegroundColorName | HEX | RGB | ""} [color] - The color of the text taken from the chalk library. * @prop {chalk.BackgroundColorName | HEX | RGB | ""} [backgroundColor] - The background color of the text taken from the chalk library. * @prop {boolean} [italic] - If the text is italic. * @prop {boolean} [bold] - If the text is bold. * @prop {boolean} [dim] - If the text is dim. * @prop {boolean} [underline] - If the text is underlined. * @prop {boolean} [inverse] - If the text is inverse. * @prop {boolean} [hidden] - If the text is hidden. * @prop {boolean} [strikethrough] - If the text is strikethrough. * @prop {boolean} [overline] - If the text is overlined. * * @example const textStyle = { color: "red", backgroundColor: "blue", bold: true, italic: true } * * @export * @interface StyleObject */ export interface StyleObject { color?: ForegroundColorName | HEX | RGB | ""; bg?: BackgroundColorName | HEX | RGB | ""; italic?: boolean; bold?: boolean; dim?: boolean; underline?: boolean; inverse?: boolean; hidden?: boolean; strikethrough?: boolean; overline?: boolean; } /** * @description The type of the single styled text, stored in a line of the PageBuilder. * * @typedef {Object} StyledElement * @prop {string} text - The text of the styled text. * @prop {StyleObject} style - The style of the styled text. * * @example const styledText = { text: "Hello", style: { color: "red", backgroundColor: "blue", bold: true, italic: true } } * * @export * @interface StyledElement */ export interface StyledElement { text: string; style: StyleObject; } /** * @description The type containing all the possible styles for the text and the text on the same level. It's used on the higher level. * * @typedef {Object} SimplifiedStyledElement * @prop {string} text - The text of the styled text. * @prop {chalk.ForegroundColorName | HEX | RGB | ""} [color] - The color of the text taken from the chalk library. * @prop {chalk.BackgroundColorName | HEX | RGB | "" | ""} [backgroundColor] - The background color of the text taken from the chalk library. * @prop {boolean} [italic] - If the text is italic. * @prop {boolean} [bold] - If the text is bold. * @prop {boolean} [dim] - If the text is dim. * @prop {boolean} [underline] - If the text is underlined. * @prop {boolean} [inverse] - If the text is inverse. * @prop {boolean} [hidden] - If the text is hidden. * @prop {boolean} [strikethrough] - If the text is strikethrough. * @prop {boolean} [overline] - If the text is overlined. * * @example const textStyle = { color: "red", backgroundColor: "blue", bold: true, italic: true } * * @export * @interface SimplifiedStyledElement */ export interface SimplifiedStyledElement { text: string; color?: ForegroundColorName | HEX | RGB | ""; bg?: BackgroundColorName | HEX | RGB | "" | ""; italic?: boolean; bold?: boolean; dim?: boolean; underline?: boolean; inverse?: boolean; hidden?: boolean; strikethrough?: boolean; overline?: boolean; } /** * @description The type that contains the phisical values of an element (x, y, width, height) * * @export * @interface PhisicalValues */ export interface PhisicalValues { x: number; y: number; width: number; height: number; id?: number; } /** @const {Object} boxChars - The characters used to draw the box. */ export declare const boxChars: { normal: { topLeft: string; topRight: string; bottomLeft: string; bottomRight: string; horizontal: string; vertical: string; cross: string; left: string; right: string; top: string; bottom: string; start: string; end: string; color: "" | `#${string}` | RGB | keyof import("chalk/source/vendor/ansi-styles").ForegroundColor; }; selected: { topLeft: string; topRight: string; bottomLeft: string; bottomRight: string; horizontal: string; vertical: string; cross: string; left: string; right: string; top: string; bottom: string; start: string; end: string; color: "" | `#${string}` | RGB | keyof import("chalk/source/vendor/ansi-styles").ForegroundColor; }; hovered: { topLeft: string; topRight: string; bottomLeft: string; bottomRight: string; horizontal: string; vertical: string; cross: string; left: string; right: string; top: string; bottom: string; start: string; end: string; color: "" | `#${string}` | RGB | keyof import("chalk/source/vendor/ansi-styles").ForegroundColor; }; }; /** * @description This function is used to truncate a string adding ... at the end. * @param {string} str - The string to truncate. * @param {number} n - The number of characters to keep. * @param {boolean} useWordBoundary - If true, the truncation will be done at the end of the word. * @example CM.truncate("Hello world", 5, true) // "Hello..." */ export declare function truncate(str: string, n: number, useWordBoundary: boolean): string; /** * @description This function is used to convert a styled element to a simplified styled element. * * @export * @param {StyledElement} styled * @return {*} {SimplifiedStyledElement} * * @example const simplifiedStyledElement = styledToSimplifiedStyled({ text: "Hello world", style: { color: "red", backgroundColor: "blue", bold: true, italic: true } }) * // returns { text: "Hello world", color: "red", backgroundColor: "blue", bold: true, italic: true } */ export declare function styledToSimplifiedStyled(styled: StyledElement): SimplifiedStyledElement; /** * @description This function is used to convert a simplified styled element to a styled element. * * @export * @param {SimplifiedStyledElement} simplifiedStyled * @return {*} {StyledElement} * * @example const styledElement = simplifiedStyledToStyled({ text: "Hello world", color: "red", bold: true }) * // returns { text: "Hello world", style: { color: "red", bold: true } } */ export declare function simplifiedStyledToStyled(simplifiedStyled: SimplifiedStyledElement): StyledElement; /** * @description Count true visible length of a string * * @export * @param {string} input * @return {number} * * @author Vitalik Gordon (xpl) */ export declare function visibleLength(input: string): number; //# sourceMappingURL=Utils.d.ts.map