cli-menu-kit 0.1.20 → 0.1.22

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,14 +10,39 @@ 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
16
40
  */
17
41
  function renderSummaryTable(config) {
18
- const { title, sections, width } = config;
42
+ const { title, titleAlign = 'center', 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
@@ -26,9 +51,25 @@ function renderSummaryTable(config) {
26
51
  (0, terminal_js_1.writeLine)(`│${' '.repeat(boxWidth - 2)}│`);
27
52
  // Title if provided
28
53
  if (title) {
29
- const titlePadding = Math.floor((contentWidth - title.length) / 2);
30
- const titleLine = ' '.repeat(titlePadding + 2) + colors_js_1.colors.cyan + title + colors_js_1.colors.reset;
31
- const remainingSpace = boxWidth - titlePadding - title.length - 4;
54
+ let titleLine;
55
+ let remainingSpace;
56
+ if (titleAlign === 'left') {
57
+ titleLine = ` ${colors_js_1.colors.cyan}${title}${colors_js_1.colors.reset}`;
58
+ const plainTitle = title;
59
+ remainingSpace = boxWidth - plainTitle.length - 4;
60
+ }
61
+ else if (titleAlign === 'right') {
62
+ const plainTitle = title;
63
+ const rightPadding = contentWidth - plainTitle.length;
64
+ titleLine = ' '.repeat(rightPadding + 2) + colors_js_1.colors.cyan + title + colors_js_1.colors.reset;
65
+ remainingSpace = 2;
66
+ }
67
+ else {
68
+ // center (default)
69
+ const titlePadding = Math.floor((contentWidth - title.length) / 2);
70
+ titleLine = ' '.repeat(titlePadding + 2) + colors_js_1.colors.cyan + title + colors_js_1.colors.reset;
71
+ remainingSpace = boxWidth - titlePadding - title.length - 4;
72
+ }
32
73
  (0, terminal_js_1.writeLine)(`│${titleLine}${' '.repeat(remainingSpace)}│`);
33
74
  (0, terminal_js_1.writeLine)(`│${' '.repeat(boxWidth - 2)}│`);
34
75
  }
@@ -42,11 +83,33 @@ function renderSummaryTable(config) {
42
83
  }
43
84
  // Section items
44
85
  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))}│`);
86
+ const keyPadding = 15;
87
+ const valueMaxWidth = contentWidth - keyPadding - 2; // 2 for leading spaces
88
+ // Check if value needs wrapping
89
+ const plainValue = item.value.replace(/\x1b\[[0-9;]*m/g, '');
90
+ if (plainValue.length > valueMaxWidth) {
91
+ // Wrap the value
92
+ const wrappedLines = wrapText(plainValue, valueMaxWidth);
93
+ // First line with key
94
+ const firstLine = ` ${item.key}:${' '.repeat(Math.max(1, keyPadding - item.key.length))}${wrappedLines[0]}`;
95
+ const plainFirstLine = firstLine.replace(/\x1b\[[0-9;]*m/g, '');
96
+ const remainingSpace = boxWidth - plainFirstLine.length - 2;
97
+ (0, terminal_js_1.writeLine)(`│${firstLine}${' '.repeat(Math.max(0, remainingSpace))}│`);
98
+ // Subsequent lines with indentation
99
+ for (let i = 1; i < wrappedLines.length; i++) {
100
+ const continuationLine = ` ${' '.repeat(keyPadding)}${wrappedLines[i]}`;
101
+ const plainContinuationLine = continuationLine.replace(/\x1b\[[0-9;]*m/g, '');
102
+ const contRemainingSpace = boxWidth - plainContinuationLine.length - 2;
103
+ (0, terminal_js_1.writeLine)(`│${continuationLine}${' '.repeat(Math.max(0, contRemainingSpace))}│`);
104
+ }
105
+ }
106
+ else {
107
+ // No wrapping needed
108
+ const itemLine = ` ${item.key}:${' '.repeat(Math.max(1, keyPadding - item.key.length))}${item.value}`;
109
+ const plainItemLine = itemLine.replace(/\x1b\[[0-9;]*m/g, '');
110
+ const remainingSpace = boxWidth - plainItemLine.length - 2;
111
+ (0, terminal_js_1.writeLine)(`│${itemLine}${' '.repeat(Math.max(0, remainingSpace))}│`);
112
+ }
50
113
  });
51
114
  // Add spacing between sections (except after last section)
52
115
  if (sectionIndex < sections.length - 1) {
@@ -46,6 +46,7 @@ export interface MessageConfig {
46
46
  */
47
47
  export interface SummaryTableConfig {
48
48
  title?: string;
49
+ titleAlign?: 'left' | 'center' | 'right';
49
50
  sections: Array<{
50
51
  header?: string;
51
52
  items: Array<{
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.22",
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",