kailogger 1.0.0-dark.red → 1.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/README.md +195 -53
- package/dist/core/Config.d.ts +15 -0
- package/dist/core/Config.js +44 -0
- package/dist/core/Logger.d.ts +75 -4
- package/dist/core/Logger.js +375 -47
- package/dist/core/Scope.d.ts +13 -0
- package/dist/core/Scope.js +36 -0
- package/dist/features/Chart.d.ts +15 -0
- package/dist/features/Chart.js +64 -0
- package/dist/features/Diff.d.ts +3 -0
- package/dist/features/Diff.js +30 -0
- package/dist/features/Encrypt.d.ts +10 -0
- package/dist/features/Encrypt.js +47 -0
- package/dist/features/Notify.d.ts +14 -0
- package/dist/features/Notify.js +70 -0
- package/dist/features/Screenshot.d.ts +10 -0
- package/dist/features/Screenshot.js +106 -0
- package/dist/features/Sound.d.ts +12 -0
- package/dist/features/Sound.js +116 -0
- package/dist/features/Timer.d.ts +6 -0
- package/dist/features/Timer.js +38 -0
- package/dist/features/Tree.d.ts +7 -0
- package/dist/features/Tree.js +25 -0
- package/dist/features/index.d.ts +8 -0
- package/dist/features/index.js +24 -0
- package/dist/icon/logo.png +0 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +21 -1
- package/dist/sounds/error.wav +0 -0
- package/dist/sounds/notification.wav +0 -0
- package/dist/sounds/success.wav +0 -0
- package/dist/sounds/warning.wav +0 -0
- package/dist/styles/KaiChroma.d.ts +85 -0
- package/dist/styles/KaiChroma.js +407 -0
- package/dist/styles/gradients.d.ts +28 -0
- package/dist/styles/palettes.d.ts +21 -26
- package/dist/styles/palettes.js +167 -13
- package/dist/transports/ConsoleTransport.d.ts +9 -0
- package/dist/transports/ConsoleTransport.js +18 -0
- package/dist/transports/FileTransport.d.ts +16 -0
- package/dist/transports/FileTransport.js +84 -0
- package/dist/transports/WebhookTransport.d.ts +15 -0
- package/dist/transports/WebhookTransport.js +31 -0
- package/dist/transports/index.d.ts +3 -0
- package/dist/transports/index.js +19 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.js +11 -0
- package/dist/utils/json.d.ts +3 -0
- package/dist/utils/json.js +33 -0
- package/dist/utils/prettyError.d.ts +3 -0
- package/dist/utils/prettyError.js +94 -0
- package/dist/utils/progress.d.ts +11 -0
- package/dist/utils/progress.js +43 -0
- package/dist/utils/prompt.d.ts +4 -0
- package/dist/utils/prompt.js +59 -0
- package/dist/utils/selection.d.ts +4 -0
- package/dist/utils/selection.js +156 -0
- package/dist/utils/spinner.d.ts +1 -1
- package/dist/utils/spinner.js +9 -13
- package/dist/utils/stripAnsi.d.ts +1 -0
- package/dist/utils/stripAnsi.js +7 -0
- package/dist/utils/table.d.ts +3 -0
- package/dist/utils/table.js +35 -0
- package/examples/demo.js +134 -0
- package/examples/demo.ts +88 -25
- package/package.json +20 -6
- package/scripts/copy-assets.js +37 -0
- package/src/core/Config.ts +44 -0
- package/src/core/Logger.ts +427 -51
- package/src/core/Scope.ts +35 -0
- package/src/features/Chart.ts +81 -0
- package/src/features/Diff.ts +25 -0
- package/src/features/Encrypt.ts +47 -0
- package/src/features/Notify.ts +39 -0
- package/src/features/Screenshot.ts +70 -0
- package/src/features/Sound.ts +92 -0
- package/src/features/Timer.ts +35 -0
- package/src/features/Tree.ts +25 -0
- package/src/features/index.ts +8 -0
- package/src/icon/logo.png +0 -0
- package/src/index.ts +13 -1
- package/src/sounds/error.wav +0 -0
- package/src/sounds/notification.wav +0 -0
- package/src/sounds/success.wav +0 -0
- package/src/sounds/warning.wav +0 -0
- package/src/styles/KaiChroma.ts +370 -0
- package/src/styles/palettes.ts +197 -14
- package/src/transports/ConsoleTransport.ts +19 -0
- package/src/transports/FileTransport.ts +55 -0
- package/src/transports/WebhookTransport.ts +37 -0
- package/src/transports/index.ts +3 -0
- package/src/types/cli-highlight.d.ts +3 -0
- package/src/types/index.ts +23 -0
- package/src/utils/json.ts +33 -0
- package/src/utils/prettyError.ts +65 -0
- package/src/utils/progress.ts +56 -0
- package/src/utils/prompt.ts +27 -0
- package/src/utils/selection.ts +136 -0
- package/src/utils/spinner.ts +11 -7
- package/src/utils/stripAnsi.ts +6 -0
- package/src/utils/table.ts +38 -0
- package/src/styles/gradients.ts +0 -22
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LogLevel, Transport } from '../types';
|
|
2
|
+
import { ThemeName } from '../styles/palettes';
|
|
3
|
+
export declare class ConsoleTransport implements Transport {
|
|
4
|
+
name: string;
|
|
5
|
+
private theme;
|
|
6
|
+
constructor(theme?: ThemeName);
|
|
7
|
+
setTheme(theme: ThemeName): void;
|
|
8
|
+
log(level: LogLevel, message: string, meta?: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleTransport = void 0;
|
|
4
|
+
const palettes_1 = require("../styles/palettes");
|
|
5
|
+
class ConsoleTransport {
|
|
6
|
+
constructor(theme = 'zen') {
|
|
7
|
+
this.name = 'console';
|
|
8
|
+
this.theme = theme;
|
|
9
|
+
}
|
|
10
|
+
setTheme(theme) {
|
|
11
|
+
this.theme = theme;
|
|
12
|
+
palettes_1.paint.setTheme(theme);
|
|
13
|
+
}
|
|
14
|
+
log(level, message, meta) {
|
|
15
|
+
console.log(message, ...(meta?.args || []));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ConsoleTransport = ConsoleTransport;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LogLevel, Transport } from '../types';
|
|
2
|
+
export interface FileTransportOptions {
|
|
3
|
+
filename: string;
|
|
4
|
+
maxSize?: number;
|
|
5
|
+
maxFiles?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class FileTransport implements Transport {
|
|
8
|
+
name: string;
|
|
9
|
+
private filename;
|
|
10
|
+
private maxSize;
|
|
11
|
+
private maxFiles;
|
|
12
|
+
constructor(options: FileTransportOptions);
|
|
13
|
+
private getTimestamp;
|
|
14
|
+
private rotate;
|
|
15
|
+
log(level: LogLevel, message: string, meta?: any): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FileTransport = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const stripAnsi_1 = require("../utils/stripAnsi");
|
|
40
|
+
class FileTransport {
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.name = 'file';
|
|
43
|
+
this.filename = options.filename;
|
|
44
|
+
this.maxSize = options.maxSize || 10 * 1024 * 1024;
|
|
45
|
+
this.maxFiles = options.maxFiles || 5;
|
|
46
|
+
const dir = path.dirname(this.filename);
|
|
47
|
+
if (dir && !fs.existsSync(dir)) {
|
|
48
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
getTimestamp() {
|
|
52
|
+
return new Date().toISOString();
|
|
53
|
+
}
|
|
54
|
+
rotate() {
|
|
55
|
+
try {
|
|
56
|
+
const stats = fs.statSync(this.filename);
|
|
57
|
+
if (stats.size >= this.maxSize) {
|
|
58
|
+
for (let i = this.maxFiles - 1; i >= 1; i--) {
|
|
59
|
+
const oldFile = `${this.filename}.${i}`;
|
|
60
|
+
const newFile = `${this.filename}.${i + 1}`;
|
|
61
|
+
if (fs.existsSync(oldFile)) {
|
|
62
|
+
if (i === this.maxFiles - 1) {
|
|
63
|
+
fs.unlinkSync(oldFile);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
fs.renameSync(oldFile, newFile);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
fs.renameSync(this.filename, `${this.filename}.1`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
// File doesn't exist yet, that's fine
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
log(level, message, meta) {
|
|
78
|
+
this.rotate();
|
|
79
|
+
const cleanMessage = (0, stripAnsi_1.stripAnsi)(message);
|
|
80
|
+
const logLine = `${this.getTimestamp()} [${level.toUpperCase()}] ${cleanMessage}\n`;
|
|
81
|
+
fs.appendFileSync(this.filename, logLine);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.FileTransport = FileTransport;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LogLevel, Transport } from '../types';
|
|
2
|
+
export interface WebhookTransportOptions {
|
|
3
|
+
url: string;
|
|
4
|
+
method?: 'POST' | 'PUT';
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
minLevel?: LogLevel;
|
|
7
|
+
}
|
|
8
|
+
export declare class WebhookTransport implements Transport {
|
|
9
|
+
name: string;
|
|
10
|
+
private url;
|
|
11
|
+
private method;
|
|
12
|
+
private headers;
|
|
13
|
+
constructor(options: WebhookTransportOptions);
|
|
14
|
+
log(level: LogLevel, message: string, meta?: any): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebhookTransport = void 0;
|
|
4
|
+
const stripAnsi_1 = require("../utils/stripAnsi");
|
|
5
|
+
class WebhookTransport {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.name = 'webhook';
|
|
8
|
+
this.url = options.url;
|
|
9
|
+
this.method = options.method || 'POST';
|
|
10
|
+
this.headers = options.headers || { 'Content-Type': 'application/json' };
|
|
11
|
+
}
|
|
12
|
+
async log(level, message, meta) {
|
|
13
|
+
try {
|
|
14
|
+
const payload = {
|
|
15
|
+
timestamp: new Date().toISOString(),
|
|
16
|
+
level: level.toUpperCase(),
|
|
17
|
+
message: (0, stripAnsi_1.stripAnsi)(message),
|
|
18
|
+
meta
|
|
19
|
+
};
|
|
20
|
+
await fetch(this.url, {
|
|
21
|
+
method: this.method,
|
|
22
|
+
headers: this.headers,
|
|
23
|
+
body: JSON.stringify(payload)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error('[KaiLogger] Webhook transport failed:', e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.WebhookTransport = WebhookTransport;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ConsoleTransport"), exports);
|
|
18
|
+
__exportStar(require("./FileTransport"), exports);
|
|
19
|
+
__exportStar(require("./WebhookTransport"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'success' | 'warning' | 'error' | 'silent';
|
|
2
|
+
export declare const LOG_LEVEL_PRIORITY: Record<LogLevel, number>;
|
|
3
|
+
export interface KaiConfig {
|
|
4
|
+
theme?: string;
|
|
5
|
+
level?: LogLevel;
|
|
6
|
+
timestamp?: 'ISO' | 'locale' | 'relative' | 'none';
|
|
7
|
+
silent?: boolean;
|
|
8
|
+
transports?: Transport[];
|
|
9
|
+
}
|
|
10
|
+
export interface Transport {
|
|
11
|
+
name: string;
|
|
12
|
+
log(level: LogLevel, message: string, meta?: any): void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface Formatter {
|
|
15
|
+
format(level: LogLevel, message: string, timestamp: string, scope?: string): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KaiJson = void 0;
|
|
4
|
+
const KaiChroma_1 = require("../styles/KaiChroma");
|
|
5
|
+
class KaiJson {
|
|
6
|
+
static print(obj, theme) {
|
|
7
|
+
const jsonStr = JSON.stringify(obj, null, 2);
|
|
8
|
+
// Manual colorization for full control using KaiChroma
|
|
9
|
+
const colored = jsonStr
|
|
10
|
+
// Strings (keys)
|
|
11
|
+
.replace(/"([^"]+)":/g, (match, key) => {
|
|
12
|
+
return KaiChroma_1.KaiChroma.hex(theme.info[0], `"${key}"`) + ':';
|
|
13
|
+
})
|
|
14
|
+
// String values
|
|
15
|
+
.replace(/: "([^"]*)"/g, (match, val) => {
|
|
16
|
+
return ': ' + KaiChroma_1.KaiChroma.hex(theme.success[1], `"${val}"`);
|
|
17
|
+
})
|
|
18
|
+
// Numbers
|
|
19
|
+
.replace(/: (\d+\.?\d*)/g, (match, num) => {
|
|
20
|
+
return ': ' + KaiChroma_1.KaiChroma.hex(theme.warning[0], num);
|
|
21
|
+
})
|
|
22
|
+
// Booleans
|
|
23
|
+
.replace(/: (true|false)/g, (match, bool) => {
|
|
24
|
+
return ': ' + KaiChroma_1.KaiChroma.hex(theme.error[0], bool);
|
|
25
|
+
})
|
|
26
|
+
// Null
|
|
27
|
+
.replace(/: (null)/g, (match, n) => {
|
|
28
|
+
return ': ' + KaiChroma_1.KaiChroma.hex(theme.dim, n);
|
|
29
|
+
});
|
|
30
|
+
console.log(colored);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.KaiJson = KaiJson;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.PrettyError = void 0;
|
|
37
|
+
const stackTrace = __importStar(require("stack-trace"));
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const KaiChroma_1 = require("../styles/KaiChroma");
|
|
40
|
+
const palettes_1 = require("../styles/palettes");
|
|
41
|
+
class PrettyError {
|
|
42
|
+
static handle(error, theme) {
|
|
43
|
+
const trace = stackTrace.parse(error);
|
|
44
|
+
console.log('');
|
|
45
|
+
console.log(palettes_1.paint.apply(` 💥 ${error.name} `, theme.error));
|
|
46
|
+
console.log(KaiChroma_1.KaiChroma.bold(error.message));
|
|
47
|
+
// Find the first relevant frame (not node internal)
|
|
48
|
+
const frame = trace.find(t => {
|
|
49
|
+
const file = t.getFileName();
|
|
50
|
+
return file && !file.includes('node_modules') && !file.startsWith('node:');
|
|
51
|
+
});
|
|
52
|
+
if (frame) {
|
|
53
|
+
const fileName = frame.getFileName();
|
|
54
|
+
const lineNumber = frame.getLineNumber();
|
|
55
|
+
console.log(KaiChroma_1.KaiChroma.hex('#666666', `at ${fileName}:${lineNumber}`));
|
|
56
|
+
console.log(KaiChroma_1.KaiChroma.hex('#666666', '─'.repeat(50)));
|
|
57
|
+
try {
|
|
58
|
+
const content = fs.readFileSync(fileName, 'utf-8');
|
|
59
|
+
const lines = content.split('\n');
|
|
60
|
+
const start = Math.max(0, lineNumber - 3);
|
|
61
|
+
const end = Math.min(lines.length, lineNumber + 2);
|
|
62
|
+
for (let i = start; i < end; i++) {
|
|
63
|
+
const isErrorLine = i + 1 === lineNumber;
|
|
64
|
+
const lineNumStr = (i + 1).toString().padEnd(4);
|
|
65
|
+
if (isErrorLine) {
|
|
66
|
+
const lineContent = KaiChroma_1.KaiChroma.bold(lines[i]);
|
|
67
|
+
console.log(palettes_1.paint.apply(` > ${lineNumStr} | ${lineContent}`, theme.error));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
console.log(KaiChroma_1.KaiChroma.hex('#888888', ` ${lineNumStr} | ${lines[i]}`));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// Fallback if file cannot be read
|
|
76
|
+
console.log(KaiChroma_1.KaiChroma.dim(' (Source code unavailable)'));
|
|
77
|
+
}
|
|
78
|
+
console.log(KaiChroma_1.KaiChroma.hex('#666666', '─'.repeat(50)));
|
|
79
|
+
}
|
|
80
|
+
// Show simplified stack
|
|
81
|
+
console.log('');
|
|
82
|
+
console.log(KaiChroma_1.KaiChroma.dim('Stack Trace:'));
|
|
83
|
+
trace.forEach(t => {
|
|
84
|
+
const fn = t.getFunctionName() || '<anonymous>';
|
|
85
|
+
const file = t.getFileName();
|
|
86
|
+
const line = t.getLineNumber();
|
|
87
|
+
if (file && !file.includes('node_modules')) {
|
|
88
|
+
console.log(KaiChroma_1.KaiChroma.dim(` at ${fn} (${file}:${line})`));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
console.log('');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.PrettyError = PrettyError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ThemeName } from '../styles/palettes';
|
|
2
|
+
export declare class KaiProgress {
|
|
3
|
+
private total;
|
|
4
|
+
private current;
|
|
5
|
+
private width;
|
|
6
|
+
private theme;
|
|
7
|
+
constructor(total: number, width?: number, theme?: ThemeName);
|
|
8
|
+
update(current: number): void;
|
|
9
|
+
increment(amount?: number): void;
|
|
10
|
+
private render;
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KaiProgress = void 0;
|
|
4
|
+
const KaiChroma_1 = require("../styles/KaiChroma");
|
|
5
|
+
const palettes_1 = require("../styles/palettes");
|
|
6
|
+
class KaiProgress {
|
|
7
|
+
constructor(total, width = 40, theme = 'zen') {
|
|
8
|
+
this.total = total;
|
|
9
|
+
this.current = 0;
|
|
10
|
+
this.width = width;
|
|
11
|
+
this.theme = theme;
|
|
12
|
+
}
|
|
13
|
+
update(current) {
|
|
14
|
+
this.current = current;
|
|
15
|
+
this.render();
|
|
16
|
+
}
|
|
17
|
+
increment(amount = 1) {
|
|
18
|
+
this.current = Math.min(this.total, this.current + amount);
|
|
19
|
+
this.render();
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
const percentage = Math.min(1, this.current / this.total);
|
|
23
|
+
const filledWidth = Math.round(this.width * percentage);
|
|
24
|
+
const emptyWidth = this.width - filledWidth;
|
|
25
|
+
const filledChar = '█';
|
|
26
|
+
const emptyChar = '░';
|
|
27
|
+
const filled = filledChar.repeat(filledWidth);
|
|
28
|
+
const empty = emptyChar.repeat(emptyWidth);
|
|
29
|
+
const palette = palettes_1.palettes[this.theme];
|
|
30
|
+
const colors = palette.info;
|
|
31
|
+
const dimColor = palette.dim;
|
|
32
|
+
// Utilizamos KaiChroma.gradient en lugar de gradient-string
|
|
33
|
+
const barFilled = KaiChroma_1.KaiChroma.gradient(colors, filled);
|
|
34
|
+
const barEmpty = KaiChroma_1.KaiChroma.hex(dimColor, empty);
|
|
35
|
+
const bar = barFilled + barEmpty;
|
|
36
|
+
const percentText = Math.round(percentage * 100).toString().padStart(3);
|
|
37
|
+
process.stdout.write(`\r${bar} ${percentText}%`);
|
|
38
|
+
if (this.current >= this.total) {
|
|
39
|
+
process.stdout.write('\n');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.KaiProgress = KaiProgress;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.KaiPrompt = void 0;
|
|
37
|
+
const readline = __importStar(require("readline"));
|
|
38
|
+
const palettes_1 = require("../styles/palettes");
|
|
39
|
+
class KaiPrompt {
|
|
40
|
+
static ask(question, theme) {
|
|
41
|
+
const rl = readline.createInterface({
|
|
42
|
+
input: process.stdin,
|
|
43
|
+
output: process.stdout
|
|
44
|
+
});
|
|
45
|
+
const q = palettes_1.paint.apply(`? ${question} `, theme.info);
|
|
46
|
+
return new Promise(resolve => {
|
|
47
|
+
rl.question(q, (answer) => {
|
|
48
|
+
rl.close();
|
|
49
|
+
resolve(answer);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
static confirm(question, theme) {
|
|
54
|
+
return this.ask(`${question} (y/n)`, theme).then(ans => {
|
|
55
|
+
return ans.toLowerCase().startsWith('y');
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.KaiPrompt = KaiPrompt;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.KaiSelection = void 0;
|
|
37
|
+
const KaiChroma_1 = require("../styles/KaiChroma");
|
|
38
|
+
const palettes_1 = require("../styles/palettes");
|
|
39
|
+
const readline = __importStar(require("readline"));
|
|
40
|
+
class KaiSelection {
|
|
41
|
+
static async select(question, options, theme) {
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
let selectedIndex = 0;
|
|
44
|
+
const stdin = process.stdin;
|
|
45
|
+
const stdout = process.stdout;
|
|
46
|
+
stdin.setRawMode(true);
|
|
47
|
+
stdin.resume();
|
|
48
|
+
stdin.setEncoding('utf8');
|
|
49
|
+
const render = () => {
|
|
50
|
+
readline.moveCursor(stdout, 0, -(options.length + 1));
|
|
51
|
+
readline.clearScreenDown(stdout);
|
|
52
|
+
const q = palettes_1.paint.apply(`? ${question} `, theme.info);
|
|
53
|
+
console.log(q);
|
|
54
|
+
options.forEach((opt, i) => {
|
|
55
|
+
if (i === selectedIndex) {
|
|
56
|
+
const pointer = palettes_1.paint.apply('>', theme.success);
|
|
57
|
+
const text = palettes_1.paint.apply(opt, theme.success);
|
|
58
|
+
console.log(`${pointer} ${text}`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.log(` ${opt}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
console.log('\n'.repeat(options.length));
|
|
66
|
+
render();
|
|
67
|
+
const handler = (key) => {
|
|
68
|
+
if (key === '\u0003') { // Ctrl+C
|
|
69
|
+
process.exit();
|
|
70
|
+
}
|
|
71
|
+
if (key === '\u001b[A') { // Up arrow
|
|
72
|
+
selectedIndex = (selectedIndex > 0) ? selectedIndex - 1 : options.length - 1;
|
|
73
|
+
render();
|
|
74
|
+
}
|
|
75
|
+
else if (key === '\u001b[B') { // Down arrow
|
|
76
|
+
selectedIndex = (selectedIndex < options.length - 1) ? selectedIndex + 1 : 0;
|
|
77
|
+
render();
|
|
78
|
+
}
|
|
79
|
+
else if (key === '\r') { // Enter
|
|
80
|
+
stdin.removeListener('data', handler);
|
|
81
|
+
stdin.setRawMode(false);
|
|
82
|
+
stdin.pause();
|
|
83
|
+
readline.moveCursor(stdout, 0, -(options.length + 1));
|
|
84
|
+
readline.clearScreenDown(stdout);
|
|
85
|
+
console.log(`${palettes_1.paint.apply(`✔ ${question}`, theme.success)} ${KaiChroma_1.KaiChroma.bold(options[selectedIndex])}`);
|
|
86
|
+
resolve(options[selectedIndex]);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
stdin.on('data', handler);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
static async multiselect(question, options, theme) {
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
let selectedIndex = 0;
|
|
95
|
+
const selected = new Set();
|
|
96
|
+
const stdin = process.stdin;
|
|
97
|
+
const stdout = process.stdout;
|
|
98
|
+
stdin.setRawMode(true);
|
|
99
|
+
stdin.resume();
|
|
100
|
+
stdin.setEncoding('utf8');
|
|
101
|
+
const render = () => {
|
|
102
|
+
readline.moveCursor(stdout, 0, -(options.length + 1));
|
|
103
|
+
readline.clearScreenDown(stdout);
|
|
104
|
+
const q = palettes_1.paint.apply(`? ${question} `, theme.info);
|
|
105
|
+
console.log(`${q} ${KaiChroma_1.KaiChroma.dim('(Space to select, Enter to confirm)')}`);
|
|
106
|
+
options.forEach((opt, i) => {
|
|
107
|
+
const isSelected = selected.has(i);
|
|
108
|
+
const isHovered = i === selectedIndex;
|
|
109
|
+
let prefix = isSelected ? palettes_1.paint.apply('◉', theme.success) : '◯';
|
|
110
|
+
let text = opt;
|
|
111
|
+
if (isHovered) {
|
|
112
|
+
prefix = palettes_1.paint.apply('>', theme.info) + ' ' + prefix;
|
|
113
|
+
text = palettes_1.paint.apply(text, theme.info);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
prefix = ' ' + prefix;
|
|
117
|
+
}
|
|
118
|
+
console.log(`${prefix} ${text}`);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
console.log('\n'.repeat(options.length));
|
|
122
|
+
render();
|
|
123
|
+
const handler = (key) => {
|
|
124
|
+
if (key === '\u0003')
|
|
125
|
+
process.exit();
|
|
126
|
+
if (key === '\u001b[A') { // Up
|
|
127
|
+
selectedIndex = (selectedIndex > 0) ? selectedIndex - 1 : options.length - 1;
|
|
128
|
+
render();
|
|
129
|
+
}
|
|
130
|
+
else if (key === '\u001b[B') { // Down
|
|
131
|
+
selectedIndex = (selectedIndex < options.length - 1) ? selectedIndex + 1 : 0;
|
|
132
|
+
render();
|
|
133
|
+
}
|
|
134
|
+
else if (key === ' ') { // Space
|
|
135
|
+
if (selected.has(selectedIndex))
|
|
136
|
+
selected.delete(selectedIndex);
|
|
137
|
+
else
|
|
138
|
+
selected.add(selectedIndex);
|
|
139
|
+
render();
|
|
140
|
+
}
|
|
141
|
+
else if (key === '\r') { // Enter
|
|
142
|
+
stdin.removeListener('data', handler);
|
|
143
|
+
stdin.setRawMode(false);
|
|
144
|
+
stdin.pause();
|
|
145
|
+
readline.moveCursor(stdout, 0, -(options.length + 1));
|
|
146
|
+
readline.clearScreenDown(stdout);
|
|
147
|
+
const result = options.filter((_, i) => selected.has(i));
|
|
148
|
+
console.log(`${palettes_1.paint.apply(`✔ ${question}`, theme.success)} ${KaiChroma_1.KaiChroma.bold(result.join(', '))}`);
|
|
149
|
+
resolve(result);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
stdin.on('data', handler);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.KaiSelection = KaiSelection;
|
package/dist/utils/spinner.d.ts
CHANGED