@vexify-org/yaggs 6.3.0 → 6.5.0

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.
Files changed (3) hide show
  1. package/index.js +10 -0
  2. package/lib/parser.js +55 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -117,6 +117,16 @@ class Yaggs {
117
117
  return this.parser.prompt(questions);
118
118
  }
119
119
 
120
+ progress(percentage, message = '') {
121
+ this.parser.progress(percentage, message);
122
+ return this;
123
+ }
124
+
125
+ table(data, options = {}) {
126
+ this.parser.table(data, options);
127
+ return this;
128
+ }
129
+
120
130
  check(fn) {
121
131
  this.middleware(fn);
122
132
  return this;
package/lib/parser.js CHANGED
@@ -771,6 +771,61 @@ complete -c ${this.scriptName} `;
771
771
  return answers;
772
772
  }
773
773
 
774
+ progress(percentage, message = '') {
775
+ const barLength = 40;
776
+ const filled = Math.round(barLength * percentage / 100);
777
+ const empty = barLength - filled;
778
+
779
+ const bar = '\u001b[32m' + '█'.repeat(filled) + '\u001b[0m' + '░'.repeat(empty);
780
+ const percent = percentage.toFixed(1);
781
+
782
+ process.stdout.write(`\r${bar} ${percent}% ${message}`);
783
+
784
+ if (percentage >= 100) {
785
+ process.stdout.write('\n');
786
+ }
787
+ }
788
+
789
+ table(data, options = {}) {
790
+ if (!data || data.length === 0) {
791
+ console.log('No data to display');
792
+ return;
793
+ }
794
+
795
+ const headers = Object.keys(data[0]);
796
+ const columnWidths = {};
797
+
798
+ for (const header of headers) {
799
+ const maxLen = Math.max(
800
+ header.length,
801
+ ...data.map(row => String(row[header] || '').length)
802
+ );
803
+ columnWidths[header] = maxLen + 2;
804
+ }
805
+
806
+ const border = '─'.repeat(Object.values(columnWidths).reduce((a, b) => a + b, 0) + headers.length + 1);
807
+
808
+ console.log('\u001b[36m' + border + '\u001b[0m');
809
+
810
+ let headerRow = '│ ';
811
+ for (const header of headers) {
812
+ headerRow += header.padEnd(columnWidths[header]) + '│ ';
813
+ }
814
+ console.log('\u001b[35m' + headerRow + '\u001b[0m');
815
+
816
+ console.log('\u001b[36m' + border + '\u001b[0m');
817
+
818
+ for (const row of data) {
819
+ let rowStr = '│ ';
820
+ for (const header of headers) {
821
+ rowStr += String(row[header] || '').padEnd(columnWidths[header]) + '│ ';
822
+ }
823
+ console.log(rowStr);
824
+ }
825
+
826
+ console.log('\u001b[36m' + border + '\u001b[0m');
827
+ }
828
+
774
829
  getHelp() {
775
830
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
776
831
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {