@getjack/jack 0.1.29 → 0.1.30
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/package.json +1 -1
- package/src/lib/output.ts +28 -9
package/package.json
CHANGED
package/src/lib/output.ts
CHANGED
|
@@ -162,7 +162,12 @@ export function box(title: string, lines: string[]): void {
|
|
|
162
162
|
if (isQuietMode) {
|
|
163
163
|
return; // Skip decorative boxes in quiet mode
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
// Respect terminal width (leave room for box borders + indent)
|
|
166
|
+
const termWidth = process.stderr.columns || process.stdout.columns || 80;
|
|
167
|
+
const maxBoxWidth = Math.max(30, termWidth - 6); // 2 indent + 2 borders + 2 padding
|
|
168
|
+
|
|
169
|
+
const contentMaxLen = Math.max(title.length, ...lines.map((l) => l.length));
|
|
170
|
+
const maxLen = Math.min(contentMaxLen, maxBoxWidth - 4);
|
|
166
171
|
const innerWidth = maxLen + 4;
|
|
167
172
|
|
|
168
173
|
const purple = isColorEnabled ? getRandomPurple() : "";
|
|
@@ -173,10 +178,15 @@ export function box(title: string, lines: string[]): void {
|
|
|
173
178
|
const fill = "▓".repeat(innerWidth);
|
|
174
179
|
const gradient = "░".repeat(innerWidth);
|
|
175
180
|
|
|
181
|
+
// Truncate text if too long for box
|
|
182
|
+
const truncate = (text: string) => (text.length > maxLen ? text.slice(0, maxLen - 1) + "…" : text);
|
|
183
|
+
|
|
176
184
|
// Pad plain text first, then apply colors (ANSI codes break padEnd calculation)
|
|
177
|
-
const pad = (text: string) => ` ${text.padEnd(maxLen)} `;
|
|
178
|
-
const padTitle = (text: string) =>
|
|
179
|
-
|
|
185
|
+
const pad = (text: string) => ` ${truncate(text).padEnd(maxLen)} `;
|
|
186
|
+
const padTitle = (text: string) => {
|
|
187
|
+
const t = truncate(text);
|
|
188
|
+
return ` ${bold}${t}${reset}${purple}${" ".repeat(maxLen - t.length)} `;
|
|
189
|
+
};
|
|
180
190
|
|
|
181
191
|
console.error("");
|
|
182
192
|
console.error(` ${purple}╔${bar}╗${reset}`);
|
|
@@ -198,7 +208,12 @@ export function celebrate(title: string, lines: string[]): void {
|
|
|
198
208
|
if (isQuietMode) {
|
|
199
209
|
return; // Skip decorative boxes in quiet mode
|
|
200
210
|
}
|
|
201
|
-
|
|
211
|
+
// Respect terminal width (leave room for box borders + indent)
|
|
212
|
+
const termWidth = process.stderr.columns || process.stdout.columns || 80;
|
|
213
|
+
const maxBoxWidth = Math.max(30, termWidth - 6); // 2 indent + 2 borders + 2 padding
|
|
214
|
+
|
|
215
|
+
const contentMaxLen = Math.max(title.length, ...lines.map((l) => l.length));
|
|
216
|
+
const maxLen = Math.min(contentMaxLen, maxBoxWidth - 4);
|
|
202
217
|
const innerWidth = maxLen + 4;
|
|
203
218
|
|
|
204
219
|
const purple = isColorEnabled ? getRandomPurple() : "";
|
|
@@ -210,12 +225,16 @@ export function celebrate(title: string, lines: string[]): void {
|
|
|
210
225
|
const gradient = "░".repeat(innerWidth);
|
|
211
226
|
const space = " ".repeat(innerWidth);
|
|
212
227
|
|
|
228
|
+
// Truncate text if too long for box
|
|
229
|
+
const truncate = (text: string) => (text.length > maxLen ? text.slice(0, maxLen - 1) + "…" : text);
|
|
230
|
+
|
|
213
231
|
// Center text based on visual length, then apply colors
|
|
214
232
|
const center = (text: string, applyBold = false) => {
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
|
|
233
|
+
const t = truncate(text);
|
|
234
|
+
const left = Math.floor((innerWidth - t.length) / 2);
|
|
235
|
+
const right = innerWidth - t.length - left;
|
|
236
|
+
const centered = " ".repeat(left) + t + " ".repeat(right);
|
|
237
|
+
return applyBold ? centered.replace(t, bold + t + reset + purple) : centered;
|
|
219
238
|
};
|
|
220
239
|
|
|
221
240
|
console.error("");
|