hopwire 0.4.0 → 0.5.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/terminal.js CHANGED
@@ -35,13 +35,37 @@ export function terminalLook(env) {
35
35
  return {
36
36
  truecolor: /^(truecolor|24bit)$/i.test(env.COLORTERM ?? ''),
37
37
  palette: background === 7 || background === 15 ? LIGHT : DARK,
38
- // The Linux console prints the escape as text
39
- links: env.TERM !== 'linux',
38
+ links: supportsHyperlinks(env),
40
39
  };
41
40
  }
41
+ /**
42
+ * Whether the terminal turns OSC 8 into a link. Only terminals known to do it get the escape; the others show the URL
43
+ * as text, which they find by themselves (Cmd+click in Apple Terminal). FORCE_HYPERLINK=1 or 0 overrides, as other
44
+ * command line tools read it.
45
+ */
46
+ export function supportsHyperlinks(env) {
47
+ if (env.FORCE_HYPERLINK !== undefined && env.FORCE_HYPERLINK !== '') {
48
+ return env.FORCE_HYPERLINK !== '0' && env.FORCE_HYPERLINK.toLowerCase() !== 'false';
49
+ }
50
+ // Inside tmux or screen the escape only passes when they are set up for it
51
+ if (env.TMUX !== undefined || /^(screen|tmux)/.test(env.TERM ?? '')) {
52
+ return false;
53
+ }
54
+ if (['iTerm.app', 'WezTerm', 'vscode', 'ghostty', 'Hyper', 'WarpTerminal'].includes(env.TERM_PROGRAM ?? '')) {
55
+ return true;
56
+ }
57
+ if (env.KITTY_WINDOW_ID !== undefined || env.WT_SESSION !== undefined || env.DOMTERM !== undefined) {
58
+ return true;
59
+ }
60
+ if (/^(xterm-kitty|xterm-ghostty|alacritty|foot)/.test(env.TERM ?? '')) {
61
+ return true;
62
+ }
63
+ // GNOME Terminal and the other VTE terminals since 0.50
64
+ return Number(env.VTE_VERSION ?? '0') >= 5000;
65
+ }
42
66
  const RESET = '\u001b[0m';
43
67
  /** Text in a colour, optionally bold. */
44
- function paint(look, text, tone, bold = false) {
68
+ export function paint(look, text, tone, bold = false) {
45
69
  if (text === '') {
46
70
  return '';
47
71
  }
@@ -139,6 +163,10 @@ export class TerminalScreen {
139
163
  return ofService === undefined || ofService.length === 0 ? null : checkSignature(exchange, ofService);
140
164
  };
141
165
  }
166
+ /** The signature check of a webhook row; null without a secret for its service or for a request that is none. */
167
+ signatureOf(exchange) {
168
+ return recogniseWebhook(exchange) === null ? null : this.verify(exchange);
169
+ }
142
170
  get look() {
143
171
  return this.options.look;
144
172
  }
@@ -473,7 +501,7 @@ export function sparkline(counts) {
473
501
  '')
474
502
  .join('');
475
503
  }
476
- const SOURCE_WORDS = {
504
+ export const SOURCE_WORDS = {
477
505
  local: 'local',
478
506
  p2p_peer: 'from a teammate',
479
507
  public_edge: 'through the edge',
@@ -483,7 +511,7 @@ const SOURCE_WORDS = {
483
511
  const DETAIL_HEADERS = 14;
484
512
  const DETAIL_BODY_LINES = 24;
485
513
  /** Headers whose values are credentials: shown shortened in the details block. */
486
- const CREDENTIAL_HEADERS = new Set([
514
+ export const CREDENTIAL_HEADERS = new Set([
487
515
  'authorization',
488
516
  'proxy-authorization',
489
517
  'cookie',
@@ -492,7 +520,7 @@ const CREDENTIAL_HEADERS = new Set([
492
520
  'api-key',
493
521
  ]);
494
522
  /** The first characters of a secret, enough to tell two apart. */
495
- function hidden(value) {
523
+ export function hidden(value) {
496
524
  return value.length <= 8 ? '••••' : `${value.slice(0, 6)}… (${value.length} characters)`;
497
525
  }
498
526
  /**
@@ -516,7 +544,7 @@ export function bodyLines(body, truncated) {
516
544
  return text.split(/\r?\n/);
517
545
  }
518
546
  /** The mark of a signature check in a row and in the details. */
519
- function signatureMark(check, palette) {
547
+ export function signatureMark(check, palette) {
520
548
  switch (check.result) {
521
549
  case 'valid':
522
550
  return check.ageMs !== null && check.ageMs > TOLERANCE_MS
@@ -545,7 +573,7 @@ export function signatureSentence(check) {
545
573
  }
546
574
  }
547
575
  /** The time of day as HH:MM:SS on this machine's clock. */
548
- function clock(timestamp) {
576
+ export function clock(timestamp) {
549
577
  const date = new Date(timestamp);
550
578
  return [date.getHours(), date.getMinutes(), date.getSeconds()]
551
579
  .map((part) => String(part).padStart(2, '0'))
@@ -600,7 +628,7 @@ function sourceTag(exchange, look) {
600
628
  return `${paint(look, 'local', palette.muted)}${ws}`;
601
629
  }
602
630
  }
603
- function statusTone(palette, status) {
631
+ export function statusTone(palette, status) {
604
632
  if (status >= 500) {
605
633
  return palette.err;
606
634
  }