@mks2508/better-logger 5.0.1 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Logger.d.ts +976 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/ScopedLogger.d.ts +74 -0
- package/dist/ScopedLogger.d.ts.map +1 -0
- package/dist/chunks/Logger-CKqzXDh3.js +2 -0
- package/dist/chunks/Logger-CKqzXDh3.js.map +1 -0
- package/dist/chunks/Logger-D_vuKP4l.js +4511 -0
- package/dist/chunks/Logger-D_vuKP4l.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
- package/dist/chunks/cli-module-B-njrTWb.js +2 -0
- package/dist/chunks/cli-module-B-njrTWb.js.map +1 -0
- package/dist/chunks/cli-module-Cx7qotPY.js +390 -0
- package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
- package/dist/chunks/color-converter-CCSQRztd.js +2 -0
- package/dist/chunks/color-converter-CCSQRztd.js.map +1 -0
- package/dist/chunks/color-converter-_Xdmsy7E.js +462 -0
- package/dist/chunks/color-converter-_Xdmsy7E.js.map +1 -0
- package/dist/chunks/environment-C1xxvc8l.js +1127 -0
- package/dist/chunks/environment-C1xxvc8l.js.map +1 -0
- package/dist/chunks/environment-Cprkw3g9.js +4 -0
- package/dist/chunks/environment-Cprkw3g9.js.map +1 -0
- package/dist/chunks/formatting-DMJxYq9o.js +380 -0
- package/dist/chunks/formatting-DMJxYq9o.js.map +1 -0
- package/dist/chunks/formatting-DpKxCsXq.js +2 -0
- package/dist/chunks/formatting-DpKxCsXq.js.map +1 -0
- package/dist/cli/CommandProcessor.d.ts +100 -0
- package/dist/cli/CommandProcessor.d.ts.map +1 -0
- package/dist/cli/commands/ConfigCommand.d.ts +14 -0
- package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/dist/cli/commands/ExportCommand.d.ts +48 -0
- package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
- package/dist/cli/commands/HistoryCommand.d.ts +47 -0
- package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
- package/dist/cli/commands/StatusCommand.d.ts +30 -0
- package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
- package/dist/cli/commands/ThemeCommand.d.ts +30 -0
- package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
- package/dist/cli/help.d.ts +12 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/{src/cli-module.ts → dist/cli-module.d.ts} +2 -8
- package/dist/cli-module.d.ts.map +1 -0
- package/dist/cli-primitives/box.d.ts +11 -0
- package/dist/cli-primitives/box.d.ts.map +1 -0
- package/dist/cli-primitives/cli-table.d.ts +11 -0
- package/dist/cli-primitives/cli-table.d.ts.map +1 -0
- package/dist/cli-primitives/divider.d.ts +11 -0
- package/dist/cli-primitives/divider.d.ts.map +1 -0
- package/dist/cli-primitives/header.d.ts +12 -0
- package/dist/cli-primitives/header.d.ts.map +1 -0
- package/{src/cli-primitives/index.ts → dist/cli-primitives/index.d.ts} +1 -1
- package/dist/cli-primitives/index.d.ts.map +1 -0
- package/dist/cli-primitives/server-fallback.d.ts +25 -0
- package/dist/cli-primitives/server-fallback.d.ts.map +1 -0
- package/dist/cli-primitives/spinner.d.ts +47 -0
- package/dist/cli-primitives/spinner.d.ts.map +1 -0
- package/dist/cli-primitives/step.d.ts +11 -0
- package/dist/cli-primitives/step.d.ts.map +1 -0
- package/dist/cli.cjs +2 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +12 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +235 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +127 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +291 -0
- package/dist/core.js.map +1 -0
- package/dist/example.d.ts +18 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/exports-module.d.ts +196 -0
- package/dist/exports-module.d.ts.map +1 -0
- package/dist/exports.cjs +2 -0
- package/dist/exports.cjs.map +1 -0
- package/dist/exports.js +238 -0
- package/dist/exports.js.map +1 -0
- package/dist/handlers/AnalyticsLogHandler.d.ts +8 -0
- package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
- package/dist/handlers/ExportLogHandler.d.ts +100 -0
- package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
- package/dist/handlers/FileLogHandler.d.ts +33 -0
- package/dist/handlers/FileLogHandler.d.ts.map +1 -0
- package/dist/handlers/RemoteLogHandler.d.ts +11 -0
- package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
- package/{src/handlers/index.ts → dist/handlers/index.d.ts} +2 -2
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/hooks/HookManager.d.ts +21 -0
- package/dist/hooks/HookManager.d.ts.map +1 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +627 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/serializers/SerializerRegistry.d.ts +16 -0
- package/dist/serializers/SerializerRegistry.d.ts.map +1 -0
- package/{src/serializers/index.ts → dist/serializers/index.d.ts} +1 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/styling/LogStyleBuilder.d.ts +146 -0
- package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
- package/dist/styling/SemanticStyles.d.ts +178 -0
- package/dist/styling/SemanticStyles.d.ts.map +1 -0
- package/dist/styling/SmartPresets.d.ts +22 -0
- package/dist/styling/SmartPresets.d.ts.map +1 -0
- package/dist/styling/StyleBuilder.d.ts +140 -0
- package/dist/styling/StyleBuilder.d.ts.map +1 -0
- package/dist/styling/StyleCache.d.ts +42 -0
- package/dist/styling/StyleCache.d.ts.map +1 -0
- package/dist/styling/banners.d.ts +42 -0
- package/dist/styling/banners.d.ts.map +1 -0
- package/dist/styling/index.d.ts +10 -0
- package/dist/styling/index.d.ts.map +1 -0
- package/dist/styling/themes.d.ts +7 -0
- package/dist/styling/themes.d.ts.map +1 -0
- package/dist/styling-module.d.ts +178 -0
- package/dist/styling-module.d.ts.map +1 -0
- package/dist/styling.cjs +2 -0
- package/dist/styling.cjs.map +1 -0
- package/dist/styling.js +146 -0
- package/dist/styling.js.map +1 -0
- package/dist/terminal/color-converter.d.ts +73 -0
- package/dist/terminal/color-converter.d.ts.map +1 -0
- package/dist/terminal/formatter.d.ts +20 -0
- package/dist/terminal/formatter.d.ts.map +1 -0
- package/dist/terminal/terminal-renderer.d.ts +77 -0
- package/dist/terminal/terminal-renderer.d.ts.map +1 -0
- package/dist/transports/ConsoleTransport.d.ts +9 -0
- package/dist/transports/ConsoleTransport.d.ts.map +1 -0
- package/dist/transports/FileTransport.d.ts +15 -0
- package/dist/transports/FileTransport.d.ts.map +1 -0
- package/dist/transports/HttpTransport.d.ts +16 -0
- package/dist/transports/HttpTransport.d.ts.map +1 -0
- package/dist/transports/TransportManager.d.ts +14 -0
- package/dist/transports/TransportManager.d.ts.map +1 -0
- package/{src/transports/index.ts → dist/transports/index.d.ts} +1 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/{src/types/core.ts → dist/types/core.d.ts} +25 -62
- package/dist/types/core.d.ts.map +1 -0
- package/{src/types/handlers.ts → dist/types/handlers.d.ts} +5 -15
- package/dist/types/handlers.d.ts.map +1 -0
- package/{src/types/hooks.ts → dist/types/hooks.d.ts} +3 -12
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/{src/types/serializers.ts → dist/types/serializers.d.ts} +1 -6
- package/dist/types/serializers.d.ts.map +1 -0
- package/{src/types/transports.ts → dist/types/transports.d.ts} +2 -7
- package/dist/types/transports.d.ts.map +1 -0
- package/dist/utils/adapter.d.ts +48 -0
- package/dist/utils/adapter.d.ts.map +1 -0
- package/dist/utils/ansi-colors.d.ts +156 -0
- package/dist/utils/ansi-colors.d.ts.map +1 -0
- package/dist/utils/environment-detector.d.ts +45 -0
- package/dist/utils/environment-detector.d.ts.map +1 -0
- package/dist/utils/environment.d.ts +47 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/formatting.d.ts +58 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/opentui-detection.d.ts +34 -0
- package/dist/utils/opentui-detection.d.ts.map +1 -0
- package/dist/utils/output.d.ts +46 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/stackTrace.d.ts +6 -0
- package/dist/utils/stackTrace.d.ts.map +1 -0
- package/dist/utils/timestamps.d.ts +20 -0
- package/dist/utils/timestamps.d.ts.map +1 -0
- package/{src/writers/BufferWriter.ts → dist/writers/BufferWriter.d.ts} +16 -77
- package/dist/writers/BufferWriter.d.ts.map +1 -0
- package/{src/writers/index.ts → dist/writers/index.d.ts} +1 -1
- package/dist/writers/index.d.ts.map +1 -0
- package/package.json +5 -1
- package/.claude/settings.local.json +0 -48
- package/.github/workflows/ci-quality.yml +0 -357
- package/.github/workflows/docs-demo.yml +0 -119
- package/.github/workflows/releases-core.yml +0 -512
- package/.github/workflows/releases-full.yml +0 -582
- package/.github/workflows-backup/ci.yml +0 -221
- package/.github/workflows-backup/nightly.yml +0 -196
- package/.github/workflows-backup/release-optimized.yml +0 -373
- package/.github/workflows-backup/release.yml +0 -269
- package/.release-notes-0.2.0.md +0 -129
- package/.yamllint +0 -28
- package/CHANGELOG.json +0 -1120
- package/CHANGELOG.md +0 -209
- package/CLAUDE.md +0 -217
- package/demo.html +0 -847
- package/docs/API.md +0 -918
- package/docs/CORE.md +0 -264
- package/docs/DEVELOPMENT.md +0 -731
- package/docs/EXPORTS.md +0 -467
- package/docs/PACKAGES.md +0 -244
- package/docs/STYLING.md +0 -405
- package/docs/_config.yml +0 -36
- package/docs/index.md +0 -179
- package/examples/README.md +0 -208
- package/examples/basic-logging.js +0 -75
- package/examples/data-export.js +0 -234
- package/examples/package.json +0 -16
- package/examples/performance-timing.js +0 -170
- package/examples/simplified-api.js +0 -124
- package/examples/styling-themes.js +0 -207
- package/index.html +0 -358
- package/packages/core/package.json +0 -57
- package/packages/exports/package.json +0 -41
- package/packages/nodejs-opentui/README.md +0 -232
- package/packages/nodejs-opentui/package.json +0 -72
- package/packages/nodejs-opentui/src/LogRenderer.ts +0 -171
- package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +0 -178
- package/packages/nodejs-opentui/src/components/LogBadge.tsx +0 -131
- package/packages/nodejs-opentui/src/index.ts +0 -133
- package/packages/nodejs-opentui/src/types.ts +0 -158
- package/packages/nodejs-opentui/tsconfig.json +0 -20
- package/packages/styling/package.json +0 -41
- package/playground/demo-all.ts +0 -95
- package/playground/demo-box.ts +0 -85
- package/playground/demo-levels.ts +0 -56
- package/playground/demo-real-world.ts +0 -98
- package/playground/demo-spinner.ts +0 -77
- package/playground/demo-steps.ts +0 -72
- package/playground/demo-table.ts +0 -83
- package/project-utils/README.md +0 -172
- package/project-utils/auto-release-gemini.ts +0 -1193
- package/project-utils/auto-release-ui.ts +0 -1329
- package/project-utils/commit-generator.ts +0 -1385
- package/project-utils/commit-ui.ts +0 -264
- package/project-utils/git-utils.ts +0 -199
- package/project-utils/github-release-manager.ts +0 -466
- package/project-utils/project-config.ts +0 -260
- package/project-utils/prompt-templates.js +0 -345
- package/project-utils/prompt-templates.ts +0 -422
- package/project-utils/version-manager.ts +0 -1078
- package/src/Logger.ts +0 -1858
- package/src/ScopedLogger.ts +0 -256
- package/src/cli/CommandProcessor.ts +0 -248
- package/src/cli/commands/ConfigCommand.ts +0 -93
- package/src/cli/commands/ExportCommand.ts +0 -276
- package/src/cli/commands/HistoryCommand.ts +0 -117
- package/src/cli/commands/StatusCommand.ts +0 -112
- package/src/cli/commands/ThemeCommand.ts +0 -88
- package/src/cli/help.ts +0 -127
- package/src/cli/index.ts +0 -71
- package/src/cli-primitives/box.ts +0 -86
- package/src/cli-primitives/cli-table.ts +0 -62
- package/src/cli-primitives/divider.ts +0 -17
- package/src/cli-primitives/header.ts +0 -18
- package/src/cli-primitives/server-fallback.ts +0 -54
- package/src/cli-primitives/spinner.ts +0 -133
- package/src/cli-primitives/step.ts +0 -22
- package/src/constants.ts +0 -313
- package/src/core.ts +0 -397
- package/src/example.ts +0 -210
- package/src/exports-module.ts +0 -311
- package/src/handlers/AnalyticsLogHandler.ts +0 -22
- package/src/handlers/ExportLogHandler.ts +0 -610
- package/src/handlers/FileLogHandler.ts +0 -169
- package/src/handlers/RemoteLogHandler.ts +0 -42
- package/src/hooks/HookManager.ts +0 -177
- package/src/index.ts +0 -395
- package/src/main.ts +0 -196
- package/src/serializers/SerializerRegistry.ts +0 -173
- package/src/style.css +0 -96
- package/src/styling/LogStyleBuilder.ts +0 -355
- package/src/styling/SemanticStyles.ts +0 -380
- package/src/styling/SmartPresets.ts +0 -288
- package/src/styling/StyleBuilder.ts +0 -319
- package/src/styling/StyleCache.ts +0 -131
- package/src/styling/banners.ts +0 -168
- package/src/styling/index.ts +0 -27
- package/src/styling/themes.ts +0 -235
- package/src/styling-module.ts +0 -244
- package/src/terminal/color-converter.ts +0 -315
- package/src/terminal/formatter.ts +0 -242
- package/src/terminal/terminal-renderer.ts +0 -342
- package/src/transports/ConsoleTransport.ts +0 -28
- package/src/transports/FileTransport.ts +0 -53
- package/src/transports/HttpTransport.ts +0 -56
- package/src/transports/TransportManager.ts +0 -130
- package/src/types/index.ts +0 -83
- package/src/typescript.svg +0 -1
- package/src/utils/adapter.ts +0 -291
- package/src/utils/ansi-colors.ts +0 -333
- package/src/utils/environment-detector.ts +0 -170
- package/src/utils/environment.ts +0 -94
- package/src/utils/formatting.ts +0 -332
- package/src/utils/index.ts +0 -33
- package/src/utils/opentui-detection.ts +0 -138
- package/src/utils/output.ts +0 -227
- package/src/utils/stackTrace.ts +0 -144
- package/src/utils/timestamps.ts +0 -80
- package/src/vite-env.d.ts +0 -1
- package/test-core-browser.html +0 -237
- package/test-core-node.js +0 -63
- package/tests/test-conflict-resolution.ts +0 -391
- package/tests/validate-workflows.sh +0 -131
- package/tests/yaml-autofix.sh +0 -146
- package/tsconfig.json +0 -50
- package/vite.config.ts +0 -256
- /package/{public → dist}/vite.svg +0 -0
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Color Converter - CSS colors to ANSI extended color codes
|
|
3
|
-
* Supports 256-color and truecolor (24-bit) terminals
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type ColorCapability = 'full' | 'basic' | 'none';
|
|
7
|
-
|
|
8
|
-
export interface RGB {
|
|
9
|
-
r: number;
|
|
10
|
-
g: number;
|
|
11
|
-
b: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const ANSI_16_COLORS: Record<string, { fg: string; bg: string; bright: { fg: string; bg: string } }> = {
|
|
15
|
-
black: { fg: '30', bg: '40', bright: { fg: '90', bg: '100' } },
|
|
16
|
-
red: { fg: '31', bg: '41', bright: { fg: '91', bg: '101' } },
|
|
17
|
-
green: { fg: '32', bg: '42', bright: { fg: '92', bg: '102' } },
|
|
18
|
-
yellow: { fg: '33', bg: '43', bright: { fg: '93', bg: '103' } },
|
|
19
|
-
blue: { fg: '34', bg: '44', bright: { fg: '94', bg: '104' } },
|
|
20
|
-
magenta: { fg: '35', bg: '45', bright: { fg: '95', bg: '105' } },
|
|
21
|
-
cyan: { fg: '36', bg: '46', bright: { fg: '96', bg: '106' } },
|
|
22
|
-
white: { fg: '37', bg: '47', bright: { fg: '97', bg: '107' } },
|
|
23
|
-
gray: { fg: '90', bg: '100', bright: { fg: '37', bg: '47' } },
|
|
24
|
-
grey: { fg: '90', bg: '100', bright: { fg: '37', bg: '47' } },
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const CSS_NAMED_COLORS: Record<string, string> = {
|
|
28
|
-
aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff',
|
|
29
|
-
aquamarine: '#7fffd4', azure: '#f0ffff', beige: '#f5f5dc',
|
|
30
|
-
bisque: '#ffe4c4', black: '#000000', blanchedalmond: '#ffebcd',
|
|
31
|
-
blue: '#0000ff', blueviolet: '#8a2be2', brown: '#a52a2a',
|
|
32
|
-
burlywood: '#deb887', cadetblue: '#5f9ea0', chartreuse: '#7fff00',
|
|
33
|
-
chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed',
|
|
34
|
-
cornsilk: '#fff8dc', crimson: '#dc143c', cyan: '#00ffff',
|
|
35
|
-
darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b',
|
|
36
|
-
darkgray: '#a9a9a9', darkgreen: '#006400', darkkhaki: '#bdb76b',
|
|
37
|
-
darkmagenta: '#8b008b', darkolivegreen: '#556b2f', darkorange: '#ff8c00',
|
|
38
|
-
darkorchid: '#9932cc', darkred: '#8b0000', darksalmon: '#e9967a',
|
|
39
|
-
darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f',
|
|
40
|
-
darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493',
|
|
41
|
-
deepskyblue: '#00bfff', dimgray: '#696969', dodgerblue: '#1e90ff',
|
|
42
|
-
firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22',
|
|
43
|
-
fuchsia: '#ff00ff', gainsboro: '#dcdcdc', ghostwhite: '#f8f8ff',
|
|
44
|
-
gold: '#ffd700', goldenrod: '#daa520', gray: '#808080',
|
|
45
|
-
green: '#008000', greenyellow: '#adff2f', honeydew: '#f0fff0',
|
|
46
|
-
hotpink: '#ff69b4', indianred: '#cd5c5c', indigo: '#4b0082',
|
|
47
|
-
ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa',
|
|
48
|
-
lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd',
|
|
49
|
-
lightblue: '#add8e6', lightcoral: '#f08080', lightcyan: '#e0ffff',
|
|
50
|
-
lightgoldenrodyellow: '#fafad2', lightgray: '#d3d3d3', lightgreen: '#90ee90',
|
|
51
|
-
lightpink: '#ffb6c1', lightsalmon: '#ffa07a', lightseagreen: '#20b2aa',
|
|
52
|
-
lightskyblue: '#87cefa', lightslategray: '#778899', lightsteelblue: '#b0c4de',
|
|
53
|
-
lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32',
|
|
54
|
-
linen: '#faf0e6', magenta: '#ff00ff', maroon: '#800000',
|
|
55
|
-
mediumaquamarine: '#66cdaa', mediumblue: '#0000cd', mediumorchid: '#ba55d3',
|
|
56
|
-
mediumpurple: '#9370db', mediumseagreen: '#3cb371', mediumslateblue: '#7b68ee',
|
|
57
|
-
mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585',
|
|
58
|
-
midnightblue: '#191970', mintcream: '#f5fffa', mistyrose: '#ffe4e1',
|
|
59
|
-
moccasin: '#ffe4b5', navajowhite: '#ffdead', navy: '#000080',
|
|
60
|
-
oldlace: '#fdf5e6', olive: '#808000', olivedrab: '#6b8e23',
|
|
61
|
-
orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6',
|
|
62
|
-
palegoldenrod: '#eee8aa', palegreen: '#98fb98', paleturquoise: '#afeeee',
|
|
63
|
-
palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9',
|
|
64
|
-
peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd',
|
|
65
|
-
powderblue: '#b0e0e6', purple: '#800080', rebeccapurple: '#663399',
|
|
66
|
-
red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1',
|
|
67
|
-
saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460',
|
|
68
|
-
seagreen: '#2e8b57', seashell: '#fff5ee', sienna: '#a0522d',
|
|
69
|
-
silver: '#c0c0c0', skyblue: '#87ceeb', slateblue: '#6a5acd',
|
|
70
|
-
slategray: '#708090', snow: '#fffafa', springgreen: '#00ff7f',
|
|
71
|
-
steelblue: '#4682b4', tan: '#d2b48c', teal: '#008080',
|
|
72
|
-
thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0',
|
|
73
|
-
violet: '#ee82ee', wheat: '#f5deb3', white: '#ffffff',
|
|
74
|
-
whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32',
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export function hexToRgb(hex: string): RGB {
|
|
78
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
79
|
-
if (!result || !result[1] || !result[2] || !result[3]) {
|
|
80
|
-
return { r: 255, g: 255, b: 255 };
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
r: parseInt(result[1], 16),
|
|
84
|
-
g: parseInt(result[2], 16),
|
|
85
|
-
b: parseInt(result[3], 16),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function rgbToHex(r: number, g: number, b: number): string {
|
|
90
|
-
return '#' + [r, g, b].map(x => x.toString(16).padStart(2, '0')).join('');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function hexTo256(hex: string): number {
|
|
94
|
-
const { r, g, b } = hexToRgb(hex);
|
|
95
|
-
|
|
96
|
-
if (r === g && g === b) {
|
|
97
|
-
if (r < 8) return 16;
|
|
98
|
-
if (r > 248) return 231;
|
|
99
|
-
return Math.round(((r - 8) / 247) * 24) + 232;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const ri = Math.round(r / 255 * 5);
|
|
103
|
-
const gi = Math.round(g / 255 * 5);
|
|
104
|
-
const bi = Math.round(b / 255 * 5);
|
|
105
|
-
|
|
106
|
-
return 16 + (36 * ri) + (6 * gi) + bi;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function colorToHex(color: string): string {
|
|
110
|
-
if (color.startsWith('#')) {
|
|
111
|
-
return color;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const named = CSS_NAMED_COLORS[color.toLowerCase()];
|
|
115
|
-
if (named) {
|
|
116
|
-
return named;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const rgbMatch = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
120
|
-
if (rgbMatch && rgbMatch[1] && rgbMatch[2] && rgbMatch[3]) {
|
|
121
|
-
return rgbToHex(
|
|
122
|
-
parseInt(rgbMatch[1]),
|
|
123
|
-
parseInt(rgbMatch[2]),
|
|
124
|
-
parseInt(rgbMatch[3])
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return '#ffffff';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function getANSIForeground(color: string, capability: ColorCapability): string {
|
|
132
|
-
if (capability === 'none') return '';
|
|
133
|
-
|
|
134
|
-
const lowerColor = color.toLowerCase();
|
|
135
|
-
|
|
136
|
-
if (capability === 'basic' && ANSI_16_COLORS[lowerColor]) {
|
|
137
|
-
return `\x1b[${ANSI_16_COLORS[lowerColor].fg}m`;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (capability === 'basic') {
|
|
141
|
-
const hex = colorToHex(color);
|
|
142
|
-
const nearestBasic = findNearestBasicColor(hex);
|
|
143
|
-
const basicColor = ANSI_16_COLORS[nearestBasic];
|
|
144
|
-
return basicColor ? `\x1b[${basicColor.fg}m` : '\x1b[37m';
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const hex = colorToHex(color);
|
|
148
|
-
const { r, g, b } = hexToRgb(hex);
|
|
149
|
-
return `\x1b[38;2;${r};${g};${b}m`;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function getANSIBackground(color: string, capability: ColorCapability): string {
|
|
153
|
-
if (capability === 'none') return '';
|
|
154
|
-
|
|
155
|
-
const lowerColor = color.toLowerCase();
|
|
156
|
-
|
|
157
|
-
if (capability === 'basic' && ANSI_16_COLORS[lowerColor]) {
|
|
158
|
-
return `\x1b[${ANSI_16_COLORS[lowerColor].bg}m`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (capability === 'basic') {
|
|
162
|
-
const hex = colorToHex(color);
|
|
163
|
-
const nearestBasic = findNearestBasicColor(hex);
|
|
164
|
-
const basicColor = ANSI_16_COLORS[nearestBasic];
|
|
165
|
-
return basicColor ? `\x1b[${basicColor.bg}m` : '\x1b[47m';
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const hex = colorToHex(color);
|
|
169
|
-
const { r, g, b } = hexToRgb(hex);
|
|
170
|
-
return `\x1b[48;2;${r};${g};${b}m`;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function getANSI256Foreground(colorIndex: number): string {
|
|
174
|
-
return `\x1b[38;5;${colorIndex}m`;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function getANSI256Background(colorIndex: number): string {
|
|
178
|
-
return `\x1b[48;5;${colorIndex}m`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function findNearestBasicColor(hex: string): string {
|
|
182
|
-
const { r, g, b } = hexToRgb(hex);
|
|
183
|
-
const basicColors: Record<string, RGB> = {
|
|
184
|
-
black: { r: 0, g: 0, b: 0 },
|
|
185
|
-
red: { r: 205, g: 0, b: 0 },
|
|
186
|
-
green: { r: 0, g: 205, b: 0 },
|
|
187
|
-
yellow: { r: 205, g: 205, b: 0 },
|
|
188
|
-
blue: { r: 0, g: 0, b: 238 },
|
|
189
|
-
magenta: { r: 205, g: 0, b: 205 },
|
|
190
|
-
cyan: { r: 0, g: 205, b: 205 },
|
|
191
|
-
white: { r: 229, g: 229, b: 229 },
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
let nearest = 'white';
|
|
195
|
-
let minDistance = Infinity;
|
|
196
|
-
|
|
197
|
-
for (const [name, rgb] of Object.entries(basicColors)) {
|
|
198
|
-
const distance = Math.sqrt(
|
|
199
|
-
Math.pow(r - rgb.r, 2) +
|
|
200
|
-
Math.pow(g - rgb.g, 2) +
|
|
201
|
-
Math.pow(b - rgb.b, 2)
|
|
202
|
-
);
|
|
203
|
-
if (distance < minDistance) {
|
|
204
|
-
minDistance = distance;
|
|
205
|
-
nearest = name;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return nearest;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export function extractGradientColors(gradient: string): string[] {
|
|
213
|
-
const hexMatches = gradient.match(/#[a-fA-F0-9]{6}/g) || [];
|
|
214
|
-
const rgbMatches = gradient.match(/rgba?\([^)]+\)/g) || [];
|
|
215
|
-
const namedMatches = gradient.match(/,\s*([a-z]+)(?:\s|,|\))/gi) || [];
|
|
216
|
-
|
|
217
|
-
const colors: string[] = [
|
|
218
|
-
...hexMatches,
|
|
219
|
-
...rgbMatches.map(colorToHex),
|
|
220
|
-
...namedMatches.map(m => {
|
|
221
|
-
const name = m.replace(/[,\s)]/g, '').toLowerCase();
|
|
222
|
-
return CSS_NAMED_COLORS[name] || null;
|
|
223
|
-
}).filter((c): c is string => c !== null)
|
|
224
|
-
];
|
|
225
|
-
|
|
226
|
-
return colors.length > 0 ? colors : ['#ffffff'];
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export function gradientToSingleColor(gradient: string): string {
|
|
230
|
-
const colors = extractGradientColors(gradient);
|
|
231
|
-
if (colors.length === 0) return '#ffffff';
|
|
232
|
-
if (colors.length === 1) return colors[0] ?? '#ffffff';
|
|
233
|
-
|
|
234
|
-
const rgbs = colors.map(c => hexToRgb(colorToHex(c)));
|
|
235
|
-
const avgR = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.r, 0) / rgbs.length);
|
|
236
|
-
const avgG = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.g, 0) / rgbs.length);
|
|
237
|
-
const avgB = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.b, 0) / rgbs.length);
|
|
238
|
-
|
|
239
|
-
return rgbToHex(avgR, avgG, avgB);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export function cssColorToANSI(
|
|
243
|
-
cssColor: string,
|
|
244
|
-
capability: ColorCapability,
|
|
245
|
-
isBackground: boolean = false
|
|
246
|
-
): string {
|
|
247
|
-
if (capability === 'none') return '';
|
|
248
|
-
|
|
249
|
-
let resolvedColor: string;
|
|
250
|
-
|
|
251
|
-
if (cssColor.includes('gradient')) {
|
|
252
|
-
resolvedColor = gradientToSingleColor(cssColor);
|
|
253
|
-
} else {
|
|
254
|
-
resolvedColor = colorToHex(cssColor);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return isBackground
|
|
258
|
-
? getANSIBackground(resolvedColor, capability)
|
|
259
|
-
: getANSIForeground(resolvedColor, capability);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export const ANSI = {
|
|
263
|
-
reset: '\x1b[0m',
|
|
264
|
-
bold: '\x1b[1m',
|
|
265
|
-
dim: '\x1b[2m',
|
|
266
|
-
italic: '\x1b[3m',
|
|
267
|
-
underline: '\x1b[4m',
|
|
268
|
-
blink: '\x1b[5m',
|
|
269
|
-
inverse: '\x1b[7m',
|
|
270
|
-
hidden: '\x1b[8m',
|
|
271
|
-
strikethrough: '\x1b[9m',
|
|
272
|
-
|
|
273
|
-
fg: {
|
|
274
|
-
black: '\x1b[30m',
|
|
275
|
-
red: '\x1b[31m',
|
|
276
|
-
green: '\x1b[32m',
|
|
277
|
-
yellow: '\x1b[33m',
|
|
278
|
-
blue: '\x1b[34m',
|
|
279
|
-
magenta: '\x1b[35m',
|
|
280
|
-
cyan: '\x1b[36m',
|
|
281
|
-
white: '\x1b[37m',
|
|
282
|
-
gray: '\x1b[90m',
|
|
283
|
-
brightRed: '\x1b[91m',
|
|
284
|
-
brightGreen: '\x1b[92m',
|
|
285
|
-
brightYellow: '\x1b[93m',
|
|
286
|
-
brightBlue: '\x1b[94m',
|
|
287
|
-
brightMagenta: '\x1b[95m',
|
|
288
|
-
brightCyan: '\x1b[96m',
|
|
289
|
-
brightWhite: '\x1b[97m',
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
bg: {
|
|
293
|
-
black: '\x1b[40m',
|
|
294
|
-
red: '\x1b[41m',
|
|
295
|
-
green: '\x1b[42m',
|
|
296
|
-
yellow: '\x1b[43m',
|
|
297
|
-
blue: '\x1b[44m',
|
|
298
|
-
magenta: '\x1b[45m',
|
|
299
|
-
cyan: '\x1b[46m',
|
|
300
|
-
white: '\x1b[47m',
|
|
301
|
-
gray: '\x1b[100m',
|
|
302
|
-
brightRed: '\x1b[101m',
|
|
303
|
-
brightGreen: '\x1b[102m',
|
|
304
|
-
brightYellow: '\x1b[103m',
|
|
305
|
-
brightBlue: '\x1b[104m',
|
|
306
|
-
brightMagenta: '\x1b[105m',
|
|
307
|
-
brightCyan: '\x1b[106m',
|
|
308
|
-
brightWhite: '\x1b[107m',
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
rgb: (r: number, g: number, b: number) => `\x1b[38;2;${r};${g};${b}m`,
|
|
312
|
-
bgRgb: (r: number, g: number, b: number) => `\x1b[48;2;${r};${g};${b}m`,
|
|
313
|
-
color256: (n: number) => `\x1b[38;5;${n}m`,
|
|
314
|
-
bgColor256: (n: number) => `\x1b[48;5;${n}m`,
|
|
315
|
-
};
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Terminal Formatter - Alignment, key-value, and advanced terminal formatting
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getTerminalWidth } from '../utils/environment-detector.js';
|
|
6
|
-
import { getANSIForeground, getANSIBackground, ANSI, type ColorCapability } from './color-converter.js';
|
|
7
|
-
import type { ColumnConfig, ColumnAlign, BadgeStyle, TimestampFormat, LogOptions } from '../types/index.js';
|
|
8
|
-
|
|
9
|
-
export function stripAnsi(str: string): string {
|
|
10
|
-
return str.replace(/\x1b\[[0-9;]*m/g, '');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getVisibleLength(str: string): number {
|
|
14
|
-
return stripAnsi(str).length;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function padToWidth(str: string, width: number, align: ColumnAlign = 'left'): string {
|
|
18
|
-
const visibleLen = getVisibleLength(str);
|
|
19
|
-
if (visibleLen >= width) return str;
|
|
20
|
-
|
|
21
|
-
const padding = width - visibleLen;
|
|
22
|
-
|
|
23
|
-
switch (align) {
|
|
24
|
-
case 'right':
|
|
25
|
-
return ' '.repeat(padding) + str;
|
|
26
|
-
case 'center':
|
|
27
|
-
const leftPad = Math.floor(padding / 2);
|
|
28
|
-
const rightPad = padding - leftPad;
|
|
29
|
-
return ' '.repeat(leftPad) + str + ' '.repeat(rightPad);
|
|
30
|
-
case 'left':
|
|
31
|
-
default:
|
|
32
|
-
return str + ' '.repeat(padding);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function formatWithRightAlign(
|
|
37
|
-
leftContent: string,
|
|
38
|
-
rightContent: string,
|
|
39
|
-
maxWidth?: number
|
|
40
|
-
): string {
|
|
41
|
-
const width = maxWidth ?? getTerminalWidth();
|
|
42
|
-
const leftLen = getVisibleLength(leftContent);
|
|
43
|
-
const rightLen = getVisibleLength(rightContent);
|
|
44
|
-
|
|
45
|
-
const gap = width - leftLen - rightLen;
|
|
46
|
-
if (gap <= 1) {
|
|
47
|
-
return `${leftContent} ${rightContent}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return `${leftContent}${' '.repeat(gap)}${rightContent}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function formatColumns(
|
|
54
|
-
columns: ColumnConfig[],
|
|
55
|
-
maxWidth?: number,
|
|
56
|
-
colorCapability: ColorCapability = 'full'
|
|
57
|
-
): string {
|
|
58
|
-
const width = maxWidth ?? getTerminalWidth();
|
|
59
|
-
const totalColumns = columns.length;
|
|
60
|
-
|
|
61
|
-
const columnsWithWidths = columns.map((col, idx) => {
|
|
62
|
-
if (col.width) return { ...col, calculatedWidth: col.width };
|
|
63
|
-
|
|
64
|
-
const remainingWidth = width - columns
|
|
65
|
-
.filter((c, i) => i !== idx && c.width)
|
|
66
|
-
.reduce((sum, c) => sum + (c.width ?? 0), 0);
|
|
67
|
-
|
|
68
|
-
const autoColumns = columns.filter(c => !c.width).length;
|
|
69
|
-
const calculatedWidth = Math.floor(remainingWidth / autoColumns);
|
|
70
|
-
|
|
71
|
-
return { ...col, calculatedWidth };
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return columnsWithWidths.map(col => {
|
|
75
|
-
let content = col.content;
|
|
76
|
-
|
|
77
|
-
if (col.color && colorCapability !== 'none') {
|
|
78
|
-
const colorCode = getANSIForeground(col.color, colorCapability);
|
|
79
|
-
content = `${colorCode}${content}${ANSI.reset}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return padToWidth(content, col.calculatedWidth, col.align);
|
|
83
|
-
}).join('');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function formatKeyValue(
|
|
87
|
-
obj: Record<string, unknown>,
|
|
88
|
-
colorCapability: ColorCapability = 'full',
|
|
89
|
-
options: { separator?: string; keyColor?: string; valueColor?: string } = {}
|
|
90
|
-
): string {
|
|
91
|
-
const {
|
|
92
|
-
separator = ' ',
|
|
93
|
-
keyColor = '#888888',
|
|
94
|
-
valueColor = '#00ffff'
|
|
95
|
-
} = options;
|
|
96
|
-
|
|
97
|
-
const entries = Object.entries(obj);
|
|
98
|
-
if (entries.length === 0) return '';
|
|
99
|
-
|
|
100
|
-
const keyColorCode = colorCapability !== 'none'
|
|
101
|
-
? getANSIForeground(keyColor, colorCapability)
|
|
102
|
-
: '';
|
|
103
|
-
const valueColorCode = colorCapability !== 'none'
|
|
104
|
-
? getANSIForeground(valueColor, colorCapability)
|
|
105
|
-
: '';
|
|
106
|
-
const reset = colorCapability !== 'none' ? ANSI.reset : '';
|
|
107
|
-
|
|
108
|
-
return entries
|
|
109
|
-
.map(([key, value]) => {
|
|
110
|
-
const valueStr = typeof value === 'object'
|
|
111
|
-
? JSON.stringify(value)
|
|
112
|
-
: String(value);
|
|
113
|
-
return `${keyColorCode}${key}:${reset} ${valueColorCode}${valueStr}${reset}`;
|
|
114
|
-
})
|
|
115
|
-
.join(separator);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function isKeyValueObject(obj: unknown): obj is Record<string, unknown> {
|
|
119
|
-
if (typeof obj !== 'object' || obj === null) return false;
|
|
120
|
-
if (Array.isArray(obj)) return false;
|
|
121
|
-
|
|
122
|
-
const proto = Object.getPrototypeOf(obj);
|
|
123
|
-
if (proto !== Object.prototype && proto !== null) return false;
|
|
124
|
-
|
|
125
|
-
const values = Object.values(obj);
|
|
126
|
-
return values.every(v =>
|
|
127
|
-
typeof v === 'string' ||
|
|
128
|
-
typeof v === 'number' ||
|
|
129
|
-
typeof v === 'boolean' ||
|
|
130
|
-
v === null
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function formatBadge(
|
|
135
|
-
badge: string,
|
|
136
|
-
style: BadgeStyle = 'brackets',
|
|
137
|
-
colorCapability: ColorCapability = 'full',
|
|
138
|
-
color?: string
|
|
139
|
-
): string {
|
|
140
|
-
const reset = colorCapability !== 'none' ? ANSI.reset : '';
|
|
141
|
-
|
|
142
|
-
const text = badge.toUpperCase();
|
|
143
|
-
|
|
144
|
-
switch (style) {
|
|
145
|
-
case 'rounded':
|
|
146
|
-
const colorCode1 = color && colorCapability !== 'none' ? getANSIForeground(color, colorCapability) : '';
|
|
147
|
-
const bgBlack1 = colorCapability !== 'none' ? ANSI.bg.black : '';
|
|
148
|
-
return `${bgBlack1}${colorCode1}⟨${text}⟩${reset}`;
|
|
149
|
-
case 'plain':
|
|
150
|
-
const colorCode2 = color && colorCapability !== 'none' ? getANSIForeground(color, colorCapability) : '';
|
|
151
|
-
return `${colorCode2}${text}${reset}`;
|
|
152
|
-
case 'unicode':
|
|
153
|
-
const colorCode3 = color && colorCapability !== 'none' ? getANSIForeground(color, colorCapability) : '';
|
|
154
|
-
const bgBlack3 = colorCapability !== 'none' ? ANSI.bg.black : '';
|
|
155
|
-
return `${bgBlack3}${colorCode3}╭${text}╮${reset}`;
|
|
156
|
-
case 'pill':
|
|
157
|
-
// Badge con background de color y texto blanco/negro
|
|
158
|
-
const bgColor = color && colorCapability !== 'none' ? getANSIBackground(color, colorCapability) : '';
|
|
159
|
-
const fgColor = colorCapability !== 'none' ? getANSIForeground('#000000', colorCapability) : '';
|
|
160
|
-
return `${bgColor}${fgColor}[${text}]${reset}`;
|
|
161
|
-
case 'brackets':
|
|
162
|
-
default:
|
|
163
|
-
const colorCode5 = color && colorCapability !== 'none' ? getANSIForeground(color, colorCapability) : '';
|
|
164
|
-
const bgBlack5 = colorCapability !== 'none' ? ANSI.bg.black : '';
|
|
165
|
-
return `${bgBlack5}${colorCode5}[${text}]${reset}`;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function formatTimestamp(
|
|
170
|
-
date: Date = new Date(),
|
|
171
|
-
format: TimestampFormat = 'time'
|
|
172
|
-
): string {
|
|
173
|
-
switch (format) {
|
|
174
|
-
case 'iso':
|
|
175
|
-
return date.toISOString();
|
|
176
|
-
case 'date':
|
|
177
|
-
return date.toISOString().split('T')[0] ?? '';
|
|
178
|
-
case 'time':
|
|
179
|
-
return date.toTimeString().slice(0, 8);
|
|
180
|
-
case 'timeMs':
|
|
181
|
-
return date.toTimeString().slice(0, 8) + '.' +
|
|
182
|
-
String(date.getMilliseconds()).padStart(3, '0');
|
|
183
|
-
case 'relative':
|
|
184
|
-
return formatRelativeTime(date);
|
|
185
|
-
case 'elapsed':
|
|
186
|
-
return formatElapsedTime(date);
|
|
187
|
-
case 'custom':
|
|
188
|
-
default:
|
|
189
|
-
return date.toLocaleTimeString();
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
let startTime: number | null = null;
|
|
194
|
-
|
|
195
|
-
export function formatRelativeTime(date: Date): string {
|
|
196
|
-
if (startTime === null) {
|
|
197
|
-
startTime = Date.now();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const diff = date.getTime() - startTime;
|
|
201
|
-
|
|
202
|
-
if (diff < 1000) {
|
|
203
|
-
return `+${diff}ms`;
|
|
204
|
-
} else if (diff < 60000) {
|
|
205
|
-
return `+${(diff / 1000).toFixed(1)}s`;
|
|
206
|
-
} else {
|
|
207
|
-
const mins = Math.floor(diff / 60000);
|
|
208
|
-
const secs = Math.floor((diff % 60000) / 1000);
|
|
209
|
-
return `+${mins}m${secs}s`;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export function formatElapsedTime(date: Date): string {
|
|
214
|
-
if (startTime === null) {
|
|
215
|
-
startTime = Date.now();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const diff = date.getTime() - startTime;
|
|
219
|
-
const hours = Math.floor(diff / 3600000);
|
|
220
|
-
const mins = Math.floor((diff % 3600000) / 60000);
|
|
221
|
-
const secs = Math.floor((diff % 60000) / 1000);
|
|
222
|
-
|
|
223
|
-
return `${String(hours).padStart(2, '0')}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export function resetStartTime(): void {
|
|
227
|
-
startTime = Date.now();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function applyLogOptions(
|
|
231
|
-
message: string,
|
|
232
|
-
options: LogOptions,
|
|
233
|
-
colorCapability: ColorCapability = 'full'
|
|
234
|
-
): string {
|
|
235
|
-
let result = message;
|
|
236
|
-
|
|
237
|
-
if (options.rightAlign) {
|
|
238
|
-
result = formatWithRightAlign(message, options.rightAlign);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return result;
|
|
242
|
-
}
|