mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add types for cli-color 2.0 (#41358)
This commit is contained in:
parent
17cb4a9032
commit
7f91641db9
5
types/cli-color/art.d.ts
vendored
Normal file
5
types/cli-color/art.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Create a text-graphical art. Within *styleConf*, string replacements needs to be defined, which are then used to convert *text* to styled graphical text.
|
||||
*/
|
||||
declare function art(text: string, styleConf: Record<string, string>): string;
|
||||
export = art;
|
||||
55
types/cli-color/bare.d.ts
vendored
Normal file
55
types/cli-color/bare.d.ts
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
declare namespace bare {
|
||||
export interface Format {
|
||||
(...text: any[]): string;
|
||||
|
||||
readonly bold: Format;
|
||||
readonly italic: Format;
|
||||
readonly underline: Format;
|
||||
readonly blink: Format;
|
||||
readonly inverse: Format;
|
||||
readonly strike: Format;
|
||||
|
||||
readonly black: Format;
|
||||
readonly red: Format;
|
||||
readonly green: Format;
|
||||
readonly yellow: Format;
|
||||
readonly blue: Format;
|
||||
readonly magenta: Format;
|
||||
readonly cyan: Format;
|
||||
readonly white: Format;
|
||||
|
||||
readonly bgBlack: Format;
|
||||
readonly bgRed: Format;
|
||||
readonly bgGreen: Format;
|
||||
readonly bgYellow: Format;
|
||||
readonly bgBlue: Format;
|
||||
readonly bgMagenta: Format;
|
||||
readonly bgCyan: Format;
|
||||
readonly bgWhite: Format;
|
||||
|
||||
readonly blackBright: Format;
|
||||
readonly redBright: Format;
|
||||
readonly greenBright: Format;
|
||||
readonly yellowBright: Format;
|
||||
readonly blueBright: Format;
|
||||
readonly magentaBright: Format;
|
||||
readonly cyanBright: Format;
|
||||
readonly whiteBright: Format;
|
||||
|
||||
readonly bgBlackBright: Format;
|
||||
readonly bgRedBright: Format;
|
||||
readonly bgGreenBright: Format;
|
||||
readonly bgYellowBright: Format;
|
||||
readonly bgBlueBright: Format;
|
||||
readonly bgMagentaBright: Format;
|
||||
readonly bgCyanBright: Format;
|
||||
readonly bgWhiteBright: Format;
|
||||
|
||||
xterm(color: number): Format;
|
||||
bgXterm(color: number): Format;
|
||||
readonly xtermSupported: boolean;
|
||||
}
|
||||
}
|
||||
declare const bare: bare.Format;
|
||||
export = bare;
|
||||
2
types/cli-color/beep.d.ts
vendored
Normal file
2
types/cli-color/beep.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
declare const beep: string;
|
||||
export = beep;
|
||||
@ -2,54 +2,110 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import clc = require('cli-color');
|
||||
import ansiTrim = require('cli-color/trim');
|
||||
import ansiStrip = require('cli-color/strip');
|
||||
import setupThrobber = require('cli-color/throbber');
|
||||
import bare = require('cli-color/bare');
|
||||
|
||||
var text: string;
|
||||
var color: number;
|
||||
var x: number;
|
||||
var y: number;
|
||||
var n: number;
|
||||
var period: number;
|
||||
let text: string;
|
||||
let period: number;
|
||||
let format: clc.Format;
|
||||
format = bare.red.redBright;
|
||||
text = format();
|
||||
|
||||
// Test cli-color
|
||||
text = clc('foo');
|
||||
text = clc('foo', 42, { toString: () => 'bar' });
|
||||
|
||||
text = clc.red("Text in red");
|
||||
text = clc.red.bgWhite.underline("Underlined red text on white background.");
|
||||
text = clc.red("red") + " plain " + clc.blue("blue");
|
||||
text = clc.red("red " + clc.blue("blue") + " red");
|
||||
text = clc.bold.italic.underline.blink.inverse.strike(text);
|
||||
text = clc.black.red.green.yellow.blue.magenta.cyan.white(text);
|
||||
text = clc.bgBlack.bgRed.bgGreen.bgYellow.bgBlack.bgMagenta.bgCyan.bgWhite(text);
|
||||
text = clc.blackBright.redBright.greenBright.yellowBright.blueBright.magentaBright.cyanBright.whiteBright(text);
|
||||
text = clc.bgBlackBright.bgRedBright.bgGreenBright.bgYellowBright.bgBlueBright.bgMagentaBright.bgCyanBright.bgWhiteBright(text);
|
||||
text = clc.xterm(color).bgXterm(color)(text);
|
||||
|
||||
text = clc.bold.red.bgGreen.yellowBright.bgBlueBright.xterm(color)(text, text, text);
|
||||
|
||||
text = clc.move(x, y);
|
||||
text = clc.moveTo(x, y);
|
||||
text = clc.bol();
|
||||
text = clc.bol(n);
|
||||
text = clc.bol(n, true);
|
||||
text = clc.up(n);
|
||||
text = clc.down(n);
|
||||
text = clc.left(n);
|
||||
text = clc.right(n);
|
||||
const error: clc.Format = clc.red.bold;
|
||||
const warn: clc.Format = clc.yellow;
|
||||
const notice: clc.Format = clc.blue;
|
||||
text = error("Error!");
|
||||
text = warn("Warning");
|
||||
text = notice("Notice");
|
||||
|
||||
format = clc.xterm(202).bgXterm(236);
|
||||
text = format("Orange text on dark gray background");
|
||||
|
||||
text = clc.beep;
|
||||
text = clc.reset;
|
||||
text = clc.erase.screen;
|
||||
text = clc.erase.screenLeft;
|
||||
text = clc.erase.screenRight;
|
||||
text = clc.erase.line;
|
||||
text = clc.erase.lineRight;
|
||||
text = clc.erase.lineLeft;
|
||||
|
||||
var width: number = clc.width;
|
||||
var height: number = clc.height;
|
||||
text = clc.move(-2, -2); // Move cursors two columns and two rows back
|
||||
text = clc.move.to(0, 0); // Move cursor to first row and first column in terminal window
|
||||
text = clc.move.up(2);
|
||||
text = clc.move.down(2);
|
||||
text = clc.move.right(2);
|
||||
text = clc.move.left(2);
|
||||
text = clc.move.lines(2);
|
||||
text = clc.move.top;
|
||||
text = clc.move.bottom;
|
||||
text = clc.move.lineBegin;
|
||||
text = clc.move.lineEnd;
|
||||
|
||||
var width: number = clc.windowSize.width;
|
||||
var height: number = clc.windowSize.height;
|
||||
var support: boolean = clc.xtermSupported;
|
||||
|
||||
// Test cli-color/trim
|
||||
text = ansiTrim(clc.red(text));
|
||||
text = clc.bold("foo") + "bar" + clc.red("elo");
|
||||
text = clc.slice(text, 1, 7); // Same as: clc.bold('oo') + 'bar' + clc.red('e')
|
||||
|
||||
text = ansiStrip(text);
|
||||
|
||||
text = clc.bold("foo") + "bar" + clc.red("elo");
|
||||
var len: number = clc.getStrippedLength(text); // 9
|
||||
|
||||
text = ".........\n" + ". Hello .\n" + ".........\n";
|
||||
var style = { ".": clc.yellowBright("X") };
|
||||
text = clc.art(text, style);
|
||||
|
||||
text =
|
||||
clc.columns([
|
||||
[clc.bold("First Name"), clc.bold("Last Name"), clc.bold("Age")], ["John", "Doe", 34],
|
||||
["Martha", "Smith", 20], ["Jan", "Kowalski", 30]
|
||||
]);
|
||||
|
||||
text =
|
||||
clc.columns([
|
||||
[clc.bold("First Name"), clc.bold("Last Name"), clc.bold("Age")], ["John", "Doe", 34],
|
||||
["Martha", "Smith", 20], { [0]: "Jan", [1]: "Kowalski", [2]: 30, length: 3 }
|
||||
]);
|
||||
|
||||
text =
|
||||
clc.columns([
|
||||
[clc.bold("First Name"), clc.bold("Last Name"), clc.bold("Age")], ["John", "Doe", 34],
|
||||
["Martha", "Smith", 20], ["Jan", "Kowalski", 30]
|
||||
], { sep: '|' });
|
||||
text =
|
||||
clc.columns([
|
||||
[clc.bold("First Name"), clc.bold("Last Name"), clc.bold("Age")], ["John", "Doe", 34],
|
||||
["Martha", "Smith", 20], ["Jan", "Kowalski", 30]
|
||||
], { columns: [{ align: 'right' }, null, { align: 'left' }] });
|
||||
|
||||
// Test cli-color/throbber
|
||||
var throbber: setupThrobber.Throbber;
|
||||
|
||||
throbber = setupThrobber(process.stdout.write.bind(process.stdout), period);
|
||||
throbber = setupThrobber(process.stdout.write.bind(process.stdout), period, clc.red);
|
||||
|
||||
throbber.start();
|
||||
throbber.stop();
|
||||
throbber.restart();
|
||||
|
||||
var iterator = new clc.throbber.Iterator();
|
||||
text = iterator.next();
|
||||
text = iterator.reset();
|
||||
|
||||
29
types/cli-color/columns.d.ts
vendored
Normal file
29
types/cli-color/columns.d.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
declare namespace columns {
|
||||
export interface ColumnOptions {
|
||||
/**
|
||||
* align: Possible options: `'left'`, `'right'` (defaults to `'left'`)
|
||||
*/
|
||||
align?: 'left' | 'right';
|
||||
}
|
||||
|
||||
export interface ColumnsOptions {
|
||||
/**
|
||||
* Custom colums separator (defaults to `|`)
|
||||
*/
|
||||
sep?: string;
|
||||
/**
|
||||
* columns: Per column customizations, as e.g. `[{ align: 'right' }, null, { align: 'left' }]`
|
||||
*/
|
||||
columns?: Array<ColumnOptions | null>;
|
||||
}
|
||||
|
||||
export type Row = Iterable<any> | ArrayLike<any>;
|
||||
export type Data = Iterable<Row> | ArrayLike<Row>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs aligned table of columns.
|
||||
*/
|
||||
declare function columns(data: ReadonlyArray<ReadonlyArray<any>>, options?: columns.ColumnsOptions): string;
|
||||
declare function columns(data: columns.Data, options?: columns.ColumnsOptions): string;
|
||||
export = columns;
|
||||
29
types/cli-color/erase.d.ts
vendored
Normal file
29
types/cli-color/erase.d.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
interface Erase {
|
||||
/**
|
||||
* Entire screen
|
||||
*/
|
||||
readonly screen: string;
|
||||
/**
|
||||
* Left portion of a screen
|
||||
*/
|
||||
readonly screenLeft: string;
|
||||
/**
|
||||
* Right portion of a screen
|
||||
*/
|
||||
readonly screenRight: string;
|
||||
/**
|
||||
* Current line
|
||||
*/
|
||||
readonly line: string;
|
||||
/**
|
||||
* Right portion of current line
|
||||
*/
|
||||
readonly lineLeft: string;
|
||||
/**
|
||||
* Left portion of current line
|
||||
*/
|
||||
readonly lineRight: string;
|
||||
}
|
||||
|
||||
declare const erase: Erase;
|
||||
export = erase;
|
||||
5
types/cli-color/get-stripped-length.d.ts
vendored
Normal file
5
types/cli-color/get-stripped-length.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Get actual length of ANSI-formatted string
|
||||
*/
|
||||
declare function getStrippedLength(str: string): number;
|
||||
export = getStrippedLength;
|
||||
96
types/cli-color/index.d.ts
vendored
96
types/cli-color/index.d.ts
vendored
@ -1,73 +1,41 @@
|
||||
// Type definitions for cli-color 0.3.2
|
||||
// Type definitions for cli-color 2.0
|
||||
// Project: https://github.com/medikoo/cli-color
|
||||
// Definitions by: Joel Spadin <https://github.com/ChaosinaCan>
|
||||
// OpportunityLiu <https://github.com/OpportunityLiu>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
declare namespace m {
|
||||
export interface Format {
|
||||
(...text: any[]): string;
|
||||
|
||||
bold: Format;
|
||||
italic: Format;
|
||||
underline: Format;
|
||||
blink: Format;
|
||||
inverse: Format;
|
||||
strike: Format;
|
||||
import art = require('./art');
|
||||
import bare = require('./bare');
|
||||
import beep = require('./beep');
|
||||
import columns = require('./columns');
|
||||
import erase = require('./erase');
|
||||
import move = require('./move');
|
||||
import getStrippedLength = require('./get-stripped-length');
|
||||
import slice = require('./slice');
|
||||
import strip = require('./strip');
|
||||
import throbber = require('./throbber');
|
||||
import reset = require('./reset');
|
||||
import windowSize = require('./window-size');
|
||||
|
||||
black: Format;
|
||||
red: Format;
|
||||
green: Format;
|
||||
yellow: Format;
|
||||
blue: Format;
|
||||
magenta: Format;
|
||||
cyan: Format;
|
||||
white: Format;
|
||||
declare namespace clc {
|
||||
export type Format = bare.Format;
|
||||
export type ColumnOptions = columns.ColumnOptions;
|
||||
export type ColumnsOptions = columns.ColumnsOptions;
|
||||
export interface Color extends Format {
|
||||
|
||||
bgBlack: Format;
|
||||
bgRed: Format;
|
||||
bgGreen: Format;
|
||||
bgYellow: Format;
|
||||
bgBlue: Format;
|
||||
bgMagenta: Format;
|
||||
bgCyan: Format;
|
||||
bgWhite: Format;
|
||||
|
||||
blackBright: Format;
|
||||
redBright: Format;
|
||||
greenBright: Format;
|
||||
yellowBright: Format;
|
||||
blueBright: Format;
|
||||
magentaBright: Format;
|
||||
cyanBright: Format;
|
||||
whiteBright: Format;
|
||||
|
||||
bgBlackBright: Format;
|
||||
bgRedBright: Format;
|
||||
bgGreenBright: Format;
|
||||
bgYellowBright: Format;
|
||||
bgBlueBright: Format;
|
||||
bgMagentaBright: Format;
|
||||
bgCyanBright: Format;
|
||||
bgWhiteBright: Format;
|
||||
|
||||
xterm(color: number): Format;
|
||||
bgXterm(color: number): Format;
|
||||
|
||||
move(x: number, y: number): string;
|
||||
moveTo(x: number, y: number): string;
|
||||
bol(n?: number, erase?: boolean): string;
|
||||
up(n: number): string;
|
||||
down(n: number): string;
|
||||
left(n: number): string;
|
||||
right(n: number): string;
|
||||
|
||||
beep: string;
|
||||
reset: string;
|
||||
|
||||
width: number;
|
||||
height: number;
|
||||
xtermSupported: boolean;
|
||||
readonly windowSize: typeof windowSize;
|
||||
readonly erase: typeof erase;
|
||||
readonly move: typeof move;
|
||||
readonly beep: typeof beep;
|
||||
readonly columns: typeof columns;
|
||||
readonly strip: typeof strip;
|
||||
readonly getStrippedLength: typeof getStrippedLength;
|
||||
readonly slice: typeof slice;
|
||||
readonly throbber: typeof throbber;
|
||||
readonly reset: typeof reset;
|
||||
readonly art: typeof art;
|
||||
}
|
||||
}
|
||||
|
||||
declare var m: m.Format;
|
||||
export = m;
|
||||
declare const clc: clc.Color;
|
||||
export = clc;
|
||||
|
||||
56
types/cli-color/move.d.ts
vendored
Normal file
56
types/cli-color/move.d.ts
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
type MoveFunction1 = (n?: number) => string;
|
||||
type MoveFunction2 = (x?: number, y?: number) => string;
|
||||
|
||||
/**
|
||||
* Move around functions
|
||||
*/
|
||||
interface Move {
|
||||
|
||||
/**
|
||||
* Move cursor x columns and y rows away. Values can be positive or negative
|
||||
*/
|
||||
(x?: number, y?: number): string;
|
||||
/**
|
||||
* Move cursor up n rows
|
||||
*/
|
||||
readonly up: MoveFunction1;
|
||||
/**
|
||||
* Move cursor down n rows
|
||||
*/
|
||||
readonly down: MoveFunction1;
|
||||
/**
|
||||
* Move cursor right n columns
|
||||
*/
|
||||
readonly right: MoveFunction1;
|
||||
/**
|
||||
* Move cursor left n columns
|
||||
*/
|
||||
readonly left: MoveFunction1;
|
||||
/**
|
||||
* Absolute move. Sets cursor position at x column and y row
|
||||
*/
|
||||
readonly to: MoveFunction2;
|
||||
/**
|
||||
* Move cursor n lines forward if n is positive, otherwise n lines backward, and place it at line beginning
|
||||
*/
|
||||
readonly lines: MoveFunction1;
|
||||
/**
|
||||
* Move cursor to top of a screen
|
||||
*/
|
||||
readonly top: string;
|
||||
/**
|
||||
* Move cursor to bottom of a screen
|
||||
*/
|
||||
readonly bottom: string;
|
||||
/**
|
||||
* Move cursor to begin of a line
|
||||
*/
|
||||
readonly lineBegin: string;
|
||||
/**
|
||||
* Move cursor to end of a line
|
||||
*/
|
||||
readonly lineEnd: string;
|
||||
}
|
||||
|
||||
declare const move: Move;
|
||||
export = move;
|
||||
5
types/cli-color/reset.d.ts
vendored
Normal file
5
types/cli-color/reset.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Terminal can be cleared with `clc.reset`
|
||||
*/
|
||||
declare const reset: string;
|
||||
export = reset;
|
||||
5
types/cli-color/slice.d.ts
vendored
Normal file
5
types/cli-color/slice.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Slice provided string with preservation of eventual ANSI formatting
|
||||
*/
|
||||
declare function slice(str: string, begin?: number, end?: number): string;
|
||||
export = slice;
|
||||
5
types/cli-color/strip.d.ts
vendored
Normal file
5
types/cli-color/strip.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Strip ANSI formatting from string
|
||||
*/
|
||||
declare function strip(str: string): string;
|
||||
export = strip;
|
||||
15
types/cli-color/throbber.d.ts
vendored
15
types/cli-color/throbber.d.ts
vendored
@ -1,12 +1,19 @@
|
||||
import clc = require('cli-color');
|
||||
|
||||
declare namespace setupThrobber {
|
||||
export interface Throbber {
|
||||
start(): void;
|
||||
stop(): void;
|
||||
restart(): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare function setupThrobber(write: (str: string) => any, period: number, format?: clc.Format): setupThrobber.Throbber;
|
||||
export class Iterator {
|
||||
readonly index: number;
|
||||
readonly running: boolean;
|
||||
next(): string;
|
||||
reset(): string;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Writes throbber string to *write* function at given *interval*. Optionally throbber output can be formatted with given *format* function
|
||||
*/
|
||||
declare function setupThrobber(write: (str: string) => void, interval: number, format?: (throbber: string) => string): setupThrobber.Throbber;
|
||||
export = setupThrobber;
|
||||
|
||||
2
types/cli-color/trim.d.ts
vendored
2
types/cli-color/trim.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
declare function ansiTrim(str: string): string;
|
||||
export = ansiTrim;
|
||||
13
types/cli-color/window-size.d.ts
vendored
Normal file
13
types/cli-color/window-size.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
interface WindowSize {
|
||||
/**
|
||||
* Returns terminal width
|
||||
*/
|
||||
readonly width: number,
|
||||
/**
|
||||
* Returns terminal height
|
||||
*/
|
||||
readonly height: number
|
||||
}
|
||||
|
||||
declare const windowSize: WindowSize;
|
||||
export = windowSize;
|
||||
Loading…
Reference in New Issue
Block a user