pear-terminal 1.1.3 → 1.2.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 +36 -4
- 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
|
}
|
|
@@ -530,9 +535,36 @@ function explain(bail = {}) {
|
|
|
530
535
|
print('\n' + bail.command.usage())
|
|
531
536
|
}
|
|
532
537
|
|
|
538
|
+
function password(prompt = 'Password: ') {
|
|
539
|
+
return new Promise((resolve) => {
|
|
540
|
+
const stdin = new tty.ReadStream(0)
|
|
541
|
+
const stdout = new tty.WriteStream(1)
|
|
542
|
+
let str = ''
|
|
543
|
+
|
|
544
|
+
stdin.setRawMode(true)
|
|
545
|
+
stdout.write(prompt)
|
|
546
|
+
|
|
547
|
+
stdin.on('data', (chunk) => {
|
|
548
|
+
const c = chunk[0]
|
|
549
|
+
if (c === 3) {
|
|
550
|
+
stdout.write('^C\n')
|
|
551
|
+
process.exit(130)
|
|
552
|
+
} else if (c === 13 || c === 10) {
|
|
553
|
+
stdin.setRawMode(false)
|
|
554
|
+
stdin.destroy()
|
|
555
|
+
stdout.write('\n')
|
|
556
|
+
return resolve(str)
|
|
557
|
+
} else if (c === 127 || c < 32) return
|
|
558
|
+
str += String.fromCharCode(c)
|
|
559
|
+
stdout.write('*')
|
|
560
|
+
})
|
|
561
|
+
})
|
|
562
|
+
}
|
|
563
|
+
|
|
533
564
|
module.exports = {
|
|
534
565
|
explain,
|
|
535
566
|
usage,
|
|
567
|
+
password,
|
|
536
568
|
permit,
|
|
537
569
|
stdio,
|
|
538
570
|
ansi,
|