Merge pull request #30202 from Gustavo6046/master

Updating the ANSI typings.
This commit is contained in:
Armando Aguirre
2018-11-05 16:38:43 -08:00
committed by GitHub
2 changed files with 25 additions and 4 deletions
+9 -1
View File
@@ -20,5 +20,13 @@ Object.keys({
, brightCyan: 96
, brightWhite: 97
}).forEach((color) => {
cursor[color]().bold().write(`Hello, bold ${color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`)} world!\n`).reset();
const cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`);
((<(...anything: any[]) => ansi.Cursor> cursor[color])()
.bold()
.bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']()
.write(
`Hello, bold ${cname} world!\n`
)
.reset();
});
+16 -3
View File
@@ -2,6 +2,7 @@
// Project: https://www.npmjs.com/package/ansi
// Definitions by: Gustavo6046 <https://github.com/Gustavo6046>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/**
* References:
@@ -14,11 +15,19 @@
/// <reference types="node" />
import { Stream } from "stream";
declare function ansi(stream: Stream, options?: any): ansi.Cursor;
interface CursorOptions {
enabled: boolean;
buffering: boolean;
}
declare function ansi(stream: Stream, options?: CursorOptions): ansi.Cursor;
declare namespace ansi {
class Cursor {
constructor(stream: Stream, options?: any);
bg: Colorer;
fg: Colorer;
constructor(stream: Stream, options?: CursorOptions);
/**
* Helper function that calls `write()` on the underlying Stream.
@@ -161,7 +170,11 @@ declare namespace ansi {
}
interface Cursor {
[key: string]: (...anything: any[]) => Cursor;
[key: string]: ((...anything: any[]) => Cursor) | Colorer;
}
interface Colorer {
[key: string]: (...anything: any[]) => (Cursor | Colorer);
}
}