From 3857e2578f1871cf3b2ad0e858fdf8a0320e30a1 Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Tue, 30 Oct 2018 22:47:46 -0300 Subject: [PATCH 01/12] Explicitized options interface. --- types/ansi/index.d.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts index 976268a29a..2b11acc7a3 100644 --- a/types/ansi/index.d.ts +++ b/types/ansi/index.d.ts @@ -14,11 +14,16 @@ /// 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); + constructor(stream: Stream, options?: CursorOptions); /** * Helper function that calls `write()` on the underlying Stream. From 0d341f372340b3137d7a1a2a8c751cab98ae7d9e Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 11:17:30 -0300 Subject: [PATCH 02/12] Updated ANSI typings. --- types/ansi/index.d.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts index 2b11acc7a3..cd1181b5d9 100644 --- a/types/ansi/index.d.ts +++ b/types/ansi/index.d.ts @@ -23,6 +23,9 @@ declare function ansi(stream: Stream, options?: CursorOptions): ansi.Cursor; declare namespace ansi { class Cursor { + bg: Colorer; + fg: Colorer; + constructor(stream: Stream, options?: CursorOptions); /** @@ -165,9 +168,11 @@ declare namespace ansi { brightWhite(): Cursor; } - interface Cursor { - [key: string]: (...anything: any[]) => Cursor; - } + /* Removed index signatures due to conflicts. Now you have to + * add them in consumer code: + * + * <{ [key: string]: (..._: any[]) => Cursor }> myCursorOrColorer; + */ } export = ansi; From c1ec00f135d06eae439b3de127408be6dec04770 Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 11:32:15 -0300 Subject: [PATCH 03/12] Fixed ANSI typings. --- types/ansi/ansi-tests.ts | 2 +- types/ansi/index.d.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index 5d8e73e8ec..09d003a563 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -20,5 +20,5 @@ 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(); + (<{ [key: string]: (..._: any[]) => ansi.Cursor }> 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(); }); diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts index cd1181b5d9..e050aa7c22 100644 --- a/types/ansi/index.d.ts +++ b/types/ansi/index.d.ts @@ -168,11 +168,13 @@ declare namespace ansi { brightWhite(): Cursor; } - /* Removed index signatures due to conflicts. Now you have to - * add them in consumer code: - * - * <{ [key: string]: (..._: any[]) => Cursor }> myCursorOrColorer; - */ + interface Cursor { + [key: string]: ((...anything: any[]) => Cursor) | Colorer; + } + + interface Colorer { + [key: string]: (...anything: any[]) => (Cursor | Colorer); + } } export = ansi; From f6b9c19c45013ff4edff3711686a23532827cf6b Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 11:40:51 -0300 Subject: [PATCH 04/12] Fixed test file line lengths. --- types/ansi/ansi-tests.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index 09d003a563..eda120452d 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -20,5 +20,12 @@ Object.keys({ , brightCyan: 96 , brightWhite: 97 }).forEach((color) => { - (<{ [key: string]: (..._: any[]) => ansi.Cursor }> 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(); + let cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); + + (<(...anything: any[]) => ansi.Cursor> cursor[color])() + .bold() + .write( + `Hello, bold ${cname} world!\n` + ) + .reset(); }); From 8235eb4474dc2738bfa7f03c9133d5def7f6d8c2 Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 11:44:29 -0300 Subject: [PATCH 05/12] Using const... --- types/ansi/ansi-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index eda120452d..cc11ec455e 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -20,7 +20,7 @@ Object.keys({ , brightCyan: 96 , brightWhite: 97 }).forEach((color) => { - let cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); + 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() From 51f918e8c977427cf55ebcac66c68edec4813bad Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 12:03:11 -0300 Subject: [PATCH 06/12] =?UTF-8?q?Added=20background=20coloring=20to=20test?= =?UTF-8?q?=20=C2=AF\=5F(=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/ansi/ansi-tests.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index cc11ec455e..dc6ec1f0da 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -22,8 +22,9 @@ Object.keys({ }).forEach((color) => { const cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); - (<(...anything: any[]) => ansi.Cursor> cursor[color])() + (((<(...anything: any[]) => ansi.Cursor> cursor[color])() .bold() + .bg as ansi.Colorer)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() as ansi.Cursor) .write( `Hello, bold ${cname} world!\n` ) From f09c1b738272f418c2e7b016ef4c497ee618df20 Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 12:10:26 -0300 Subject: [PATCH 07/12] Fixed slight issues regarding casts. --- types/ansi/ansi-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index dc6ec1f0da..b2625defa5 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -22,9 +22,9 @@ Object.keys({ }).forEach((color) => { const cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); - (((<(...anything: any[]) => ansi.Cursor> cursor[color])() + ((<(...anything: any[]) => ansi.Cursor> cursor[color])() .bold() - .bg as ansi.Colorer)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() as ansi.Cursor) + .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() .write( `Hello, bold ${cname} world!\n` ) From 505c4ba3cd92a75e10c068f23d9e06937eabe154 Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 12:16:07 -0300 Subject: [PATCH 08/12] I'm sincerely confused with TypeScript's casting mechanisms. --- types/ansi/ansi-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index b2625defa5..b2ee94a544 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -22,9 +22,9 @@ Object.keys({ }).forEach((color) => { const cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); - ((<(...anything: any[]) => ansi.Cursor> cursor[color])() + (((<(...anything: any[]) => ansi.Cursor> cursor[color])() .bold() - .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() + .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() as ansi.Cursor) .write( `Hello, bold ${cname} world!\n` ) From 48877e1cdfdcd6b62ac6a6640041ef8316a71fef Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 12:51:54 -0300 Subject: [PATCH 09/12] This cast *shall* work... --- types/ansi/ansi-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index b2ee94a544..cfac4aada9 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -22,9 +22,9 @@ Object.keys({ }).forEach((color) => { const cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); - (((<(...anything: any[]) => ansi.Cursor> cursor[color])() + ((((<(...anything: any[]) => ansi.Cursor> cursor[color])() .bold() - .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() as ansi.Cursor) + .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']())) .write( `Hello, bold ${cname} world!\n` ) From 9177bcb136b992b7de8d4bb0bede068f9ebe553c Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 13:04:36 -0300 Subject: [PATCH 10/12] Forcing TypeScript >= 2.1 is the only apparent way. --- types/ansi/ansi-tests.ts | 4 ++-- types/ansi/index.d.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index cfac4aada9..b2625defa5 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -22,9 +22,9 @@ Object.keys({ }).forEach((color) => { const cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); - ((((<(...anything: any[]) => ansi.Cursor> cursor[color])() + ((<(...anything: any[]) => ansi.Cursor> cursor[color])() .bold() - .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']())) + .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() .write( `Hello, bold ${cname} world!\n` ) diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts index e050aa7c22..e027df4c98 100644 --- a/types/ansi/index.d.ts +++ b/types/ansi/index.d.ts @@ -2,6 +2,7 @@ // Project: https://www.npmjs.com/package/ansi // Definitions by: Gustavo6046 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript version: 2.1 /** * References: From 5dd8f459c6aff79bcec4d0c83625c24ed2318c2a Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 19:21:47 -0300 Subject: [PATCH 11/12] Fixed header. --- types/ansi/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts index e027df4c98..61b7a515df 100644 --- a/types/ansi/index.d.ts +++ b/types/ansi/index.d.ts @@ -2,7 +2,7 @@ // Project: https://www.npmjs.com/package/ansi // Definitions by: Gustavo6046 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript version: 2.1 +// TypeScript version: 2.1 /** * References: From 9ab531176b5d06c618132e3e67500fca51b6ad13 Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Thu, 1 Nov 2018 20:08:30 -0300 Subject: [PATCH 12/12] Why isn't the version declaration working? --- types/ansi/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts index 61b7a515df..4e486d61ef 100644 --- a/types/ansi/index.d.ts +++ b/types/ansi/index.d.ts @@ -2,7 +2,7 @@ // Project: https://www.npmjs.com/package/ansi // Definitions by: Gustavo6046 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript version: 2.1 +// TypeScript Version: 2.1 /** * References: