From bd74ec5aa42ac0e9e2062117fd93abd6ad8a41a2 Mon Sep 17 00:00:00 2001 From: Lukas Elmer Date: Mon, 22 Oct 2018 23:44:52 +0200 Subject: [PATCH 1/2] add ascii-art definitions --- types/ascii-art/ascii-art-tests.ts | 193 +++++++++++++++++++++++++++++ types/ascii-art/index.d.ts | 43 +++++++ types/ascii-art/tsconfig.json | 24 ++++ types/ascii-art/tslint.json | 6 + 4 files changed, 266 insertions(+) create mode 100644 types/ascii-art/ascii-art-tests.ts create mode 100644 types/ascii-art/index.d.ts create mode 100644 types/ascii-art/tsconfig.json create mode 100644 types/ascii-art/tslint.json diff --git a/types/ascii-art/ascii-art-tests.ts b/types/ascii-art/ascii-art-tests.ts new file mode 100644 index 0000000000..d061554fd6 --- /dev/null +++ b/types/ascii-art/ascii-art-tests.ts @@ -0,0 +1,193 @@ +import art from 'ascii-art'; + +art.font('test', 'doom').toPromise(); + +art.font('my text', 'Doom', (rendered: string) => { + rendered.big(); +}); + +art.font('my text', 'Doom', '', (rendered) => { + rendered.big(); +}); + +art.artwork({ + artwork: 'textfiles.com/art/st-char.asc' +}).lines(31, 45, function(rendered: string) { + // cleanup non-unix terminators + rendered = rendered.replace(/\r/g, ''); + art.image({ + filepath : '~/Images/earth_in_space.jpg', + alphabet : 'ultra-wide' + }).overlay(rendered, { + x: 0, + y: -1, + style: 'red+blink', + transparent: '&' + }, function(_final: any) {}); +}); + +art.font('Ghost Wire BBS', 'Doom', function(logo) { + art.font('No place like home', 'rusted', function(subtext) { + art.table({ + verticalBar : ' ', + horizontalBar : ' ', + intersection : ' ', + data: [ + {name: art.style('current users', 'red'), value: '203'}, + {name: 'operator', value: 'vince.vega'}, + {name: 'dial-in', value: '(917)555-4202'}, + ] + }).lines(2, function(table: any) { + art.image({ + filepath : '~/Images/starburst_red.jpg', + alphabet : 'ultra-wide' + }).lines(2, 30).overlay(logo, { + x: 0, + y: 0, + style: 'blue', + }).overlay(subtext, { + x: 19, + y: 8, + style: 'yellow', + }).overlay(table, { + x: -1, + y: -1, + style: 'green', + }, function(_final: any) { + }); + }); + }); +}); + +art.image({ + width : 40, + filepath : '/Images/initech.png', + alphabet : 'wide' +}).font('INITECH', 'Doom', 'cyan', function(_ascii) { +}); + +art.table({ + data: [ + {text: ' .\'ANDRE. '}, + {text: ' ..THE.GIANT\'. '}, + {text: '.With.Bobby."The.Brain"'}, + {text: '.Heenan.'} + ], + verticalBar : ' ', + horizontalBar : ' ', + intersection : ' ' +}).lines(2, function(table: any) { + art.strings([ + 'ANDRE', + 'the', + 'GIANT', + 'POSSE', + '7\'4"', + '520 LB' + ], 'rusted', function(andre: any, the: any, giant: any, posse: any, height: any, weight: any) { + art.strings([ 'has', 'a'], 'twopoint', function(has: any, a: any) { + art.image({ + filepath : '/Images/andre_has_a_posse.jpeg', + alphabet : 'ultra-wide' + }).overlay(andre, { + x: 8, y: 4, + style: 'white' + }).overlay(the, { + x: 10, y: 7, + style: 'white', + transparent : true + }).overlay(giant, { + x: 8, y: 10, + style: 'white', + transparent : true + }).overlay(has, { + x: 10, y: 14, + style: 'white' + }).overlay(a, { + x: 13, y: 17, + style: 'white' + }).overlay(posse, { + x: 5, y: 20, + style: 'bright_black', + transparent: true + }).overlay(height, { + x: 59, y: 3, + style: 'bright_black', + transparent: true + }).overlay(weight, { + x: 59, y: 8, + style: 'bright_black', + transparent: true + }).overlay(table, { + x: 6, y: -6, + style: 'bright_black', + transparent: true + }, function(_final: any) { + }); + }); + }); +}); + +art.Figlet.fontPath = 'Fonts'; + +const image = new art.Image({ + filepath: '~/Images/metropolis.jpg', + alphabet: 'variant4' +}); +image.write(function(_err: any, _rendered: string) { +}); + +art.font('Prompt', 'Basic', 'red').font('v1', 'Doom', 'magenta', function(_rendered) { +}); + +art.image({ + width : 40, + filepath : '/Images/initech.png', + alphabet : 'wide' +}).font('INITECH', 'Doom', 'cyan', function(_ascii) { +}); + +art.style('my text', 'red+underline'); + +art.table({ + width : 80, + data : [ /* ... */ ], + verticalBar : ' ', + horizontalBar : ' ', + intersection : ' ', + columns : [ + { + value : 'Product', + style : 'black+gray_bg' + }, { + value : 'Maker', + style : 'white' + }, { + value : 'Location', + style : 'white' + } + ] +}, function(_rendered) { + // use rendered text +}); + +art.table({ + width : 80, + data : [ /* ... */ ], + bars : { + ul_corner: '┏', + ur_corner: '┓', + lr_corner: '┛', + ll_corner: '┗', + bottom_t: '┻', + top_t: '┳', + right_t: '┫', + left_t: '┣', + intersection: '╋', + vertical: '┃', + horizontal: '━', + }, + borderColor : 'bright_white', +}, function(_rendered) { + // use rendered text +}); diff --git a/types/ascii-art/index.d.ts b/types/ascii-art/index.d.ts new file mode 100644 index 0000000000..3a753a183b --- /dev/null +++ b/types/ascii-art/index.d.ts @@ -0,0 +1,43 @@ +// Type definitions for ascii-art 1.4 +// Project: https://github.com/khrome/ascii-art +// Definitions by: Lukas Elmer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +export type StyleType = (text: string, style?: string, close?: boolean) => Art; +export type FontType = ((text: string, font?: string, styleOrCallback?: string | Cb, callback?: Cb) => Art); +export type ImageType = (options: object, callback?: Cb) => Art; +export type TableType = (options: object, callback?: Cb) => Art; +export type ArtworkType = (options: object, callback?: Cb) => Art; +export type LinesType = (...options: any[]) => Art; +export type OverlayType = (...options: any[]) => Art; +export type JoinType = (...options: any[]) => Art; +export type StringsType = (...options: any[]) => Art; + +export const style: StyleType; +export const font: FontType; +export const image: ImageType; +export const table: TableType; +export const artwork: ArtworkType; +export const lines: LinesType; +export const overlay: OverlayType; +export const join: JoinType; +export const strings: StringsType; +export const Figlet: any; +export const Image: any; + +export interface Art { + style: StyleType; + font: FontType; + image: ImageType; + table: TableType; + artwork: ArtworkType; + lines: LinesType; + overlay: OverlayType; + join: JoinType; + working: boolean; + + toPromise: (() => Promise); +} + +export type Cb = (result: string) => void; diff --git a/types/ascii-art/tsconfig.json b/types/ascii-art/tsconfig.json new file mode 100644 index 0000000000..1f9759cc1f --- /dev/null +++ b/types/ascii-art/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "allowSyntheticDefaultImports": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ascii-art-tests.ts" + ] +} diff --git a/types/ascii-art/tslint.json b/types/ascii-art/tslint.json new file mode 100644 index 0000000000..e67cf4277a --- /dev/null +++ b/types/ascii-art/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules":{ + "only-arrow-functions": false + } +} From aa24fb9b00e08ca1758990e849bef9d6bcf7d22c Mon Sep 17 00:00:00 2001 From: Lukas Elmer Date: Tue, 23 Oct 2018 11:41:20 +0200 Subject: [PATCH 2/2] change examples to arrow functions --- types/ascii-art/ascii-art-tests.ts | 32 +++++++++++++++--------------- types/ascii-art/tslint.json | 5 +---- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/types/ascii-art/ascii-art-tests.ts b/types/ascii-art/ascii-art-tests.ts index d061554fd6..d5a2d567f8 100644 --- a/types/ascii-art/ascii-art-tests.ts +++ b/types/ascii-art/ascii-art-tests.ts @@ -12,7 +12,7 @@ art.font('my text', 'Doom', '', (rendered) => { art.artwork({ artwork: 'textfiles.com/art/st-char.asc' -}).lines(31, 45, function(rendered: string) { +}).lines(31, 45, (rendered: string) => { // cleanup non-unix terminators rendered = rendered.replace(/\r/g, ''); art.image({ @@ -23,11 +23,11 @@ art.artwork({ y: -1, style: 'red+blink', transparent: '&' - }, function(_final: any) {}); + }, (_final: any) => {}); }); -art.font('Ghost Wire BBS', 'Doom', function(logo) { - art.font('No place like home', 'rusted', function(subtext) { +art.font('Ghost Wire BBS', 'Doom', (logo) => { + art.font('No place like home', 'rusted', (subtext) => { art.table({ verticalBar : ' ', horizontalBar : ' ', @@ -37,7 +37,7 @@ art.font('Ghost Wire BBS', 'Doom', function(logo) { {name: 'operator', value: 'vince.vega'}, {name: 'dial-in', value: '(917)555-4202'}, ] - }).lines(2, function(table: any) { + }).lines(2, (table: any) => { art.image({ filepath : '~/Images/starburst_red.jpg', alphabet : 'ultra-wide' @@ -53,7 +53,7 @@ art.font('Ghost Wire BBS', 'Doom', function(logo) { x: -1, y: -1, style: 'green', - }, function(_final: any) { + }, (_final: any) => { }); }); }); @@ -63,7 +63,7 @@ art.image({ width : 40, filepath : '/Images/initech.png', alphabet : 'wide' -}).font('INITECH', 'Doom', 'cyan', function(_ascii) { +}).font('INITECH', 'Doom', 'cyan', (_ascii) => { }); art.table({ @@ -76,7 +76,7 @@ art.table({ verticalBar : ' ', horizontalBar : ' ', intersection : ' ' -}).lines(2, function(table: any) { +}).lines(2, (table: any) => { art.strings([ 'ANDRE', 'the', @@ -84,8 +84,8 @@ art.table({ 'POSSE', '7\'4"', '520 LB' - ], 'rusted', function(andre: any, the: any, giant: any, posse: any, height: any, weight: any) { - art.strings([ 'has', 'a'], 'twopoint', function(has: any, a: any) { + ], 'rusted', (andre: any, the: any, giant: any, posse: any, height: any, weight: any) => { + art.strings([ 'has', 'a'], 'twopoint', (has: any, a: any) => { art.image({ filepath : '/Images/andre_has_a_posse.jpeg', alphabet : 'ultra-wide' @@ -122,7 +122,7 @@ art.table({ x: 6, y: -6, style: 'bright_black', transparent: true - }, function(_final: any) { + }, (_final: any) => { }); }); }); @@ -134,17 +134,17 @@ const image = new art.Image({ filepath: '~/Images/metropolis.jpg', alphabet: 'variant4' }); -image.write(function(_err: any, _rendered: string) { +image.write((_err: any, _rendered: string) => { }); -art.font('Prompt', 'Basic', 'red').font('v1', 'Doom', 'magenta', function(_rendered) { +art.font('Prompt', 'Basic', 'red').font('v1', 'Doom', 'magenta', (_rendered) => { }); art.image({ width : 40, filepath : '/Images/initech.png', alphabet : 'wide' -}).font('INITECH', 'Doom', 'cyan', function(_ascii) { +}).font('INITECH', 'Doom', 'cyan', (_ascii) => { }); art.style('my text', 'red+underline'); @@ -167,7 +167,7 @@ art.table({ style : 'white' } ] -}, function(_rendered) { +}, (_rendered) => { // use rendered text }); @@ -188,6 +188,6 @@ art.table({ horizontal: '━', }, borderColor : 'bright_white', -}, function(_rendered) { +}, (_rendered) => { // use rendered text }); diff --git a/types/ascii-art/tslint.json b/types/ascii-art/tslint.json index e67cf4277a..f93cf8562a 100644 --- a/types/ascii-art/tslint.json +++ b/types/ascii-art/tslint.json @@ -1,6 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules":{ - "only-arrow-functions": false - } + "extends": "dtslint/dt.json" }