pear-terminal 1.1.4 → 1.2.1
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 +39 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
|
|
3
2
|
const readline = require('bare-readline')
|
|
4
3
|
const tty = require('bare-tty')
|
|
5
4
|
const fs = require('bare-fs')
|
|
@@ -277,7 +276,13 @@ function indicator(value, type = 'success') {
|
|
|
277
276
|
if (type === 'diff') {
|
|
278
277
|
return value === 0 ? ansi.yellow('~') : value === 1 ? ansi.green('+') : ansi.red('-')
|
|
279
278
|
}
|
|
280
|
-
return value < 0
|
|
279
|
+
return value < 0
|
|
280
|
+
? ansi.cross + ' '
|
|
281
|
+
: value === 1
|
|
282
|
+
? ansi.tick + ' '
|
|
283
|
+
: value > 1
|
|
284
|
+
? ''
|
|
285
|
+
: ansi.gray('- ')
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
const outputter =
|
|
@@ -412,7 +417,7 @@ async function trust(ipc, key, cmd) {
|
|
|
412
417
|
Bare.exit()
|
|
413
418
|
}
|
|
414
419
|
|
|
415
|
-
async function
|
|
420
|
+
async function passperm(ipc, key, cmd) {
|
|
416
421
|
const z32 = hypercoreid.normalize(key)
|
|
417
422
|
|
|
418
423
|
const explain = {
|
|
@@ -467,7 +472,7 @@ async function password(ipc, key, cmd) {
|
|
|
467
472
|
function permit(ipc, info, cmd) {
|
|
468
473
|
const key = info.key
|
|
469
474
|
if (info.encrypted) {
|
|
470
|
-
return
|
|
475
|
+
return passperm(ipc, key, cmd)
|
|
471
476
|
} else {
|
|
472
477
|
return trust(ipc, key, cmd)
|
|
473
478
|
}
|
|
@@ -500,7 +505,7 @@ function explain(bail = {}) {
|
|
|
500
505
|
Bare.exit(1)
|
|
501
506
|
}
|
|
502
507
|
}
|
|
503
|
-
const messageUsage = (bail) => bail.err.message
|
|
508
|
+
const messageUsage = (bail) => bail.err.info?.message ?? bail.err.message
|
|
504
509
|
const messageOnly = (bail) => bail.err.message
|
|
505
510
|
const opFail = (cmd) => cmd.err.info.message
|
|
506
511
|
const codemap = new Map([
|
|
@@ -512,13 +517,14 @@ function explain(bail = {}) {
|
|
|
512
517
|
['MISSING_ARG', (bail) => bail.arg.value],
|
|
513
518
|
['INVALID', messageUsage],
|
|
514
519
|
['ERR_INVALID_INPUT', messageUsage],
|
|
520
|
+
['ERR_INVALID_CONFIG', messageUsage],
|
|
515
521
|
['ERR_LEGACY', messageOnly],
|
|
516
522
|
['ERR_INVALID_TEMPLATE', messageOnly],
|
|
517
523
|
['ERR_DIR_NONEMPTY', messageOnly],
|
|
518
524
|
['ERR_OPERATION_FAILED', opFail]
|
|
519
525
|
])
|
|
520
526
|
const nouse = [messageOnly, opFail]
|
|
521
|
-
const code = codemap.has(bail.err?.code) ? bail.err.code : bail.reason
|
|
527
|
+
const code = bail?.err?.info?.code ?? (codemap.has(bail.err?.code) ? bail.err.code : bail.reason)
|
|
522
528
|
const ref = codemap.get(code)
|
|
523
529
|
const reason = codemap.has(code) ? (codemap.get(code)(bail) ?? bail.reason) : bail.reason
|
|
524
530
|
Bare.exitCode = 1
|
|
@@ -530,9 +536,36 @@ function explain(bail = {}) {
|
|
|
530
536
|
print('\n' + bail.command.usage())
|
|
531
537
|
}
|
|
532
538
|
|
|
539
|
+
function password(prompt = 'Password: ') {
|
|
540
|
+
return new Promise((resolve) => {
|
|
541
|
+
const stdin = new tty.ReadStream(0)
|
|
542
|
+
const stdout = new tty.WriteStream(1)
|
|
543
|
+
let str = ''
|
|
544
|
+
|
|
545
|
+
stdin.setRawMode(true)
|
|
546
|
+
stdout.write(prompt)
|
|
547
|
+
|
|
548
|
+
stdin.on('data', (chunk) => {
|
|
549
|
+
const c = chunk[0]
|
|
550
|
+
if (c === 3) {
|
|
551
|
+
stdout.write('^C\n')
|
|
552
|
+
process.exit(130)
|
|
553
|
+
} else if (c === 13 || c === 10) {
|
|
554
|
+
stdin.setRawMode(false)
|
|
555
|
+
stdin.destroy()
|
|
556
|
+
stdout.write('\n')
|
|
557
|
+
return resolve(str)
|
|
558
|
+
} else if (c === 127 || c < 32) return
|
|
559
|
+
str += String.fromCharCode(c)
|
|
560
|
+
stdout.write('*')
|
|
561
|
+
})
|
|
562
|
+
})
|
|
563
|
+
}
|
|
564
|
+
|
|
533
565
|
module.exports = {
|
|
534
566
|
explain,
|
|
535
567
|
usage,
|
|
568
|
+
password,
|
|
536
569
|
permit,
|
|
537
570
|
stdio,
|
|
538
571
|
ansi,
|