cli-menu-kit 0.1.20 → 0.1.21

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.
@@ -10,6 +10,30 @@ exports.createSimpleSummary = createSimpleSummary;
10
10
  const terminal_js_1 = require("../../core/terminal.js");
11
11
  const colors_js_1 = require("../../core/colors.js");
12
12
  const terminal_js_2 = require("../../core/terminal.js");
13
+ /**
14
+ * Wrap text to fit within a specific width
15
+ */
16
+ function wrapText(text, maxWidth) {
17
+ const words = text.split(' ');
18
+ const lines = [];
19
+ let currentLine = '';
20
+ for (const word of words) {
21
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
22
+ if (testLine.length <= maxWidth) {
23
+ currentLine = testLine;
24
+ }
25
+ else {
26
+ if (currentLine) {
27
+ lines.push(currentLine);
28
+ }
29
+ currentLine = word;
30
+ }
31
+ }
32
+ if (currentLine) {
33
+ lines.push(currentLine);
34
+ }
35
+ return lines;
36
+ }
13
37
  /**
14
38
  * Render a summary table
15
39
  * @param config - Summary table configuration
@@ -17,7 +41,8 @@ const terminal_js_2 = require("../../core/terminal.js");
17
41
  function renderSummaryTable(config) {
18
42
  const { title, sections, width } = config;
19
43
  const termWidth = (0, terminal_js_2.getTerminalWidth)();
20
- const boxWidth = width || Math.min(termWidth - 4, 60);
44
+ // Use full terminal width minus padding, or specified width
45
+ const boxWidth = width || Math.max(60, termWidth - 4);
21
46
  // Calculate content width (excluding borders and padding)
22
47
  const contentWidth = boxWidth - 4;
23
48
  // Top border
@@ -42,11 +67,33 @@ function renderSummaryTable(config) {
42
67
  }
43
68
  // Section items
44
69
  section.items.forEach(item => {
45
- const itemLine = ` ${item.key}:${' '.repeat(Math.max(1, 15 - item.key.length))}${item.value}`;
46
- // Remove ANSI codes for length calculation
47
- const plainItemLine = itemLine.replace(/\x1b\[[0-9;]*m/g, '');
48
- const remainingSpace = boxWidth - plainItemLine.length - 2;
49
- (0, terminal_js_1.writeLine)(`│${itemLine}${' '.repeat(Math.max(0, remainingSpace))}│`);
70
+ const keyPadding = 15;
71
+ const valueMaxWidth = contentWidth - keyPadding - 2; // 2 for leading spaces
72
+ // Check if value needs wrapping
73
+ const plainValue = item.value.replace(/\x1b\[[0-9;]*m/g, '');
74
+ if (plainValue.length > valueMaxWidth) {
75
+ // Wrap the value
76
+ const wrappedLines = wrapText(plainValue, valueMaxWidth);
77
+ // First line with key
78
+ const firstLine = ` ${item.key}:${' '.repeat(Math.max(1, keyPadding - item.key.length))}${wrappedLines[0]}`;
79
+ const plainFirstLine = firstLine.replace(/\x1b\[[0-9;]*m/g, '');
80
+ const remainingSpace = boxWidth - plainFirstLine.length - 2;
81
+ (0, terminal_js_1.writeLine)(`│${firstLine}${' '.repeat(Math.max(0, remainingSpace))}│`);
82
+ // Subsequent lines with indentation
83
+ for (let i = 1; i < wrappedLines.length; i++) {
84
+ const continuationLine = ` ${' '.repeat(keyPadding)}${wrappedLines[i]}`;
85
+ const plainContinuationLine = continuationLine.replace(/\x1b\[[0-9;]*m/g, '');
86
+ const contRemainingSpace = boxWidth - plainContinuationLine.length - 2;
87
+ (0, terminal_js_1.writeLine)(`│${continuationLine}${' '.repeat(Math.max(0, contRemainingSpace))}│`);
88
+ }
89
+ }
90
+ else {
91
+ // No wrapping needed
92
+ const itemLine = ` ${item.key}:${' '.repeat(Math.max(1, keyPadding - item.key.length))}${item.value}`;
93
+ const plainItemLine = itemLine.replace(/\x1b\[[0-9;]*m/g, '');
94
+ const remainingSpace = boxWidth - plainItemLine.length - 2;
95
+ (0, terminal_js_1.writeLine)(`│${itemLine}${' '.repeat(Math.max(0, remainingSpace))}│`);
96
+ }
50
97
  });
51
98
  // Add spacing between sections (except after last section)
52
99
  if (sectionIndex < sections.length - 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli-menu-kit",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "A lightweight, customizable CLI menu system with keyboard shortcuts and real-time rendering",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",