MCPcopy Index your code
hub / github.com/codeaashu/claude-code / renderVerticalFormat

Function renderVerticalFormat

src/components/MarkdownTable.tsx:241–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

239
240 // Render vertical format (key-value pairs) for extra-narrow terminals
241 function renderVerticalFormat(): string {
242 const lines_2: string[] = [];
243 const headers = token.header.map(h => getPlainText(h.tokens));
244 const separatorWidth = Math.min(terminalWidth - 1, 40);
245 const separator = '─'.repeat(separatorWidth);
246 // Small indent for wrapped lines (just 2 spaces)
247 const wrapIndent = ' ';
248 token.rows.forEach((row_2, rowIndex) => {
249 if (rowIndex > 0) {
250 lines_2.push(separator);
251 }
252 row_2.forEach((cell_0, colIndex_4) => {
253 const label = headers[colIndex_4] || `Column ${colIndex_4 + 1}`;
254 // Clean value: trim, remove extra internal whitespace/newlines
255 const rawValue = formatCell(cell_0.tokens).trimEnd();
256 const value = rawValue.replace(/\n+/g, ' ').replace(/\s+/g, ' ').trim();
257
258 // Wrap value to fit terminal, accounting for label on first line
259 const firstLineWidth = terminalWidth - stringWidth(label) - 3;
260 const subsequentLineWidth = terminalWidth - wrapIndent.length - 1;
261
262 // Two-pass wrap: first line is narrower (label takes space),
263 // continuation lines get the full width minus indent.
264 const firstPassLines = wrapText(value, Math.max(firstLineWidth, 10));
265 const firstLine = firstPassLines[0] || '';
266 let wrappedValue: string[];
267 if (firstPassLines.length <= 1 || subsequentLineWidth <= firstLineWidth) {
268 wrappedValue = firstPassLines;
269 } else {
270 // Re-join remaining text and re-wrap to the wider continuation width
271 const remainingText = firstPassLines.slice(1).map(l => l.trim()).join(' ');
272 const rewrapped = wrapText(remainingText, subsequentLineWidth);
273 wrappedValue = [firstLine, ...rewrapped];
274 }
275
276 // First line: bold label + value
277 lines_2.push(`${ANSI_BOLD_START}${label}:${ANSI_BOLD_END} ${wrappedValue[0] || ''}`);
278
279 // Subsequent lines with small indent (skip empty lines)
280 for (let i_3 = 1; i_3 < wrappedValue.length; i_3++) {
281 const line_1 = wrappedValue[i_3]!;
282 if (!line_1.trim()) continue;
283 lines_2.push(`${wrapIndent}${line_1}`);
284 }
285 });
286 });
287 return lines_2.join('\n');
288 }
289
290 // Choose format based on available width
291 if (useVerticalFormat) {

Callers 1

MarkdownTableFunction · 0.85

Calls 6

getPlainTextFunction · 0.85
formatCellFunction · 0.85
forEachMethod · 0.80
maxMethod · 0.80
wrapTextFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected