@aprovan/patchwork-ink 0.1.0-dev.6bd527d
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/.turbo/turbo-build.log +27 -0
- package/LICENSE +373 -0
- package/dist/chunk-5NAXJKRC.js +62 -0
- package/dist/chunk-5NAXJKRC.js.map +1 -0
- package/dist/chunk-FQPGY42H.js +183 -0
- package/dist/chunk-FQPGY42H.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/runner.d.ts +87 -0
- package/dist/runner.js +15 -0
- package/dist/runner.js.map +1 -0
- package/dist/setup.d.ts +40 -0
- package/dist/setup.js +9 -0
- package/dist/setup.js.map +1 -0
- package/package.json +53 -0
- package/src/index.ts +48 -0
- package/src/runner.ts +331 -0
- package/src/setup.ts +123 -0
- package/tsconfig.json +10 -0
- package/tsup.config.ts +11 -0
package/src/setup.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aprovan/patchwork-image-ink
|
|
3
|
+
*
|
|
4
|
+
* Setup function for the Ink terminal UI image.
|
|
5
|
+
* Handles terminal environment configuration for CLI widgets.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { WriteStream } from 'node:tty';
|
|
9
|
+
|
|
10
|
+
export interface SetupOptions {
|
|
11
|
+
/** Output stream (default: process.stdout) */
|
|
12
|
+
stdout?: WriteStream;
|
|
13
|
+
/** Input stream (default: process.stdin) */
|
|
14
|
+
stdin?: NodeJS.ReadStream;
|
|
15
|
+
/** Enable color support detection override */
|
|
16
|
+
colorMode?: 'detect' | 'ansi' | 'ansi256' | 'truecolor' | 'none';
|
|
17
|
+
/** Enable debug mode (default: false) */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface InkEnvironment {
|
|
22
|
+
stdout: WriteStream;
|
|
23
|
+
stdin: NodeJS.ReadStream;
|
|
24
|
+
colorSupport: 'none' | 'ansi' | 'ansi256' | 'truecolor';
|
|
25
|
+
isInteractive: boolean;
|
|
26
|
+
columns: number;
|
|
27
|
+
rows: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Detect terminal color support
|
|
32
|
+
*/
|
|
33
|
+
function detectColorSupport(
|
|
34
|
+
stdout: WriteStream,
|
|
35
|
+
): 'none' | 'ansi' | 'ansi256' | 'truecolor' {
|
|
36
|
+
// Check for NO_COLOR environment variable
|
|
37
|
+
if (process.env['NO_COLOR'] !== undefined) {
|
|
38
|
+
return 'none';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Check for FORCE_COLOR
|
|
42
|
+
const forceColor = process.env['FORCE_COLOR'];
|
|
43
|
+
if (forceColor !== undefined) {
|
|
44
|
+
if (forceColor === '0') return 'none';
|
|
45
|
+
if (forceColor === '1') return 'ansi';
|
|
46
|
+
if (forceColor === '2') return 'ansi256';
|
|
47
|
+
if (forceColor === '3') return 'truecolor';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Check COLORTERM for true color
|
|
51
|
+
if (
|
|
52
|
+
process.env['COLORTERM'] === 'truecolor' ||
|
|
53
|
+
process.env['COLORTERM'] === '24bit'
|
|
54
|
+
) {
|
|
55
|
+
return 'truecolor';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Check terminal capabilities
|
|
59
|
+
if (!stdout.isTTY) {
|
|
60
|
+
return 'none';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Check TERM for 256 color support
|
|
64
|
+
const term = process.env['TERM'] || '';
|
|
65
|
+
if (term.includes('256color') || term.includes('256')) {
|
|
66
|
+
return 'ansi256';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Default to basic ANSI if TTY
|
|
70
|
+
return 'ansi';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Setup the Ink terminal UI image runtime environment
|
|
75
|
+
*
|
|
76
|
+
* @param options - Optional configuration
|
|
77
|
+
* @returns Environment configuration for Ink
|
|
78
|
+
*/
|
|
79
|
+
export function setup(options: SetupOptions = {}): InkEnvironment {
|
|
80
|
+
const {
|
|
81
|
+
stdout = process.stdout as WriteStream,
|
|
82
|
+
stdin = process.stdin,
|
|
83
|
+
colorMode = 'detect',
|
|
84
|
+
debug = false,
|
|
85
|
+
} = options;
|
|
86
|
+
|
|
87
|
+
// Detect or use specified color mode
|
|
88
|
+
let colorSupport: 'none' | 'ansi' | 'ansi256' | 'truecolor';
|
|
89
|
+
if (colorMode === 'detect') {
|
|
90
|
+
colorSupport = detectColorSupport(stdout);
|
|
91
|
+
} else {
|
|
92
|
+
colorSupport = colorMode;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Get terminal dimensions
|
|
96
|
+
const columns = stdout.columns || 80;
|
|
97
|
+
const rows = stdout.rows || 24;
|
|
98
|
+
|
|
99
|
+
// Check if interactive
|
|
100
|
+
const isInteractive = stdin.isTTY ?? false;
|
|
101
|
+
|
|
102
|
+
if (debug) {
|
|
103
|
+
console.error(`[patchwork-ink] Color support: ${colorSupport}`);
|
|
104
|
+
console.error(`[patchwork-ink] Terminal size: ${columns}x${rows}`);
|
|
105
|
+
console.error(`[patchwork-ink] Interactive: ${isInteractive}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
stdout,
|
|
110
|
+
stdin,
|
|
111
|
+
colorSupport,
|
|
112
|
+
isInteractive,
|
|
113
|
+
columns,
|
|
114
|
+
rows,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Cleanup - no-op for CLI but provided for API consistency
|
|
120
|
+
*/
|
|
121
|
+
export function cleanup(): void {
|
|
122
|
+
// No cleanup needed for terminal
|
|
123
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ['src/index.ts', 'src/setup.ts', 'src/runner.ts'],
|
|
5
|
+
format: ['esm'],
|
|
6
|
+
dts: true,
|
|
7
|
+
sourcemap: true,
|
|
8
|
+
clean: true,
|
|
9
|
+
target: 'node20',
|
|
10
|
+
external: ['react', 'ink', 'chalk'],
|
|
11
|
+
});
|