From 55cfed47405746ac0f3bb2cad603c3d5302e3f71 Mon Sep 17 00:00:00 2001 From: chloe caruso Date: Sun, 1 Jun 2025 17:18:16 -0700 Subject: [PATCH] fix ansi writing on windows 7 --- README.md | 4 +- bun.lock | 37 ------------- package-lock.json | 132 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +- src/console.ts | 2 +- src/error.ts | 2 +- src/internal.ts | 9 ++-- 7 files changed, 144 insertions(+), 47 deletions(-) delete mode 100644 bun.lock create mode 100644 package-lock.json diff --git a/README.md b/README.md index 8ef469e..a9335e5 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/bun.lock b/bun.lock deleted file mode 100644 index 7a8f617..0000000 --- a/bun.lock +++ /dev/null @@ -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=="], - } -} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..5270c0a --- /dev/null +++ b/package-lock.json @@ -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" + } + } +} diff --git a/package.json b/package.json index dd96433..b183fb2 100644 --- a/package.json +++ b/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/src/console.ts b/src/console.ts index a94bc96..83c55e6 100644 --- a/src/console.ts +++ b/src/console.ts @@ -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'; diff --git a/src/error.ts b/src/error.ts index 340e034..ef1d629 100644 --- a/src/error.ts +++ b/src/error.ts @@ -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) { diff --git a/src/internal.ts b/src/internal.ts index 3bb59b2..c080cef 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -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); -} \ No newline at end of file +}