@futils/commandline
v1.0.0
Published
A simple utility for using the commandline
Downloads
2
Readme
commandline
A simple utility for using the commandline
colors
This object contains a list of colorcodes for ansi 256 terminals
color
type Color =
| {
space: 'fg' | 'bg';
color:
| 'black'
| 'blue'
| 'cyan'
| 'gray'
| 'green'
| 'magenta'
| 'red'
| 'white'
| 'yellow';
}
| {
space: 'fgBright' | 'bgBright';
color:
| 'black'
| 'blue'
| 'cyan'
| 'green'
| 'magenta'
| 'red'
| 'white'
| 'yellow';
}
| {
space: 'reset';
color:
| 'all'
| 'underline'
| 'bold'
| 'strikethrough'
| 'italic'
| 'bg'
| 'fg'
| 'colorAll'
| 'style';
}
| {
space: 'style';
color: 'italic' | 'strikethrough' | 'underline' | 'bold';
};
function color(text: string, color: Color): string;
Color a text
getInput
function getInput(question: string): Promise<string>;
Gets input from the user over stdin
removeTerminalColors
function removeTerminalColors(text: string): string;
Removes terminal (ansi) colorcodes from a string
removeAnsiColors
function removeAnsiColors(text: string): string;
Removes ansi colorcodes from a string
createTextbox
function createTextbox(title: string | undefined, contents: string): string;
Creates a textbox
createTable
function createTable<T extends string>(
header: string,
keys: T[],
data: { [Key in T]: string | number | boolean | { type: 'delimiter' } }[],
differentiateLines: boolean | undefined = false
): string
Creates a table. Specify all the keys in the keys array. The header is the title. Specify the data into data. The data can be a delimiter by setting the current data value to { type: 'delimiter' }
.
applyPadding
export interface PaddingOptions {
top?: number;
left?: number;
right?: number;
bottom?: number;
}
function applyPadding(str: string, padding?: PaddingOptions);
Applies padding (uses spaces (
) and newlines (\n
))
TextboxBuilder
Creates a textbox
setTitle
function setTitle(title: string): TextboxBuilder;
sets the title
setFooter
function setFooter(footer: string): TextboxBuilder;
sets the footer
paddingLeft
function paddingLeft(padding: number): TextboxBuilder;
Sets the padding to the left
paddingRight
function paddingRight(padding: number): TextboxBuilder;
Sets the padding to the right
padding
function padding(padding: { left: number; right: number; }): TextboxBuilder;
Sets the padding
getPaddingLeft
function getPaddingLeft(): number;
Gets the left-padding
getPaddingRight
function getPaddingRight(): number;
Gets the right-padding
getPadding
function getPadding(): { left: number; right: number; };
Gets the padding
getFooter
function getFooter(): string;
Gets the footer
addLine
function addLine(line: string): TextboxBuilder;
Adds a line to the textbox
addLines
function addLines(lines: string|string[]): TextboxBuilder;
Adds 1 or more lines to the textbox
setMinLength
function setMinLength(length: number): TextboxBuilder;
Sets the minimum length of the textbox
getMinLength
function getMinLength(): number;
Gets the minimum length
addDivider
function addDivider(): TextboxBuilder
Adds a divider between lines
getLines
function getLines(): (string|{ type: 'divider' })[];
Gets the lines
getTitle
function getTitle(): string;
Gets the title
removeLine
function removeLine(last?: boolean): TextboxBuilder
Removes the last or first line. Defaults to firstline
build
function build(): string;
Builds the textbox
log
function log(loggingFunction?: (text: string) => void): void;
Logs the textbox, defaults to console.log