From 9571d1595aaaa8ed82280ba702122e2774bc1e9c Mon Sep 17 00:00:00 2001 From: Steffen Waldmann Date: Wed, 2 Oct 2024 14:59:07 +0200 Subject: [PATCH] Add types for `cds.utils.colors` (#263) --- CHANGELOG.md | 3 +- apis/utils.d.ts | 53 +++++++++++++++++++++++ test/typescript/apis/project/cds-utils.ts | 12 +++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d99bdfb5..feb8a61f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Added - `cds.app` typed as express.js application - `cds.cli` CLI arguments -- `cds.requires` types for MTX services. +- `cds.requires` types for MTX services +- `cds.utils.colors` types ### Changed - Most `cds.requires` entries are now optionals. diff --git a/apis/utils.d.ts b/apis/utils.d.ts index 468fd6b4..f38ff7aa 100644 --- a/apis/utils.d.ts +++ b/apis/utils.d.ts @@ -87,4 +87,57 @@ declare const utils: { * @see https://cap.cloud.sap/docs/node.js/cds-utils#async-rm-path */ rm: (...path: string[]) => Promise>, + + /** + * @since 8.3.0 + * @see https://cap.cloud.sap/docs/node.js/cds-utils#colors + */ + colors: { + enabled: boolean, + RESET: '\x1b[0m', + BOLD: '\x1b[1m' | '', + BRIGHT: '\x1b[1m' | '', + DIMMED: '\x1b[2m' | '', + ITALIC: '\x1b[3m' | '', + UNDER: '\x1b[4m' | '', + BLINK: '\x1b[5m' | '', + FLASH: '\x1b[6m' | '', + INVERT: '\x1b[7m' | '', + BLACK: '\x1b[30m' | '', + RED: '\x1b[31m' | '', + GREEN: '\x1b[32m' | '', + YELLOW: '\x1b[33m' | '', + BLUE: '\x1b[34m' | '', + PINK: '\x1b[35m' | '', + CYAN: '\x1b[36m' | '', + LIGHT_GRAY: '\x1b[37m' | '', + DEFAULT: '\x1b[39m' | '', + GRAY: '\x1b[90m' | '', + LIGHT_RED: '\x1b[91m' | '', + LIGHT_GREEN: '\x1b[92m' | '', + LIGHT_YELLOW: '\x1b[93m' | '', + LIGHT_BLUE: '\x1b[94m' | '', + LIGHT_PINK: '\x1b[95m' | '', + LIGHT_CYAN: '\x1b[96m' | '', + WHITE: '\x1b[97m' | '', + bg: { + BLACK: '\x1b[40m' | '', + RED: '\x1b[41m' | '', + GREEN: '\x1b[42m' | '', + YELLOW: '\x1b[43m' | '', + BLUE: '\x1b[44m' | '', + PINK: '\x1b[45m' | '', + CYAN: '\x1b[46m' | '', + WHITE: '\x1b[47m' | '', + DEFAULT: '\x1b[49m' | '', + LIGHT_GRAY: '\x1b[100m' | '', + LIGHT_RED: '\x1b[101m' | '', + LIGHT_GREEN: '\x1b[102m' | '', + LIGHT_YELLOW: '\x1b[103m' | '', + LIGHT_BLUE: '\x1b[104m' | '', + LIGHT_PINK: '\x1b[105m' | '', + LIGHT_CYAN: '\x1b[106m' | '', + LIGHT_WHITE: '\x1b[107m' | '', + }, + }, } diff --git a/test/typescript/apis/project/cds-utils.ts b/test/typescript/apis/project/cds-utils.ts index 63fd9f80..6d94f967 100644 --- a/test/typescript/apis/project/cds-utils.ts +++ b/test/typescript/apis/project/cds-utils.ts @@ -36,3 +36,15 @@ await rimraf('dist/db/data') const { rm } = cds.utils await rm('dist','db','data') await rm('dist/db/data') + +const { colors } = cds.utils +const { + enabled, + RESET, BOLD, BRIGHT, DIMMED, ITALIC, UNDER, BLINK, FLASH, INVERT, + BLACK, RED, GREEN, YELLOW, BLUE, PINK, CYAN, LIGHT_GRAY, DEFAULT, GRAY, LIGHT_RED, LIGHT_GREEN, LIGHT_YELLOW, LIGHT_BLUE, LIGHT_PINK, LIGHT_CYAN, WHITE, + bg +} = colors +enabled; +RESET; BOLD; BRIGHT; DIMMED; ITALIC; UNDER; BLINK; FLASH; INVERT; +BLACK; RED; GREEN; YELLOW; BLUE; PINK; CYAN; LIGHT_GRAY; DEFAULT; GRAY; LIGHT_RED; LIGHT_GREEN; LIGHT_YELLOW; LIGHT_BLUE; LIGHT_PINK; LIGHT_CYAN; WHITE; +bg.BLACK; bg.RED; bg.GREEN; bg.YELLOW; bg.BLUE; bg.PINK; bg.CYAN; bg.WHITE; bg.DEFAULT; bg.LIGHT_GRAY; bg.LIGHT_RED; bg.LIGHT_GREEN; bg.LIGHT_YELLOW; bg.LIGHT_BLUE; bg.LIGHT_PINK; bg.LIGHT_CYAN; bg.LIGHT_WHITE