@lethevimlet/sshift 1.7.0 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -49,7 +49,7 @@ class SSHIFTClient {
49
49
  this.sftpClipboard = null; // For cut/copy/paste: { action: 'cut'|'copy', path: string, name: string, sessionId: string }
50
50
  this.terminalClipboardContent = null; // Pre-read clipboard content for context menu paste
51
51
  this.osc52Buffer = null; // Buffered OSC 52 clipboard content pending write
52
- this.terminalColorOverride = true; // Default to true, will be loaded in initThemeAndAccent
52
+ this.terminalColorOverride = false; // Default OFF — loaded per theme in initThemeAndAccent
53
53
  this.terminalBgColor = '#0d1117';
54
54
  this.terminalFgColor = '#e6edf3';
55
55
  this.terminalSelectionColor = '#264f78';
@@ -1658,13 +1658,20 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1658
1658
  return defaultTheme;
1659
1659
  }
1660
1660
 
1661
- // When override is enabled, use custom colors from settings
1661
+ // When override is enabled, use custom colors from settings.
1662
+ // Sanitize each color: a corrupt value (e.g. the literal string
1663
+ // "undefined" persisted by old buggy saves) is truthy, so a plain
1664
+ // `value || default` passes it straight to xterm.js — which renders
1665
+ // unparseable colors as #000000 (black-on-black = "override broken").
1666
+ const bg = this._sanitizeHexColor(this.terminalBgColor, '#0d1117');
1667
+ const fg = this._sanitizeHexColor(this.terminalFgColor, '#e6edf3');
1668
+ const sel = this._sanitizeHexColor(this.terminalSelectionColor, '#264f78');
1662
1669
  const customTheme = {
1663
- background: this.terminalBgColor || '#0d1117',
1664
- foreground: this.terminalFgColor || '#e6edf3',
1670
+ background: bg,
1671
+ foreground: fg,
1665
1672
  cursor: '#c10059',
1666
- cursorAccent: this.terminalBgColor || '#0d1117',
1667
- selectionBackground: this.hexToRgba(this.terminalSelectionColor || '#264f78', 0.5),
1673
+ cursorAccent: bg,
1674
+ selectionBackground: this.hexToRgba(sel, 0.5),
1668
1675
  black: isDark ? '#484f58' : '#6e7681',
1669
1676
  red: '#f85149',
1670
1677
  green: '#3fb950',
@@ -4437,6 +4444,12 @@ const wheelHandler = (e) => {
4437
4444
  this.theme = data.theme;
4438
4445
  this.saveTheme(data.theme);
4439
4446
  this.updateThemeIcon(data.theme);
4447
+ // Terminal color settings are stored PER THEME — load the new
4448
+ // theme's set before repainting, otherwise the previous theme's
4449
+ // override/colors leak into this theme (and a later save would
4450
+ // persist them under the wrong key).
4451
+ this.loadTerminalColorSettings();
4452
+ this.updateTerminalColorOverrideUI();
4440
4453
  this.updateTerminalThemes(data.theme);
4441
4454
  }
4442
4455
  }
@@ -4581,6 +4594,11 @@ const wheelHandler = (e) => {
4581
4594
  this.theme = data.theme;
4582
4595
  this.saveTheme(data.theme);
4583
4596
  this.updateThemeIcon(data.theme);
4597
+ // Load the new theme's per-theme terminal color settings before
4598
+ // repainting (mirrors toggleTheme) so override/colors don't leak
4599
+ // between themes.
4600
+ this.loadTerminalColorSettings();
4601
+ this.updateTerminalColorOverrideUI();
4584
4602
  this.updateTerminalThemes(data.theme);
4585
4603
  }
4586
4604
  });
@@ -7484,46 +7502,84 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
7484
7502
  }
7485
7503
  }
7486
7504
 
7487
- saveTerminalColorSettings() {
7488
- // Save settings for current theme
7489
- const themeKey = this.theme; // 'dark' or 'light'
7490
- localStorage.setItem(`terminalColorOverride_${themeKey}`, this.terminalColorOverride);
7491
- localStorage.setItem(`terminalBgColor_${themeKey}`, this.terminalBgColor);
7492
- localStorage.setItem(`terminalFgColor_${themeKey}`, this.terminalFgColor);
7493
- localStorage.setItem(`terminalSelectionColor_${themeKey}`, this.terminalSelectionColor);
7505
+ // Validate a persisted color value. Historically, saves could run while
7506
+ // the color properties (or this.theme) were still undefined, writing the
7507
+ // literal string "undefined" into localStorage. Such garbage is truthy,
7508
+ // so it survived `value || default` fallbacks and reached xterm.js —
7509
+ // which silently renders unparseable colors as #000000. With both bg and
7510
+ // fg corrupted, enabling the override painted the terminal black-on-black
7511
+ // (invisible), i.e. "the color override stopped working". Sanitizing on
7512
+ // every load/save self-heals those clients.
7513
+ _sanitizeHexColor(value, fallback) {
7514
+ if (typeof value === 'string' && /^#[0-9a-fA-F]{6}$/.test(value.trim())) {
7515
+ return value.trim().toLowerCase();
7516
+ }
7517
+ return fallback;
7494
7518
  }
7495
7519
 
7496
- loadTerminalColorSettings() {
7497
- // Load settings for current theme
7498
- const themeKey = this.theme; // 'dark' or 'light'
7499
-
7500
- // Default colors for each theme
7520
+ _terminalColorDefaults(themeKey) {
7521
+ // Default colors for each theme. Override defaults to OFF: out of the
7522
+ // box the terminal keeps its standard colors and remote ANSI palette;
7523
+ // the user opts in explicitly per theme.
7501
7524
  const defaults = {
7502
7525
  dark: {
7503
- override: true,
7526
+ override: false,
7504
7527
  bg: '#0d1117',
7505
7528
  fg: '#e6edf3',
7506
7529
  selection: '#264f78'
7507
7530
  },
7508
7531
  light: {
7509
- override: true,
7532
+ override: false,
7510
7533
  bg: '#ffffff',
7511
7534
  fg: '#1f2328',
7512
7535
  selection: '#b6e3ff'
7513
7536
  }
7514
7537
  };
7515
-
7516
- const defaultSet = defaults[themeKey] || defaults.dark;
7517
-
7518
- this.terminalColorOverride = localStorage.getItem(`terminalColorOverride_${themeKey}`) !== 'false';
7519
- // If not set, use default (true for both themes)
7520
- if (localStorage.getItem(`terminalColorOverride_${themeKey}`) === null) {
7521
- this.terminalColorOverride = defaultSet.override;
7538
+ return defaults[themeKey] || defaults.dark;
7539
+ }
7540
+
7541
+ saveTerminalColorSettings() {
7542
+ // Save settings for current theme
7543
+ const themeKey = this.theme; // 'dark' or 'light'
7544
+ if (themeKey !== 'dark' && themeKey !== 'light') {
7545
+ // this.theme not initialized yet — writing now would create
7546
+ // "terminalBgColor_undefined" style keys (and losing the real ones).
7547
+ console.warn('[SSHIFT] Skipping terminal color save — theme not initialized yet');
7548
+ return;
7522
7549
  }
7523
-
7524
- this.terminalBgColor = localStorage.getItem(`terminalBgColor_${themeKey}`) || defaultSet.bg;
7525
- this.terminalFgColor = localStorage.getItem(`terminalFgColor_${themeKey}`) || defaultSet.fg;
7526
- this.terminalSelectionColor = localStorage.getItem(`terminalSelectionColor_${themeKey}`) || defaultSet.selection;
7550
+ const defaultSet = this._terminalColorDefaults(themeKey);
7551
+ // The override flag uses a v2 key: the legacy key was written as "true"
7552
+ // by every color save while override still defaulted to ON, so it can't
7553
+ // distinguish "user chose ON" from "old default". Ignoring it resets
7554
+ // everyone to the new default (OFF) exactly once; an explicit toggle
7555
+ // re-enables and persists under the v2 key.
7556
+ localStorage.setItem(`terminalColorOverrideV2_${themeKey}`, this.terminalColorOverride ? 'true' : 'false');
7557
+ localStorage.setItem(`terminalBgColor_${themeKey}`, this._sanitizeHexColor(this.terminalBgColor, defaultSet.bg));
7558
+ localStorage.setItem(`terminalFgColor_${themeKey}`, this._sanitizeHexColor(this.terminalFgColor, defaultSet.fg));
7559
+ localStorage.setItem(`terminalSelectionColor_${themeKey}`, this._sanitizeHexColor(this.terminalSelectionColor, defaultSet.selection));
7560
+ }
7561
+
7562
+ loadTerminalColorSettings() {
7563
+ // Load settings for current theme
7564
+ const themeKey = (this.theme === 'dark' || this.theme === 'light') ? this.theme : 'dark';
7565
+ const defaultSet = this._terminalColorDefaults(themeKey);
7566
+
7567
+ // Clean up junk keys written by historical saves that ran before
7568
+ // this.theme was initialized (e.g. "terminalBgColor_undefined").
7569
+ try {
7570
+ ['terminalColorOverride', 'terminalColorOverrideV2', 'terminalBgColor', 'terminalFgColor', 'terminalSelectionColor']
7571
+ .forEach(k => localStorage.removeItem(`${k}_undefined`));
7572
+ } catch (_) {}
7573
+
7574
+ // Override is opt-in: only an explicit persisted 'true' (v2 key) turns
7575
+ // it on. Anything else — missing key, legacy key, garbage — means OFF.
7576
+ this.terminalColorOverride = localStorage.getItem(`terminalColorOverrideV2_${themeKey}`) === 'true';
7577
+
7578
+ // Colors: sanitize persisted values so corrupt entries (e.g. the
7579
+ // literal string "undefined") can never reach xterm.js again.
7580
+ this.terminalBgColor = this._sanitizeHexColor(localStorage.getItem(`terminalBgColor_${themeKey}`), defaultSet.bg);
7581
+ this.terminalFgColor = this._sanitizeHexColor(localStorage.getItem(`terminalFgColor_${themeKey}`), defaultSet.fg);
7582
+ this.terminalSelectionColor = this._sanitizeHexColor(localStorage.getItem(`terminalSelectionColor_${themeKey}`), defaultSet.selection);
7527
7583
  }
7528
7584
 
7529
7585
  updateTerminalColors() {