This commit is contained in:
Kent Wong
2018-12-06 16:43:14 -08:00
parent 5e483391e5
commit e009d1c3c0
4 changed files with 141 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import Box = require('cli-box');
// Create a simple box
const b1: Box = Box("20x10");
// console.log(b1.toString());
// Set custom marks
const b2: Box = new Box({
w: 10
, h: 10
, stringify: false
, marks: {
nw: "╔"
, n: "══"
, ne: "╗"
, e: "║"
, se: "╝"
, s: "══"
, sw: "╚"
, w: "║"
, b: "░░"
}
});
// console.log(b2.stringify());
// Box with text and use the stringify
const b3: Box = Box("20x10", "I will be \u001b[31mdis\u001b[0mplayed inside! \n A\u001b[34mnd I'm in a\u001b[0m new line!");
// console.log(b3);
// Box with aligned text to top-right
const b4: Box = Box("30x20", {
text: "Box content"
, stretch: true
, autoEOL: true
, vAlign: "top"
, hAlign: "right"
});
// console.log(b4);
// Full screen box
const b5: Box = Box({fullscreen: true, marks: {}}, "Hello World!");
// console.log(b5.toString());
const b5s: string = Box({stringify: true, fullscreen: true, marks: {}}, "Hello World!");
const b5ns: Box = Box({stringify: false, fullscreen: true, marks: {}}, "Hello World!");
const defaults = Box.defaults;
+70
View File
@@ -0,0 +1,70 @@
// Type definitions for cli-box 6.0
// Project: https://github.com/IonicaBizau/node-cli-box
// Definitions by: Kent Wong <https://github.com/athasach>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/*~ Note that ES6 modules cannot directly export callable functions.
*~ This file should be imported using the CommonJS-style:
*~ import x = require('someLibrary');
*~
*~ Refer to the documentation to understand common
*~ workarounds for this limitation of ES6 modules.
*/
/*~ This declaration specifies that the function
*~ is the exported object from the file
*/
export = Box;
type MarksKeys = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'b';
type Marks = Record<MarksKeys, string>;
interface Options {
w?: number;
width?: number;
h?: number;
height?: number;
fullscreen?: boolean;
stringify?: boolean;
marks?: Partial<Marks>;
}
interface Text {
text?: string;
stretch?: boolean;
autoEOL?: boolean;
hAlign?: 'left' | 'middle' | 'right';
vAlign?: 'top' | 'center' | 'bottom';
}
interface Box {
stringify(): string;
settings: {
width: number;
height: number;
marks: Marks;
lines: Array<{
text: string;
offset: {
y: number;
}
}>
};
options: {
width: number;
height: number;
marks: Marks;
fullscreen: boolean;
stringify: boolean;
};
}
interface BoxConstructor {
new(options: Options | string, text?: Text | string): Box;
(options: (Exclude<Options, 'stringify'> & { stringify: true }), text?: Text | string): string;
(options: Options | string, text?: Text | string): Box;
defaults: { marks: Marks };
}
declare const Box: BoxConstructor;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"cli-box-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }