hopwire 0.7.0 → 0.8.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/dist/cli.js +44 -11
- package/dist/commands/http.js +1 -1
- package/dist/inspector/THIRD-PARTY-NOTICES.txt +4 -4
- package/dist/inspector/assets/index-TosvUM6Z.js +5 -0
- package/dist/inspector/index.html +1 -1
- package/dist/settings.js +447 -122
- package/dist/tui/app.js +158 -34
- package/dist/tui/settings.js +253 -102
- package/package.json +1 -1
- package/dist/inspector/assets/index-CdyIIKdA.js +0 -5
package/dist/tui/app.js
CHANGED
|
@@ -7,8 +7,8 @@ import { parseInput } from './input.js';
|
|
|
7
7
|
import { Traffic } from './model.js';
|
|
8
8
|
import { menuItems, requestsLines } from './requests.js';
|
|
9
9
|
import { TAB_KEYS, listWindow, sectionsOf, tabsOf, target, } from './state.js';
|
|
10
|
-
import { settingValue, unavailable, withSetting } from '../settings.js';
|
|
11
|
-
import {
|
|
10
|
+
import { invalidAuth, invalidValue, isOn, settingKind, settingValue, unavailable, withSetting, } from '../settings.js';
|
|
11
|
+
import { boxChoices, boxFields, settingName, settingRows, settingsLines, shownValue, } from './settings.js';
|
|
12
12
|
import { helpContent, scrolled, shareItems, shareLines, statusContent, tools, toolsLines } from './tabs.js';
|
|
13
13
|
/** Rows of the window that are not the tab: two of the header, two rules, two of the footer. */
|
|
14
14
|
const CHROME_ROWS = 6;
|
|
@@ -46,6 +46,7 @@ export class App {
|
|
|
46
46
|
atStart: options.settings.current,
|
|
47
47
|
history: [],
|
|
48
48
|
cursor: 0,
|
|
49
|
+
top: 0,
|
|
49
50
|
problem: null,
|
|
50
51
|
box: null,
|
|
51
52
|
},
|
|
@@ -314,10 +315,15 @@ export class App {
|
|
|
314
315
|
this.settingsKey('enter');
|
|
315
316
|
}
|
|
316
317
|
break;
|
|
318
|
+
case 'field':
|
|
319
|
+
if (state.settings?.box != null) {
|
|
320
|
+
state.settings.box.focus = Number(value);
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
317
323
|
case 'choice':
|
|
318
324
|
if (state.settings?.box != null) {
|
|
319
|
-
state.settings.box.
|
|
320
|
-
this.
|
|
325
|
+
state.settings.box.focus = state.settings.box.fields.length + Number(value);
|
|
326
|
+
this.boxKey('enter');
|
|
321
327
|
}
|
|
322
328
|
break;
|
|
323
329
|
default:
|
|
@@ -365,12 +371,13 @@ export class App {
|
|
|
365
371
|
this.menuKey(key);
|
|
366
372
|
return;
|
|
367
373
|
}
|
|
368
|
-
|
|
369
|
-
|
|
374
|
+
// A box of the Settings tab takes every key: what is typed into it is text, not a key of the view
|
|
375
|
+
if (state.tab === 'settings' && state.settings?.box != null) {
|
|
376
|
+
this.boxKey(key);
|
|
370
377
|
return;
|
|
371
378
|
}
|
|
372
|
-
if (
|
|
373
|
-
this.
|
|
379
|
+
if (key === 'q') {
|
|
380
|
+
this.quit();
|
|
374
381
|
return;
|
|
375
382
|
}
|
|
376
383
|
const tabs = tabsOf(state);
|
|
@@ -411,35 +418,14 @@ export class App {
|
|
|
411
418
|
break;
|
|
412
419
|
}
|
|
413
420
|
}
|
|
414
|
-
/** Keys of the Settings tab
|
|
421
|
+
/** Keys of the Settings tab while no box is open. */
|
|
415
422
|
settingsKey(key) {
|
|
416
423
|
const view = this.state.settings;
|
|
417
424
|
if (view === null) {
|
|
418
425
|
return;
|
|
419
426
|
}
|
|
420
427
|
const settings = view.access.current;
|
|
421
|
-
const rows = settingRows(
|
|
422
|
-
if (view.box !== null) {
|
|
423
|
-
const { box } = view;
|
|
424
|
-
const on = !settingValue(settings, box.id);
|
|
425
|
-
const choices = changeChoices(view.access, on);
|
|
426
|
-
if (key === 'up') {
|
|
427
|
-
box.choice = Math.max(box.choice - 1, 0);
|
|
428
|
-
}
|
|
429
|
-
else if (key === 'down') {
|
|
430
|
-
box.choice = Math.min(box.choice + 1, choices.length - 1);
|
|
431
|
-
}
|
|
432
|
-
else if (key === 'esc' || key === 'q') {
|
|
433
|
-
view.box = null;
|
|
434
|
-
}
|
|
435
|
-
else if (key === 'enter') {
|
|
436
|
-
view.box = null;
|
|
437
|
-
if (box.choice < 2) {
|
|
438
|
-
this.change(withSetting(settings, box.id, on), box.choice === 1, `${settingName(settings, box.id)}: ${on ? 'on' : 'off'}`);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
428
|
+
const rows = settingRows(view.access);
|
|
443
429
|
const row = rows[view.cursor];
|
|
444
430
|
if (key === 'up') {
|
|
445
431
|
view.cursor = Math.max(view.cursor - 1, 0);
|
|
@@ -447,16 +433,23 @@ export class App {
|
|
|
447
433
|
else if (key === 'down') {
|
|
448
434
|
view.cursor = Math.min(view.cursor + 1, rows.length - 1);
|
|
449
435
|
}
|
|
436
|
+
else if (key === 'pageup' || key === 'home') {
|
|
437
|
+
view.cursor = key === 'home' ? 0 : Math.max(view.cursor - 5, 0);
|
|
438
|
+
}
|
|
439
|
+
else if (key === 'pagedown' || key === 'end') {
|
|
440
|
+
view.cursor = key === 'end' ? rows.length - 1 : Math.min(view.cursor + 5, rows.length - 1);
|
|
441
|
+
}
|
|
450
442
|
else if ((key === 'enter' || key === 'space') && row !== undefined) {
|
|
451
|
-
|
|
443
|
+
// What is on can always be turned off; what needs something else says so
|
|
444
|
+
const reason = isOn(settings, row.id) ? null : unavailable(settings, row.id);
|
|
452
445
|
if (this.state.restarting) {
|
|
453
446
|
this.flash('The tunnel is restarting; one change at a time.', true, false);
|
|
454
447
|
}
|
|
455
448
|
else if (reason !== null) {
|
|
456
|
-
this.flash(`${row.label.trim()} ${reason}.`, true, false);
|
|
449
|
+
this.flash(`${row.label.trim()}: ${reason}.`, true, false);
|
|
457
450
|
}
|
|
458
451
|
else {
|
|
459
|
-
|
|
452
|
+
this.openBox(row.id);
|
|
460
453
|
}
|
|
461
454
|
}
|
|
462
455
|
else if (key === 's') {
|
|
@@ -472,6 +465,137 @@ export class App {
|
|
|
472
465
|
}
|
|
473
466
|
}
|
|
474
467
|
}
|
|
468
|
+
openBox(id) {
|
|
469
|
+
const view = this.state.settings;
|
|
470
|
+
if (view === null) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const box = {
|
|
474
|
+
id,
|
|
475
|
+
fields: boxFields(view.access.current, id),
|
|
476
|
+
focus: 0,
|
|
477
|
+
problem: null,
|
|
478
|
+
note: null,
|
|
479
|
+
};
|
|
480
|
+
view.box = box;
|
|
481
|
+
if (settingKind(id) === 'auth') {
|
|
482
|
+
// A saved password stands in the file as text: whether Git would take the file along is said here
|
|
483
|
+
const { shown } = view.access.file;
|
|
484
|
+
void view.access.ignored().then((ignored) => {
|
|
485
|
+
box.note =
|
|
486
|
+
ignored === false
|
|
487
|
+
? `Saved, the password stands in ${shown} as text, and Git does not ignore ${shown} here: it would be committed with it.`
|
|
488
|
+
: `Saved, the password stands in ${shown} as text${ignored === true ? '; Git ignores that file here' : ''}.`;
|
|
489
|
+
this.invalidate();
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/** Keys while a box of the Settings tab is open: typing into its fields, moving, choosing. */
|
|
494
|
+
boxKey(key) {
|
|
495
|
+
const view = this.state.settings;
|
|
496
|
+
const box = view?.box;
|
|
497
|
+
if (view == null || box == null) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const choices = boxChoices(view.access, box.id);
|
|
501
|
+
const last = box.fields.length + choices.length - 1;
|
|
502
|
+
const field = box.fields[box.focus];
|
|
503
|
+
if (key === 'esc') {
|
|
504
|
+
view.box = null;
|
|
505
|
+
}
|
|
506
|
+
else if (key === 'up' || key === 'shift-tab') {
|
|
507
|
+
box.focus = Math.max(box.focus - 1, 0);
|
|
508
|
+
}
|
|
509
|
+
else if (key === 'down' || key === 'tab') {
|
|
510
|
+
box.focus = Math.min(box.focus + 1, last);
|
|
511
|
+
}
|
|
512
|
+
else if (field !== undefined) {
|
|
513
|
+
// In a field: what is typed is its text, q and the digits included
|
|
514
|
+
if (key === 'enter') {
|
|
515
|
+
box.focus += 1;
|
|
516
|
+
}
|
|
517
|
+
else if (key === 'backspace') {
|
|
518
|
+
field.value = [...field.value].slice(0, -1).join('');
|
|
519
|
+
box.problem = null;
|
|
520
|
+
}
|
|
521
|
+
else if (key === 'space') {
|
|
522
|
+
field.value += ' ';
|
|
523
|
+
}
|
|
524
|
+
else if ([...key].length === 1) {
|
|
525
|
+
field.value += key;
|
|
526
|
+
box.problem = null;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else if (key === 'enter') {
|
|
530
|
+
const choice = choices[box.focus - box.fields.length];
|
|
531
|
+
if (choice !== undefined) {
|
|
532
|
+
this.choose(choice);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
else if (key === 'q') {
|
|
536
|
+
view.box = null;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/** Takes a choice of the box: checks what was typed, then changes the setting. */
|
|
540
|
+
choose(choice) {
|
|
541
|
+
const view = this.state.settings;
|
|
542
|
+
const box = view?.box;
|
|
543
|
+
if (view == null || box == null) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const { id } = box;
|
|
547
|
+
const settings = view.access.current;
|
|
548
|
+
if (choice.action === 'cancel') {
|
|
549
|
+
view.box = null;
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const kind = settingKind(id);
|
|
553
|
+
const typed = (box.fields[0]?.value ?? '').trim();
|
|
554
|
+
let next;
|
|
555
|
+
if (kind === 'switch') {
|
|
556
|
+
next = withSetting(settings, id, !isOn(settings, id));
|
|
557
|
+
}
|
|
558
|
+
else if (choice.action === 'off') {
|
|
559
|
+
next = withSetting(settings, id, null);
|
|
560
|
+
}
|
|
561
|
+
else if (kind === 'list') {
|
|
562
|
+
const list = settingValue(settings, id);
|
|
563
|
+
const entries = Array.isArray(list) ? list : [];
|
|
564
|
+
if (choice.action === 'remove') {
|
|
565
|
+
next = withSetting(settings, id, entries.filter((_, index) => index !== choice.remove));
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
box.problem = invalidValue(settings, id, typed);
|
|
569
|
+
if (box.problem !== null) {
|
|
570
|
+
box.focus = 0;
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
next = withSetting(settings, id, [...entries, typed]);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
else if (kind === 'auth') {
|
|
577
|
+
const user = typed;
|
|
578
|
+
const password = box.fields[1]?.value ?? '';
|
|
579
|
+
box.problem = invalidAuth(user, password);
|
|
580
|
+
if (box.problem !== null) {
|
|
581
|
+
box.focus = user === '' ? 0 : 1;
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
next = withSetting(settings, id, `${user}:${password}`);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
box.problem = invalidValue(settings, id, typed);
|
|
588
|
+
if (box.problem !== null) {
|
|
589
|
+
box.focus = 0;
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
next = withSetting(settings, id, typed);
|
|
593
|
+
}
|
|
594
|
+
const name = settingName(view.access, id);
|
|
595
|
+
view.box = null;
|
|
596
|
+
// The line about it never holds a password: shownValue names the user only
|
|
597
|
+
this.change(next, choice.save, `${name}: ${shownValue(next, id)}`);
|
|
598
|
+
}
|
|
475
599
|
/** Restarts the tunnel with changed settings, and saves them when asked. */
|
|
476
600
|
change(next, save, done, remember = true, forRun = true) {
|
|
477
601
|
const { state } = this;
|