Skip to content

Commit e142742

Browse files
committed
Improve ctl help with terminal width test & multi-line desc support
1 parent 7ca4ef7 commit e142742

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/commands/ctl.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ function getTerminalWidth(): number {
149149
return process.stdout.columns || 80;
150150
}
151151

152-
function truncateToWidth(text: string, maxWidth: number): string {
153-
if (text.length <= maxWidth) return text;
154-
return text.slice(0, maxWidth - 3) + '...';
155-
}
156-
157152
function generateGeneralHelp(operations: HtkOperation[]): string {
158153
const termWidth = getTerminalWidth();
159154
const indent = 2;
@@ -181,7 +176,11 @@ function generateGeneralHelp(operations: HtkOperation[]): string {
181176
for (const op of ops) {
182177
const cmd = op.name.replace(/\./g, ' ');
183178
const padded = cmd.padEnd(27);
184-
const desc = truncateToWidth(op.description, descWidth);
179+
// Use first line only, truncated to fit in terminal
180+
const firstLine = op.description.split('\n')[0];
181+
const desc = firstLine.length > descWidth
182+
? firstLine.slice(0, descWidth - 3) + '...'
183+
: firstLine;
185184
lines.push(` ${padded}${desc}`);
186185
}
187186
}
@@ -219,7 +218,7 @@ function generateOperationHelp(op: HtkOperation): string {
219218
const desc = prop?.description || '';
220219
const enumStr = prop?.enum ? ` [${prop.enum.join('|')}]` : '';
221220
const defaultStr = prop?.default !== undefined ? ` (default: ${JSON.stringify(prop.default)})` : '';
222-
lines.push(` ${(`<${name}>`).padEnd(35)}${desc}${enumStr}${defaultStr}`);
221+
lines.push(` ${(`<${name}>`).padEnd(35)}${indentMultilineDesc(desc + enumStr + defaultStr, 37)}`);
223222
}
224223
}
225224

@@ -233,6 +232,13 @@ function generateOperationHelp(op: HtkOperation): string {
233232
return lines.join('\n');
234233
}
235234

235+
function indentMultilineDesc(desc: string, indent: number): string {
236+
const descLines = desc.split('\n');
237+
if (descLines.length <= 1) return desc;
238+
const pad = ' '.repeat(indent);
239+
return descLines[0] + '\n' + descLines.slice(1).map(l => pad + l).join('\n');
240+
}
241+
236242
function formatHelpParams(schema: any, lines: string[], prefix = ''): void {
237243
if (!schema?.properties) return;
238244
const positionalSet = new Set<string>(schema.required ?? []);
@@ -258,7 +264,8 @@ function formatHelpParams(schema: any, lines: string[], prefix = ''): void {
258264
const padded = flag.padEnd(35);
259265
const desc = prop.description || '';
260266
const defaultStr = prop.default !== undefined ? ` (default: ${JSON.stringify(prop.default)})` : '';
261-
lines.push(` ${padded}${desc}${defaultStr}`);
267+
// 2 leading spaces + 35 padded flag = 37 char indent for continuation lines
268+
lines.push(` ${padded}${indentMultilineDesc(desc + defaultStr, 37)}`);
262269

263270
if (prop.type === 'object' && prop.properties) {
264271
formatHelpParams(prop, lines, fullKey);

0 commit comments

Comments
 (0)