cli-menu-kit 0.1.21 → 0.1.23

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.
@@ -39,7 +39,7 @@ function wrapText(text, maxWidth) {
39
39
  * @param config - Summary table configuration
40
40
  */
41
41
  function renderSummaryTable(config) {
42
- const { title, sections, width } = config;
42
+ const { title, titleAlign = 'center', sections, width } = config;
43
43
  const termWidth = (0, terminal_js_2.getTerminalWidth)();
44
44
  // Use full terminal width minus padding, or specified width
45
45
  const boxWidth = width || Math.max(60, termWidth - 4);
@@ -51,9 +51,25 @@ function renderSummaryTable(config) {
51
51
  (0, terminal_js_1.writeLine)(`│${' '.repeat(boxWidth - 2)}│`);
52
52
  // Title if provided
53
53
  if (title) {
54
- const titlePadding = Math.floor((contentWidth - title.length) / 2);
55
- const titleLine = ' '.repeat(titlePadding + 2) + colors_js_1.colors.cyan + title + colors_js_1.colors.reset;
56
- 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
+ }
57
73
  (0, terminal_js_1.writeLine)(`│${titleLine}${' '.repeat(remainingSpace)}│`);
58
74
  (0, terminal_js_1.writeLine)(`│${' '.repeat(boxWidth - 2)}│`);
59
75
  }
@@ -61,13 +77,15 @@ function renderSummaryTable(config) {
61
77
  sections.forEach((section, sectionIndex) => {
62
78
  // Section header if provided
63
79
  if (section.header) {
64
- const headerLine = ` ${colors_js_1.colors.brightCyan}${section.header}${colors_js_1.colors.reset}`;
80
+ const headerLine = ` ${section.header}`;
65
81
  const remainingSpace = boxWidth - section.header.length - 4;
66
82
  (0, terminal_js_1.writeLine)(`│${headerLine}${' '.repeat(remainingSpace)}│`);
67
83
  }
84
+ // Calculate keyPadding based on longest key in this section
85
+ const maxKeyLength = Math.max(...section.items.map(item => item.key.length));
86
+ const keyPadding = maxKeyLength + 3; // +3 for colon and spacing
68
87
  // Section items
69
88
  section.items.forEach(item => {
70
- const keyPadding = 15;
71
89
  const valueMaxWidth = contentWidth - keyPadding - 2; // 2 for leading spaces
72
90
  // Check if value needs wrapping
73
91
  const plainValue = item.value.replace(/\x1b\[[0-9;]*m/g, '');
@@ -75,7 +93,7 @@ function renderSummaryTable(config) {
75
93
  // Wrap the value
76
94
  const wrappedLines = wrapText(plainValue, valueMaxWidth);
77
95
  // First line with key
78
- const firstLine = ` ${item.key}:${' '.repeat(Math.max(1, keyPadding - item.key.length))}${wrappedLines[0]}`;
96
+ const firstLine = ` ${colors_js_1.colors.cyan}${item.key}:${colors_js_1.colors.reset}${' '.repeat(Math.max(1, keyPadding - item.key.length))}${wrappedLines[0]}`;
79
97
  const plainFirstLine = firstLine.replace(/\x1b\[[0-9;]*m/g, '');
80
98
  const remainingSpace = boxWidth - plainFirstLine.length - 2;
81
99
  (0, terminal_js_1.writeLine)(`│${firstLine}${' '.repeat(Math.max(0, remainingSpace))}│`);
@@ -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.21",
3
+ "version": "0.1.23",
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",