mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Add typings for color support
This commit is contained in:
committed by
Dmitry Guketlev
parent
48cb1f507e
commit
b65f9a5bfe
@@ -0,0 +1,48 @@
|
||||
import * as colorSupport from 'color-support';
|
||||
|
||||
(() => {
|
||||
const result = colorSupport();
|
||||
if (!result) {
|
||||
console.log('color is not supported');
|
||||
} else if (result.has16m) {
|
||||
console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m');
|
||||
} else if (result.has256) {
|
||||
console.log('\x1b[38;5;119m256 colors\x1b[0m');
|
||||
} else if (result.hasBasic) {
|
||||
console.log('\x1b[31mbasic colors\x1b[0m');
|
||||
} else {
|
||||
console.log('Level: ', result.level);
|
||||
console.log('this is impossible, but colors are not supported');
|
||||
}
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const result = colorSupport({
|
||||
alwaysReturn: false,
|
||||
env: process.env,
|
||||
ignoreCI: true,
|
||||
ignoreDumb: true,
|
||||
ignoreTTY: true,
|
||||
level: 2,
|
||||
stream: process.stdout,
|
||||
term: process.env.TERM,
|
||||
}, {
|
||||
has16m: false,
|
||||
has256: false,
|
||||
hasBasic: false,
|
||||
level: 0,
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
console.log('color is not supported');
|
||||
} else if (result.has16m) {
|
||||
console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m');
|
||||
} else if (result.has256) {
|
||||
console.log('\x1b[38;5;119m256 colors\x1b[0m');
|
||||
} else if (result.hasBasic) {
|
||||
console.log('\x1b[31mbasic colors\x1b[0m');
|
||||
} else {
|
||||
console.log('Level: ', result.level);
|
||||
console.log('this is impossible, but colors are not supported');
|
||||
}
|
||||
})();
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// Type definitions for color-support 1.1
|
||||
// Project: https://github.com/isaacs/color-support#readme
|
||||
// Definitions by: Guketlev Dmitry <https://github.com/Yavanosta>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
type ColorSupportLevel = 0 | 1 | 2 | 3;
|
||||
|
||||
interface ColorSupportOptions {
|
||||
alwaysReturn?: boolean;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
ignoreCI?: boolean;
|
||||
ignoreDumb?: boolean;
|
||||
ignoreTTY?: boolean;
|
||||
level?: ColorSupportLevel;
|
||||
stream?: NodeJS.WriteStream;
|
||||
term?: string;
|
||||
}
|
||||
|
||||
interface ColorSupportResult {
|
||||
level: ColorSupportLevel;
|
||||
hasBasic: boolean;
|
||||
has256: boolean;
|
||||
has16m: boolean;
|
||||
}
|
||||
|
||||
type ColorSupport = (options?: ColorSupportOptions,
|
||||
obj?: ColorSupportResult) => false | ColorSupportResult;
|
||||
|
||||
declare var colorSupport: ColorSupport;
|
||||
|
||||
export = colorSupport;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"color-support-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user