@vexify-org/yaggs 6.8.0 → 6.10.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.
- package/index.js +8 -0
- package/lib/parser.js +52 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -161,6 +161,14 @@ class Yaggs {
|
|
|
161
161
|
return this.parser.ask(question, options);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
spinner(message = 'Loading') {
|
|
165
|
+
return this.parser.spinner(message);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async confirm(message, options = {}) {
|
|
169
|
+
return this.parser.confirm(message, options);
|
|
170
|
+
}
|
|
171
|
+
|
|
164
172
|
check(fn) {
|
|
165
173
|
this.middleware(fn);
|
|
166
174
|
return this;
|
package/lib/parser.js
CHANGED
|
@@ -924,6 +924,58 @@ complete -c ${this.scriptName} `;
|
|
|
924
924
|
});
|
|
925
925
|
}
|
|
926
926
|
|
|
927
|
+
spinner(message = 'Loading') {
|
|
928
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
929
|
+
let frameIndex = 0;
|
|
930
|
+
let interval;
|
|
931
|
+
|
|
932
|
+
const start = () => {
|
|
933
|
+
interval = setInterval(() => {
|
|
934
|
+
process.stdout.write(`\r\u001b[34m${frames[frameIndex]} ${message}\u001b[0m`);
|
|
935
|
+
frameIndex = (frameIndex + 1) % frames.length;
|
|
936
|
+
}, 80);
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
const stop = (finalMessage = '') => {
|
|
940
|
+
clearInterval(interval);
|
|
941
|
+
if (finalMessage) {
|
|
942
|
+
process.stdout.write(`\r\u001b[32m✓ ${finalMessage}\u001b[0m\n`);
|
|
943
|
+
} else {
|
|
944
|
+
process.stdout.write('\r');
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
start();
|
|
949
|
+
|
|
950
|
+
return { stop };
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
async confirm(message, options = {}) {
|
|
954
|
+
const readline = require('readline');
|
|
955
|
+
const rl = readline.createInterface({
|
|
956
|
+
input: process.stdin,
|
|
957
|
+
output: process.stdout
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
return new Promise((resolve) => {
|
|
961
|
+
const defaultValue = options.default !== undefined ? (options.default ? 'Y/n' : 'y/N') : 'y/N';
|
|
962
|
+
|
|
963
|
+
rl.question(`\u001b[33m${message} [${defaultValue}]:\u001b[0m `, (input) => {
|
|
964
|
+
const answer = input.trim().toLowerCase();
|
|
965
|
+
|
|
966
|
+
let result;
|
|
967
|
+
if (answer === '') {
|
|
968
|
+
result = options.default !== undefined ? options.default : false;
|
|
969
|
+
} else {
|
|
970
|
+
result = ['yes', 'y', 'true', '1'].includes(answer);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
rl.close();
|
|
974
|
+
resolve(result);
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
|
|
927
979
|
getHelp() {
|
|
928
980
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
929
981
|
|