tnp-core 18.0.42 → 18.0.44

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/lib/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UtilsMigrations = exports.UtilsString = exports.UtilsOs = exports.UtilsProcess = exports.Utils = void 0;
3
+ exports.UtilsTerminal = exports.UtilsMigrations = exports.UtilsString = exports.UtilsOs = exports.UtilsProcess = exports.Utils = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var core_models_1 = require("./core-models");
6
6
  var axios_1 = require("axios");
@@ -11,6 +11,7 @@ var core_imports_2 = require("./core-imports");
11
11
  var core_imports_3 = require("./core-imports");
12
12
  var core_imports_4 = require("./core-imports");
13
13
  var buffer_1 = require("buffer");
14
+ var net = require("net");
14
15
  //#endregion
15
16
  var BLOB_SUPPORTED_IN_SQLJS = false;
16
17
  //#region utils
@@ -984,6 +985,7 @@ var UtilsProcess;
984
985
  //#region utils os
985
986
  var UtilsOs;
986
987
  (function (UtilsOs) {
988
+ var _this = this;
987
989
  //#region utils os / is running in browser
988
990
  /**
989
991
  * check if script is running in client browser
@@ -1106,6 +1108,111 @@ var UtilsOs;
1106
1108
  //#endregion
1107
1109
  };
1108
1110
  //#endregion
1111
+ //#region utils os / is running in cli mode
1112
+ /**
1113
+ * Check whether the current process is running in CLI mode.
1114
+ */
1115
+ UtilsOs.isRunningInCliMode = function () {
1116
+ /* */
1117
+ /* */
1118
+ //#region @backendFunc
1119
+ return !!global['globalSystemToolMode'];
1120
+ //#endregion
1121
+ };
1122
+ //#endregion
1123
+ //#region utils os / is running in mocha test
1124
+ /**
1125
+ * Check whether the current process is running in mocha test.
1126
+ */
1127
+ UtilsOs.isRunningInMochaTest = function () {
1128
+ /* */
1129
+ /* */
1130
+ //#region @backendFunc
1131
+ return typeof global['it'] === 'function';
1132
+ //#endregion
1133
+ };
1134
+ //#endregion
1135
+ //#region utils os / is port in use
1136
+ var isPortInUseOnHost = function (port, host) {
1137
+ //#region @backendFunc
1138
+ return new Promise(function (resolve, reject) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1139
+ var server;
1140
+ return tslib_1.__generator(this, function (_a) {
1141
+ server = net.createServer();
1142
+ // If the port is already in use, you'll get an EADDRINUSE error.
1143
+ server.once('error', function (err) {
1144
+ // console.log('error', err);
1145
+ if (err.code === 'EADDRINUSE' || err.code === 'EACCES') {
1146
+ resolve(true); // Port is in use
1147
+ }
1148
+ else {
1149
+ reject(err); // Some other error occurred
1150
+ }
1151
+ });
1152
+ // If the server successfully starts listening, the port is free.
1153
+ server.once('listening', function () {
1154
+ server.close(function () {
1155
+ // console.log(`closing ${port} on ${host}`);
1156
+ resolve(false); // Port is not in use
1157
+ });
1158
+ });
1159
+ server.listen(port, host);
1160
+ return [2 /*return*/];
1161
+ });
1162
+ }); });
1163
+ //#endregion
1164
+ };
1165
+ /**
1166
+ * Checks if a given port is already in use (bound by another process).
1167
+ *
1168
+ * @param port - The port number to check.
1169
+ * @param host - The hostname or IP address to bind to (default: '127.0.0.1').
1170
+ * @returns Promise<boolean> - Resolves to `true` if the port is in use, otherwise `false`.
1171
+ */
1172
+ UtilsOs.isPortInUse = function (port, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1173
+ var hostArr, hostArr_1, hostArr_1_1, host, e_4_1;
1174
+ var e_4, _a;
1175
+ return tslib_1.__generator(this, function (_b) {
1176
+ switch (_b.label) {
1177
+ case 0:
1178
+ //#region @backendFunc
1179
+ options = options || {};
1180
+ hostArr = options.checkForSpecificOnlyHost
1181
+ ? [options.checkForSpecificOnlyHost]
1182
+ : ['::', '0.0.0.0', '127.0.0.1'];
1183
+ _b.label = 1;
1184
+ case 1:
1185
+ _b.trys.push([1, 6, 7, 8]);
1186
+ hostArr_1 = tslib_1.__values(hostArr), hostArr_1_1 = hostArr_1.next();
1187
+ _b.label = 2;
1188
+ case 2:
1189
+ if (!!hostArr_1_1.done) return [3 /*break*/, 5];
1190
+ host = hostArr_1_1.value;
1191
+ return [4 /*yield*/, isPortInUseOnHost(port, host)];
1192
+ case 3:
1193
+ if (_b.sent()) {
1194
+ return [2 /*return*/, true];
1195
+ }
1196
+ _b.label = 4;
1197
+ case 4:
1198
+ hostArr_1_1 = hostArr_1.next();
1199
+ return [3 /*break*/, 2];
1200
+ case 5: return [3 /*break*/, 8];
1201
+ case 6:
1202
+ e_4_1 = _b.sent();
1203
+ e_4 = { error: e_4_1 };
1204
+ return [3 /*break*/, 8];
1205
+ case 7:
1206
+ try {
1207
+ if (hostArr_1_1 && !hostArr_1_1.done && (_a = hostArr_1.return)) _a.call(hostArr_1);
1208
+ }
1209
+ finally { if (e_4) throw e_4.error; }
1210
+ return [7 /*endfinally*/];
1211
+ case 8: return [2 /*return*/, false];
1212
+ }
1213
+ });
1214
+ }); };
1215
+ //#endregion
1109
1216
  })(UtilsOs || (exports.UtilsOs = UtilsOs = {}));
1110
1217
  //#endregion
1111
1218
  //#region utils string
@@ -1159,4 +1266,476 @@ var UtilsMigrations;
1159
1266
  };
1160
1267
  })(UtilsMigrations || (exports.UtilsMigrations = UtilsMigrations = {}));
1161
1268
  //#endregion
1269
+ //#region utils terminal
1270
+ var UtilsTerminal;
1271
+ (function (UtilsTerminal) {
1272
+ var _this = this;
1273
+ //#region clear
1274
+ UtilsTerminal.clearConsole = function () {
1275
+ //#region @backendFunc
1276
+ index_1.Helpers.msgCacheClear();
1277
+ console.log('\x1Bc');
1278
+ // process.stdout.write('\033c\033[3J');
1279
+ // try {
1280
+ // run('clear').sync()
1281
+ // } catch (error) {
1282
+ // console.log('clear console not succedd')
1283
+ // }
1284
+ //#endregion
1285
+ };
1286
+ //#endregion
1287
+ //#region transform choices
1288
+ var transformChoices = function (choices) {
1289
+ //#region @backendFunc
1290
+ if (!core_imports_1._.isArray(choices) && core_imports_1._.isObject(choices)) {
1291
+ choices = Object.keys(choices)
1292
+ .map(function (key) {
1293
+ return {
1294
+ name: choices[key].name,
1295
+ value: key,
1296
+ };
1297
+ })
1298
+ .reduce(function (a, b) { return a.concat(b); }, []);
1299
+ }
1300
+ return choices.map(function (c) { return ({ name: c.name, value: c.value }); });
1301
+ //#endregion
1302
+ };
1303
+ //#endregion
1304
+ //#region multiselect
1305
+ UtilsTerminal.multiselect = function (options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1306
+ var select, fuzzy, choices, defaultValue, res;
1307
+ return tslib_1.__generator(this, function (_a) {
1308
+ switch (_a.label) {
1309
+ case 0: return [4 /*yield*/, Promise.resolve().then(function () { return require('inquirer-select-pro'); })];
1310
+ case 1:
1311
+ select = (_a.sent()).select;
1312
+ return [4 /*yield*/, Promise.resolve().then(function () { return require('fuzzy'); })];
1313
+ case 2:
1314
+ fuzzy = _a.sent();
1315
+ options = core_imports_1._.cloneDeep(options);
1316
+ options.autocomplete = core_imports_1._.isNil(options.autocomplete)
1317
+ ? true
1318
+ : options.autocomplete;
1319
+ choices = transformChoices(options.choices);
1320
+ defaultValue = options.defaultSelected || [];
1321
+ return [4 /*yield*/, select({
1322
+ message: options.question,
1323
+ // options: choices,
1324
+ clearInputWhenSelected: true,
1325
+ emptyText: '<< No results >>',
1326
+ multiple: !options.onlyOneChoice,
1327
+ canToggleAll: true,
1328
+ pageSize: 10,
1329
+ loop: true,
1330
+ defaultValue: defaultValue,
1331
+ options: !options.autocomplete
1332
+ ? choices
1333
+ : function (input) {
1334
+ if (input === void 0) { input = ''; }
1335
+ if (!input) {
1336
+ return choices;
1337
+ }
1338
+ var fuzzyResult = fuzzy.filter(input, choices.map(function (f) { return f.name; }));
1339
+ return fuzzyResult.map(function (el) {
1340
+ return {
1341
+ name: el.original,
1342
+ value: choices.find(function (c) { return c.name === el.original; }).value,
1343
+ };
1344
+ });
1345
+ },
1346
+ })];
1347
+ case 3:
1348
+ res = _a.sent();
1349
+ return [2 /*return*/, (Array.isArray(res) ? res : [res])];
1350
+ }
1351
+ });
1352
+ }); };
1353
+ /**
1354
+ * Similar to select but executes action if provided
1355
+ * @returns selected and executed value
1356
+ */
1357
+ UtilsTerminal.selectActionAndExecute = function (choices, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1358
+ var res;
1359
+ var _this = this;
1360
+ return tslib_1.__generator(this, function (_a) {
1361
+ switch (_a.label) {
1362
+ case 0:
1363
+ //#region @backendFunc
1364
+ options = options || {};
1365
+ options.question = options.question || 'Select action to execute';
1366
+ options.executeActionOnDefault = core_imports_1._.isBoolean(options.executeActionOnDefault)
1367
+ ? options.executeActionOnDefault
1368
+ : true;
1369
+ return [4 /*yield*/, UtilsTerminal.select(tslib_1.__assign(tslib_1.__assign({}, options), { choices: choices }))];
1370
+ case 1:
1371
+ res = _a.sent();
1372
+ if (!(res &&
1373
+ choices[res] &&
1374
+ core_imports_1._.isFunction(choices[res].action) &&
1375
+ options.executeActionOnDefault)) return [3 /*break*/, 3];
1376
+ return [4 /*yield*/, choices[res].action()];
1377
+ case 2:
1378
+ _a.sent();
1379
+ _a.label = 3;
1380
+ case 3:
1381
+ // console.log(`Response from select: "${res}"`);
1382
+ // pipeEnterToStdin();
1383
+ return [2 /*return*/, { selected: res, action: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
1384
+ switch (_a.label) {
1385
+ case 0: return [4 /*yield*/, choices[res].action()];
1386
+ case 1: return [2 /*return*/, _a.sent()];
1387
+ }
1388
+ }); }); } }];
1389
+ }
1390
+ });
1391
+ }); };
1392
+ //#endregion
1393
+ //#region select
1394
+ UtilsTerminal.select = function (options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1395
+ var choices, preselectedIndex, prompt, AutoComplete, res, Select, res_1;
1396
+ var _a;
1397
+ return tslib_1.__generator(this, function (_b) {
1398
+ switch (_b.label) {
1399
+ case 0:
1400
+ //#region @backendFunc
1401
+ options = core_imports_1._.cloneDeep(options);
1402
+ options.hint = core_imports_1._.isNil(options.hint)
1403
+ ? '- Space to select. Return to submit'
1404
+ : options.hint;
1405
+ options.autocomplete = core_imports_1._.isNil(options.autocomplete)
1406
+ ? true
1407
+ : options.autocomplete;
1408
+ choices = transformChoices(options.choices);
1409
+ preselectedIndex = choices.findIndex(function (c) { return c.value === options.defaultSelected; }) || 0;
1410
+ if (preselectedIndex === -1) {
1411
+ preselectedIndex = 0;
1412
+ }
1413
+ if (!options.autocomplete) return [3 /*break*/, 2];
1414
+ AutoComplete = require('enquirer').AutoComplete;
1415
+ prompt = new AutoComplete({
1416
+ name: 'value',
1417
+ message: options.question,
1418
+ limit: 10,
1419
+ multiple: false,
1420
+ initial: preselectedIndex,
1421
+ choices: choices,
1422
+ hint: options.hint,
1423
+ footer: function () {
1424
+ return core_imports_1.chalk.green('(Scroll up and down to reveal more choices)');
1425
+ },
1426
+ });
1427
+ return [4 /*yield*/, prompt.run()];
1428
+ case 1:
1429
+ res = _b.sent();
1430
+ // console.log({choices})
1431
+ // console.log(`Selected!!!: "${res}" `);
1432
+ return [2 /*return*/, res];
1433
+ case 2:
1434
+ Select = require('enquirer').Select;
1435
+ prompt = new Select({
1436
+ // name: 'value',
1437
+ message: options.question,
1438
+ choices: choices,
1439
+ });
1440
+ return [4 /*yield*/, prompt.run()];
1441
+ case 3:
1442
+ res_1 = _b.sent();
1443
+ return [2 /*return*/, (_a = choices.find(function (c) { return c.name === res_1; })) === null || _a === void 0 ? void 0 : _a.value];
1444
+ }
1445
+ });
1446
+ }); };
1447
+ //#endregion
1448
+ //#region pipe enter to stdin
1449
+ UtilsTerminal.pipeEnterToStdin = function () {
1450
+ //#region @backendFunc
1451
+ process.stdin.push('\n');
1452
+ //#endregion
1453
+ };
1454
+ //#endregion
1455
+ //#region input
1456
+ UtilsTerminal.input = function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
1457
+ var initial, inquirer, response, anwser, error_1;
1458
+ var defaultValue = _b.defaultValue, question = _b.question, required = _b.required;
1459
+ return tslib_1.__generator(this, function (_c) {
1460
+ switch (_c.label) {
1461
+ case 0:
1462
+ initial = defaultValue || '';
1463
+ return [4 /*yield*/, Promise.resolve().then(function () { return require('inquirer'); })];
1464
+ case 1:
1465
+ inquirer = _c.sent();
1466
+ _c.label = 2;
1467
+ case 2:
1468
+ if (!true) return [3 /*break*/, 7];
1469
+ _c.label = 3;
1470
+ case 3:
1471
+ _c.trys.push([3, 5, , 6]);
1472
+ return [4 /*yield*/, inquirer.prompt({
1473
+ type: 'input',
1474
+ name: 'name',
1475
+ message: question,
1476
+ default: initial,
1477
+ // required: _.isNil(required) ? true : required,
1478
+ })];
1479
+ case 4:
1480
+ response = _c.sent();
1481
+ anwser = response.name;
1482
+ if (required && !anwser) {
1483
+ console.warn("Answer is required...");
1484
+ return [3 /*break*/, 2];
1485
+ }
1486
+ return [2 /*return*/, anwser];
1487
+ case 5:
1488
+ error_1 = _c.sent();
1489
+ console.error(error_1);
1490
+ if (required) {
1491
+ console.warn("Something went wrong, please try again...");
1492
+ return [3 /*break*/, 2];
1493
+ }
1494
+ else {
1495
+ return [2 /*return*/, ''];
1496
+ }
1497
+ return [3 /*break*/, 6];
1498
+ case 6: return [3 /*break*/, 2];
1499
+ case 7: return [2 /*return*/];
1500
+ }
1501
+ });
1502
+ }); };
1503
+ //#endregion
1504
+ //#region confirm
1505
+ UtilsTerminal.confirm = function (options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1506
+ var defaultValue, message,
1507
+ // mustAnswerQuestion,
1508
+ callbackFalse, callbackTrue, response, inquirerToggle, answer, confirm_1, answer, prompts, Select, choices, prompt_1;
1509
+ var _a;
1510
+ return tslib_1.__generator(this, function (_b) {
1511
+ switch (_b.label) {
1512
+ case 0:
1513
+ //#region @backendFunc
1514
+ options = options || {};
1515
+ options.defaultValue = core_imports_1._.isBoolean(options.defaultValue)
1516
+ ? options.defaultValue
1517
+ : true;
1518
+ options.message = options.message || 'Are you sure?';
1519
+ options.engine = options.engine || 'inquirer-toggle';
1520
+ defaultValue = options.defaultValue, message = options.message, callbackFalse = options.callbackFalse, callbackTrue = options.callbackTrue;
1521
+ response = {
1522
+ value: defaultValue,
1523
+ };
1524
+ if (!global.tnpNonInteractive) return [3 /*break*/, 1];
1525
+ index_1.Helpers.info("".concat(message, " - AUTORESPONSE: ").concat(defaultValue ? 'YES' : 'NO'));
1526
+ return [3 /*break*/, 11];
1527
+ case 1:
1528
+ if (!(options.engine === 'inquirer-toggle')) return [3 /*break*/, 4];
1529
+ return [4 /*yield*/, Promise.resolve().then(function () { return require('inquirer-toggle'); })];
1530
+ case 2:
1531
+ inquirerToggle = (_b.sent()).default;
1532
+ return [4 /*yield*/, inquirerToggle({
1533
+ message: message,
1534
+ default: defaultValue,
1535
+ theme: {
1536
+ style: {
1537
+ highlight: core_imports_1.chalk.bold.cyan.underline,
1538
+ },
1539
+ },
1540
+ })];
1541
+ case 3:
1542
+ answer = _b.sent();
1543
+ response = {
1544
+ value: answer,
1545
+ };
1546
+ return [3 /*break*/, 11];
1547
+ case 4:
1548
+ if (!(options.engine === '@inquirer/prompts')) return [3 /*break*/, 7];
1549
+ return [4 /*yield*/, Promise.resolve().then(function () { return require('@inquirer/prompts'); })];
1550
+ case 5:
1551
+ confirm_1 = (_b.sent()).confirm;
1552
+ return [4 /*yield*/, confirm_1({
1553
+ message: message,
1554
+ default: defaultValue,
1555
+ })];
1556
+ case 6:
1557
+ answer = _b.sent();
1558
+ response = {
1559
+ value: answer,
1560
+ };
1561
+ return [3 /*break*/, 11];
1562
+ case 7:
1563
+ if (!(options.engine === 'prompts')) return [3 /*break*/, 9];
1564
+ prompts = require('prompts');
1565
+ return [4 /*yield*/, prompts({
1566
+ type: 'toggle',
1567
+ name: 'value',
1568
+ message: message,
1569
+ initial: defaultValue,
1570
+ active: 'yes',
1571
+ inactive: 'no',
1572
+ })];
1573
+ case 8:
1574
+ response = _b.sent();
1575
+ return [3 /*break*/, 11];
1576
+ case 9:
1577
+ if (!(options.engine === 'enquirer')) return [3 /*break*/, 11];
1578
+ Select = require('enquirer').Select;
1579
+ choices = defaultValue ? ['yes', 'no'] : ['no', 'yes'];
1580
+ prompt_1 = new Select({
1581
+ name: 'question',
1582
+ message: message,
1583
+ choices: choices,
1584
+ });
1585
+ _a = {};
1586
+ return [4 /*yield*/, prompt_1.run()];
1587
+ case 10:
1588
+ response = (_a.value = (_b.sent()) === 'yes',
1589
+ _a);
1590
+ _b.label = 11;
1591
+ case 11:
1592
+ if (!response.value) return [3 /*break*/, 14];
1593
+ if (!callbackTrue) return [3 /*break*/, 13];
1594
+ return [4 /*yield*/, index_1.Helpers.runSyncOrAsync({ functionFn: callbackTrue })];
1595
+ case 12:
1596
+ _b.sent();
1597
+ _b.label = 13;
1598
+ case 13: return [3 /*break*/, 16];
1599
+ case 14:
1600
+ if (!callbackFalse) return [3 /*break*/, 16];
1601
+ return [4 /*yield*/, index_1.Helpers.runSyncOrAsync({ functionFn: callbackFalse })];
1602
+ case 15:
1603
+ _b.sent();
1604
+ _b.label = 16;
1605
+ case 16: return [2 /*return*/, response.value];
1606
+ }
1607
+ });
1608
+ }); };
1609
+ //#endregion
1610
+ //#region press any key to continue
1611
+ UtilsTerminal.pressAnyKeyToContinueAsync = function (options) {
1612
+ //#region @backendFunc
1613
+ options = options || {};
1614
+ options.message =
1615
+ options.message || core_imports_1.chalk.bold('Press any key to continue...');
1616
+ var message = options.message;
1617
+ var readline = require('readline');
1618
+ return new Promise(function (resolve) {
1619
+ var rl = readline.createInterface({
1620
+ input: process.stdin,
1621
+ output: process.stdout,
1622
+ });
1623
+ // Prompt user with the question
1624
+ rl.question(message, function (answer) {
1625
+ rl.close();
1626
+ resolve(answer);
1627
+ });
1628
+ });
1629
+ //#endregion
1630
+ };
1631
+ //#endregion
1632
+ //#region press any key
1633
+ /**
1634
+ * @deprecated use UtilsTerminal.pressAnyKeyToContinueAsync()
1635
+ */
1636
+ UtilsTerminal.pressAnyKey = function (options) {
1637
+ //#region @backendFunc
1638
+ options = options || {};
1639
+ options.message = options.message || 'Press any key to continue...';
1640
+ var message = options.message;
1641
+ if (process.platform === 'win32') {
1642
+ var terminal = UtilsProcess.getBashOrShellName();
1643
+ // console.log({ terminal });
1644
+ if (terminal === 'gitbash') {
1645
+ var getGitBashPath = UtilsProcess.getGitBashPath();
1646
+ // console.log({ getGitBashPath });
1647
+ var gitbashCommand = "read -p \"".concat(core_imports_1.chalk.bold(message), "\"");
1648
+ core_imports_3.child_process.execSync(gitbashCommand, {
1649
+ stdio: 'inherit',
1650
+ shell: getGitBashPath,
1651
+ });
1652
+ }
1653
+ else {
1654
+ console.log(core_imports_1.chalk.bold(message));
1655
+ core_imports_3.spawn.sync('pause', '', { shell: true, stdio: [0, 1, 2] });
1656
+ }
1657
+ return;
1658
+ }
1659
+ console.log(core_imports_1.chalk.bold(message));
1660
+ require('child_process').spawnSync('read _ ', {
1661
+ shell: true,
1662
+ stdio: [0, 1, 2],
1663
+ });
1664
+ //#endregion
1665
+ };
1666
+ //#endregion
1667
+ //#region preview long list as select
1668
+ UtilsTerminal.previewLongList = function (list_1) {
1669
+ var args_1 = [];
1670
+ for (var _i = 1; _i < arguments.length; _i++) {
1671
+ args_1[_i - 1] = arguments[_i];
1672
+ }
1673
+ return tslib_1.__awaiter(_this, tslib_1.__spreadArray([list_1], tslib_1.__read(args_1), false), void 0, function (list, listName) {
1674
+ var choices;
1675
+ if (listName === void 0) { listName = 'List'; }
1676
+ return tslib_1.__generator(this, function (_a) {
1677
+ switch (_a.label) {
1678
+ case 0:
1679
+ //#region @backendFunc
1680
+ if (!Array.isArray(list)) {
1681
+ list = list.split('\n');
1682
+ }
1683
+ choices = list.reduce(function (a, b) {
1684
+ var _a;
1685
+ return core_imports_1._.merge(a, (_a = {},
1686
+ _a[b] = {
1687
+ name: b,
1688
+ // action: () => {},
1689
+ },
1690
+ _a));
1691
+ }, {});
1692
+ return [4 /*yield*/, UtilsTerminal.selectActionAndExecute(choices, {
1693
+ autocomplete: true,
1694
+ question: listName,
1695
+ hint: 'Press enter to return',
1696
+ })];
1697
+ case 1:
1698
+ _a.sent();
1699
+ return [2 /*return*/];
1700
+ }
1701
+ });
1702
+ });
1703
+ };
1704
+ //#endregion
1705
+ //#region preview long list with 'less' (git log like)
1706
+ /**
1707
+ * Displays a long list in the console using a pager like `less`.
1708
+ * Returns a Promise that resolves when the user exits the pager.
1709
+ *
1710
+ * @param {string} list - The long string content to display.
1711
+ * @returns {Promise<void>} A Promise that resolves when the pager exits.
1712
+ */
1713
+ UtilsTerminal.previewLongListGitLogLike = function (list) {
1714
+ //#region @backendFunc
1715
+ if (Array.isArray(list)) {
1716
+ list = list.join('\n');
1717
+ }
1718
+ return new Promise(function (resolve, reject) {
1719
+ var less = (0, core_imports_3.spawn)('less', [], {
1720
+ stdio: ['pipe', process.stdout, process.stderr],
1721
+ });
1722
+ less.stdin.write(list); // Write the list content to the less process
1723
+ less.stdin.end(); // Signal that writing is complete
1724
+ less.on('close', function (code) {
1725
+ if (code === 0) {
1726
+ resolve(void 0);
1727
+ }
1728
+ else {
1729
+ reject(new Error("less process exited with code ".concat(code)));
1730
+ }
1731
+ });
1732
+ less.on('error', function (err) {
1733
+ reject(err);
1734
+ });
1735
+ });
1736
+ //#endregion
1737
+ };
1738
+ //#endregion
1739
+ })(UtilsTerminal || (exports.UtilsTerminal = UtilsTerminal = {}));
1740
+ //#endregion
1162
1741
  //# sourceMappingURL=utils.js.map