fix ansi writing on windows 7

This commit is contained in:
chloe caruso 2025-06-01 17:18:16 -07:00
parent 968f4ab467
commit 55cfed4740
7 changed files with 144 additions and 47 deletions

View file

@ -8,9 +8,9 @@ Examples are available in the `examples` directory.
## Install
The package is distributed as TypeScript source code through this Git
repository. You can install it with a JavaScript package manager such as `bun`.
repository. You can install it with a JavaScript package manager such as `npm`.
Most package managers should pin the latest commit.
```
bun add git+https://git.paperclover.net/clo/console.git
npm add git+https://git.paperclover.net/clo/console.git
```

View file

@ -1,37 +0,0 @@
{
"lockfileVersion": 1,
"workspaces": {
"": {
"name": "@paperclover/console",
"dependencies": {
"ansi-escapes": "^7.0.0",
"chalk": "^5.4.1",
"strip-ansi": "^7.1.0",
},
"devDependencies": {
"@types/bun": "1.2.5",
},
},
},
"packages": {
"@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="],
"@types/node": ["@types/node@22.13.10", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw=="],
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
"ansi-escapes": ["ansi-escapes@7.0.0", "", { "dependencies": { "environment": "^1.0.0" } }, "sha512-GdYO7a61mR0fOlAsvC9/rIHf7L96sBc6dEWzeOu+KAea5bZyQRPIpojrVoI4AXGJS/ycu/fBTdLrUkA4ODrvjw=="],
"ansi-regex": ["ansi-regex@6.1.0", "", {}, "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA=="],
"bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="],
"chalk": ["chalk@5.4.1", "", {}, "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w=="],
"environment": ["environment@1.1.0", "", {}, "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q=="],
"strip-ansi": ["strip-ansi@7.1.0", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ=="],
"undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
}
}

132
package-lock.json generated Normal file
View file

@ -0,0 +1,132 @@
{
"name": "@paperclover/console",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@paperclover/console",
"dependencies": {
"ansi-escapes": "^7.0.0",
"chalk": "^5.4.1",
"strip-ansi": "^7.1.0"
},
"devDependencies": {
"@types/bun": "1.2.5"
}
},
"node_modules/@types/bun": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.2.5.tgz",
"integrity": "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg==",
"dev": true,
"license": "MIT",
"dependencies": {
"bun-types": "1.2.5"
}
},
"node_modules/@types/node": {
"version": "22.15.29",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.29.tgz",
"integrity": "sha512-LNdjOkUDlU1RZb8e1kOIUpN1qQUlzGkEtbVNo53vbrwDg5om6oduhm4SiUaPW5ASTXhAiP0jInWG8Qx9fVlOeQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.21.0"
}
},
"node_modules/@types/ws": {
"version": "8.5.14",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.14.tgz",
"integrity": "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/ansi-escapes": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.0.0.tgz",
"integrity": "sha512-GdYO7a61mR0fOlAsvC9/rIHf7L96sBc6dEWzeOu+KAea5bZyQRPIpojrVoI4AXGJS/ycu/fBTdLrUkA4ODrvjw==",
"license": "MIT",
"dependencies": {
"environment": "^1.0.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/ansi-regex": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz",
"integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
}
},
"node_modules/bun-types": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.2.5.tgz",
"integrity": "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*",
"@types/ws": "~8.5.10"
}
},
"node_modules/chalk": {
"version": "5.4.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.4.1.tgz",
"integrity": "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==",
"license": "MIT",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/environment": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/environment/-/environment-1.1.0.tgz",
"integrity": "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/strip-ansi": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz",
"integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^6.0.1"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
}
},
"node_modules/undici-types": {
"version": "6.21.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
"dev": true,
"license": "MIT"
}
}
}

View file

@ -7,7 +7,8 @@
"./Spinner": "./src/Spinner.ts",
"./Progress": "./src/Progress.ts",
"./Widget": "./src/Widget.ts",
"./inject": "./src/inject.ts"
"./inject": "./src/inject.ts",
"./error": "./src/error.ts"
},
"devDependencies": {
"@types/bun": "1.2.5"
@ -17,4 +18,4 @@
"chalk": "^5.4.1",
"strip-ansi": "^7.1.0"
}
}
}

View file

@ -236,7 +236,7 @@ export const success = /* @__PURE__ */ scoped(successSymbol, {
});
import chalk, { type ChalkInstance } from 'chalk';
import { inspect } from 'util';
import { inspect } from 'node:util';
import { type LogFunction, type CustomLoggerColor, type CustomLoggerOptions, type StringLike, getColor } from './internal.ts';
import { formatErrorObj, formatStackTrace } from './error.ts';
import stripAnsi from 'strip-ansi';

View file

@ -1,5 +1,5 @@
import chalk from 'chalk';
import path from 'path';
import path from 'node:path';
import { isBuiltin } from 'node:module';
export function platformSimplifyErrorPath(filepath: string) {

View file

@ -1,6 +1,5 @@
import chalk, { type ChalkInstance } from 'chalk';
import { writeSync } from 'fs';
import { inspect } from 'util';
import { inspect } from 'node:util';
export function convertHSVtoRGB(h: number, s: number, v: number): [number, number, number] {
let r, g, b;
@ -49,19 +48,21 @@ export function writeToStderr(data: string, needsUnfreeze = false) {
if (needsUnfreeze) bufferNeedsUnfreeze = true;
}
const stderr = process.stderr;
export function flushStderr() {
if (buffer) {
if (bufferNeedsUnfreeze) {
buffer += '\u001B[?2026l';
bufferNeedsUnfreeze = false;
}
writeSync(2, buffer);
stderr.write(buffer);
buffer = '';
}
}
process.on('exit', () => {
exiting = true;
buffer += '\x1b[0;39;49m';
flushStderr();
});
@ -160,4 +161,4 @@ export function getColor(color: CustomLoggerColor): ChalkInstance {
return chalk.rgb(color[0], color[1], color[2]);
}
return chalk.ansi256(color);
}
}