@lethevimlet/sshift 1.7.0 → 1.7.2

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.2",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -868,6 +868,7 @@ body {
868
868
  align-items: center;
869
869
  justify-content: space-between;
870
870
  gap: 12px;
871
+ min-width: 0;
871
872
  }
872
873
 
873
874
  .terminal-color-options label {
@@ -876,6 +877,40 @@ body {
876
877
  flex-shrink: 0;
877
878
  }
878
879
 
880
+ /* Color picker + its restore-default button, kept together on the right */
881
+ .color-input-group {
882
+ display: flex;
883
+ align-items: center;
884
+ gap: 6px;
885
+ flex-shrink: 0;
886
+ }
887
+
888
+ .color-reset-btn {
889
+ display: inline-flex;
890
+ align-items: center;
891
+ justify-content: center;
892
+ width: 28px;
893
+ height: 28px;
894
+ flex-shrink: 0;
895
+ background: var(--bg-tertiary);
896
+ border: 1px solid var(--border-color);
897
+ border-radius: var(--radius-sm);
898
+ color: var(--text-secondary);
899
+ cursor: pointer;
900
+ font-size: 12px;
901
+ padding: 0;
902
+ transition: var(--transition-fast);
903
+ }
904
+
905
+ .color-reset-btn:hover {
906
+ color: var(--text-primary);
907
+ border-color: var(--accent-primary);
908
+ }
909
+
910
+ .color-reset-btn:active {
911
+ transform: scale(0.94);
912
+ }
913
+
879
914
  .color-input {
880
915
  width: 40px;
881
916
  height: 28px;
@@ -125,15 +125,30 @@
125
125
  <div class="terminal-color-options" id="terminalColorOptions">
126
126
  <div class="terminal-color-option">
127
127
  <label for="terminalBgColor">Background</label>
128
- <input type="color" id="terminalBgColor" class="color-input" value="#0d1117">
128
+ <div class="color-input-group">
129
+ <input type="color" id="terminalBgColor" class="color-input" value="#0d1117">
130
+ <button type="button" class="color-reset-btn" data-color-target="bg" title="Restore default background">
131
+ <i class="fas fa-rotate-left"></i>
132
+ </button>
133
+ </div>
129
134
  </div>
130
135
  <div class="terminal-color-option">
131
136
  <label for="terminalFgColor">Foreground</label>
132
- <input type="color" id="terminalFgColor" class="color-input" value="#e6edf3">
137
+ <div class="color-input-group">
138
+ <input type="color" id="terminalFgColor" class="color-input" value="#e6edf3">
139
+ <button type="button" class="color-reset-btn" data-color-target="fg" title="Restore default foreground">
140
+ <i class="fas fa-rotate-left"></i>
141
+ </button>
142
+ </div>
133
143
  </div>
134
144
  <div class="terminal-color-option">
135
145
  <label for="terminalSelectionColor">Selection</label>
136
- <input type="color" id="terminalSelectionColor" class="color-input" value="#264f78">
146
+ <div class="color-input-group">
147
+ <input type="color" id="terminalSelectionColor" class="color-input" value="#264f78">
148
+ <button type="button" class="color-reset-btn" data-color-target="selection" title="Restore default selection color">
149
+ <i class="fas fa-rotate-left"></i>
150
+ </button>
151
+ </div>
137
152
  </div>
138
153
  </div>
139
154
  </div>
@@ -219,15 +234,30 @@
219
234
  <div class="terminal-color-options" id="mobileTerminalColorOptions">
220
235
  <div class="terminal-color-option">
221
236
  <label for="mobileTerminalBgColor">Background</label>
222
- <input type="color" id="mobileTerminalBgColor" class="color-input" value="#0d1117">
237
+ <div class="color-input-group">
238
+ <input type="color" id="mobileTerminalBgColor" class="color-input" value="#0d1117">
239
+ <button type="button" class="color-reset-btn" data-color-target="bg" title="Restore default background">
240
+ <i class="fas fa-rotate-left"></i>
241
+ </button>
242
+ </div>
223
243
  </div>
224
244
  <div class="terminal-color-option">
225
245
  <label for="mobileTerminalFgColor">Foreground</label>
226
- <input type="color" id="mobileTerminalFgColor" class="color-input" value="#e6edf3">
246
+ <div class="color-input-group">
247
+ <input type="color" id="mobileTerminalFgColor" class="color-input" value="#e6edf3">
248
+ <button type="button" class="color-reset-btn" data-color-target="fg" title="Restore default foreground">
249
+ <i class="fas fa-rotate-left"></i>
250
+ </button>
251
+ </div>
227
252
  </div>
228
253
  <div class="terminal-color-option">
229
254
  <label for="mobileTerminalSelectionColor">Selection</label>
230
- <input type="color" id="mobileTerminalSelectionColor" class="color-input" value="#264f78">
255
+ <div class="color-input-group">
256
+ <input type="color" id="mobileTerminalSelectionColor" class="color-input" value="#264f78">
257
+ <button type="button" class="color-reset-btn" data-color-target="selection" title="Restore default selection color">
258
+ <i class="fas fa-rotate-left"></i>
259
+ </button>
260
+ </div>
231
261
  </div>
232
262
  </div>
233
263
  </div>
@@ -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',
@@ -1851,6 +1858,27 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1851
1858
  this.updateTerminalThemes(currentTheme);
1852
1859
  }
1853
1860
 
1861
+ // Restore a single terminal color to its per-theme default (the defaults
1862
+ // differ between the dark and light themes — see _terminalColorDefaults).
1863
+ // Used by the reset buttons next to each color picker in the terminal
1864
+ // colors dropdown (desktop) and mobile overflow submenu.
1865
+ resetTerminalColorToDefault(target) {
1866
+ const themeKey = (this.theme === 'dark' || this.theme === 'light') ? this.theme : 'dark';
1867
+ const defaults = this._terminalColorDefaults(themeKey);
1868
+ if (target === 'bg') {
1869
+ this.setTerminalBgColor(defaults.bg);
1870
+ } else if (target === 'fg') {
1871
+ this.setTerminalFgColor(defaults.fg);
1872
+ } else if (target === 'selection') {
1873
+ this.setTerminalSelectionColor(defaults.selection);
1874
+ } else {
1875
+ return;
1876
+ }
1877
+ // Sync both desktop and mobile pickers to the restored value.
1878
+ this.updateTerminalColorOverrideUI();
1879
+ console.log('[SSHIFT] Terminal color reset to default:', target, 'theme:', themeKey);
1880
+ }
1881
+
1854
1882
  updateTerminalColorOverrideUI() {
1855
1883
  // Desktop elements
1856
1884
  const checkbox = document.getElementById('terminalColorOverride');
@@ -4437,6 +4465,12 @@ const wheelHandler = (e) => {
4437
4465
  this.theme = data.theme;
4438
4466
  this.saveTheme(data.theme);
4439
4467
  this.updateThemeIcon(data.theme);
4468
+ // Terminal color settings are stored PER THEME — load the new
4469
+ // theme's set before repainting, otherwise the previous theme's
4470
+ // override/colors leak into this theme (and a later save would
4471
+ // persist them under the wrong key).
4472
+ this.loadTerminalColorSettings();
4473
+ this.updateTerminalColorOverrideUI();
4440
4474
  this.updateTerminalThemes(data.theme);
4441
4475
  }
4442
4476
  }
@@ -4581,6 +4615,11 @@ const wheelHandler = (e) => {
4581
4615
  this.theme = data.theme;
4582
4616
  this.saveTheme(data.theme);
4583
4617
  this.updateThemeIcon(data.theme);
4618
+ // Load the new theme's per-theme terminal color settings before
4619
+ // repainting (mirrors toggleTheme) so override/colors don't leak
4620
+ // between themes.
4621
+ this.loadTerminalColorSettings();
4622
+ this.updateTerminalColorOverrideUI();
4584
4623
  this.updateTerminalThemes(data.theme);
4585
4624
  }
4586
4625
  });
@@ -5528,6 +5567,18 @@ const wheelHandler = (e) => {
5528
5567
  this.setTerminalSelectionColor(e.target.value);
5529
5568
  });
5530
5569
  }
5570
+
5571
+ // Per-picker "restore default" buttons (desktop dropdown + mobile
5572
+ // overflow submenu share the same class + data attribute). Defaults
5573
+ // are per theme (dark/light). stopPropagation keeps the dropdown/
5574
+ // submenu open so the user sees the picker snap back.
5575
+ document.querySelectorAll('.color-reset-btn').forEach(btn => {
5576
+ btn.addEventListener('click', (e) => {
5577
+ e.preventDefault();
5578
+ e.stopPropagation();
5579
+ this.resetTerminalColorToDefault(btn.dataset.colorTarget);
5580
+ });
5581
+ });
5531
5582
 
5532
5583
  // Initialize terminal color override UI state
5533
5584
  this.updateTerminalColorOverrideUI();
@@ -7484,46 +7535,84 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
7484
7535
  }
7485
7536
  }
7486
7537
 
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);
7538
+ // Validate a persisted color value. Historically, saves could run while
7539
+ // the color properties (or this.theme) were still undefined, writing the
7540
+ // literal string "undefined" into localStorage. Such garbage is truthy,
7541
+ // so it survived `value || default` fallbacks and reached xterm.js —
7542
+ // which silently renders unparseable colors as #000000. With both bg and
7543
+ // fg corrupted, enabling the override painted the terminal black-on-black
7544
+ // (invisible), i.e. "the color override stopped working". Sanitizing on
7545
+ // every load/save self-heals those clients.
7546
+ _sanitizeHexColor(value, fallback) {
7547
+ if (typeof value === 'string' && /^#[0-9a-fA-F]{6}$/.test(value.trim())) {
7548
+ return value.trim().toLowerCase();
7549
+ }
7550
+ return fallback;
7494
7551
  }
7495
7552
 
7496
- loadTerminalColorSettings() {
7497
- // Load settings for current theme
7498
- const themeKey = this.theme; // 'dark' or 'light'
7499
-
7500
- // Default colors for each theme
7553
+ _terminalColorDefaults(themeKey) {
7554
+ // Default colors for each theme. Override defaults to OFF: out of the
7555
+ // box the terminal keeps its standard colors and remote ANSI palette;
7556
+ // the user opts in explicitly per theme.
7501
7557
  const defaults = {
7502
7558
  dark: {
7503
- override: true,
7559
+ override: false,
7504
7560
  bg: '#0d1117',
7505
7561
  fg: '#e6edf3',
7506
7562
  selection: '#264f78'
7507
7563
  },
7508
7564
  light: {
7509
- override: true,
7565
+ override: false,
7510
7566
  bg: '#ffffff',
7511
7567
  fg: '#1f2328',
7512
7568
  selection: '#b6e3ff'
7513
7569
  }
7514
7570
  };
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;
7571
+ return defaults[themeKey] || defaults.dark;
7572
+ }
7573
+
7574
+ saveTerminalColorSettings() {
7575
+ // Save settings for current theme
7576
+ const themeKey = this.theme; // 'dark' or 'light'
7577
+ if (themeKey !== 'dark' && themeKey !== 'light') {
7578
+ // this.theme not initialized yet — writing now would create
7579
+ // "terminalBgColor_undefined" style keys (and losing the real ones).
7580
+ console.warn('[SSHIFT] Skipping terminal color save — theme not initialized yet');
7581
+ return;
7522
7582
  }
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;
7583
+ const defaultSet = this._terminalColorDefaults(themeKey);
7584
+ // The override flag uses a v2 key: the legacy key was written as "true"
7585
+ // by every color save while override still defaulted to ON, so it can't
7586
+ // distinguish "user chose ON" from "old default". Ignoring it resets
7587
+ // everyone to the new default (OFF) exactly once; an explicit toggle
7588
+ // re-enables and persists under the v2 key.
7589
+ localStorage.setItem(`terminalColorOverrideV2_${themeKey}`, this.terminalColorOverride ? 'true' : 'false');
7590
+ localStorage.setItem(`terminalBgColor_${themeKey}`, this._sanitizeHexColor(this.terminalBgColor, defaultSet.bg));
7591
+ localStorage.setItem(`terminalFgColor_${themeKey}`, this._sanitizeHexColor(this.terminalFgColor, defaultSet.fg));
7592
+ localStorage.setItem(`terminalSelectionColor_${themeKey}`, this._sanitizeHexColor(this.terminalSelectionColor, defaultSet.selection));
7593
+ }
7594
+
7595
+ loadTerminalColorSettings() {
7596
+ // Load settings for current theme
7597
+ const themeKey = (this.theme === 'dark' || this.theme === 'light') ? this.theme : 'dark';
7598
+ const defaultSet = this._terminalColorDefaults(themeKey);
7599
+
7600
+ // Clean up junk keys written by historical saves that ran before
7601
+ // this.theme was initialized (e.g. "terminalBgColor_undefined").
7602
+ try {
7603
+ ['terminalColorOverride', 'terminalColorOverrideV2', 'terminalBgColor', 'terminalFgColor', 'terminalSelectionColor']
7604
+ .forEach(k => localStorage.removeItem(`${k}_undefined`));
7605
+ } catch (_) {}
7606
+
7607
+ // Override is opt-in: only an explicit persisted 'true' (v2 key) turns
7608
+ // it on. Anything else — missing key, legacy key, garbage — means OFF.
7609
+ this.terminalColorOverride = localStorage.getItem(`terminalColorOverrideV2_${themeKey}`) === 'true';
7610
+
7611
+ // Colors: sanitize persisted values so corrupt entries (e.g. the
7612
+ // literal string "undefined") can never reach xterm.js again.
7613
+ this.terminalBgColor = this._sanitizeHexColor(localStorage.getItem(`terminalBgColor_${themeKey}`), defaultSet.bg);
7614
+ this.terminalFgColor = this._sanitizeHexColor(localStorage.getItem(`terminalFgColor_${themeKey}`), defaultSet.fg);
7615
+ this.terminalSelectionColor = this._sanitizeHexColor(localStorage.getItem(`terminalSelectionColor_${themeKey}`), defaultSet.selection);
7527
7616
  }
7528
7617
 
7529
7618
  updateTerminalColors() {
@@ -7980,6 +8069,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
7980
8069
  flushRemaining: null,
7981
8070
  originalScrollback: null,
7982
8071
  scrollbackRestoreTimer: null,
8072
+ settleRefreshTimer: null,
7983
8073
  // Per-session buffer for OSC 52 / DCS sequences that arrive split
7984
8074
  // across two write-chunk frames (see _handleOsc52).
7985
8075
  pendingOsc52: null
@@ -9415,6 +9505,9 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
9415
9505
  if (session.terminal && session.originalScrollback) {
9416
9506
  session.terminal.options.scrollback = session.originalScrollback;
9417
9507
  session.originalScrollback = null;
9508
+ // The scrollback option change adjusts the buffer; repaint the
9509
+ // full viewport so no row is left showing pre-adjustment content.
9510
+ try { session.terminal.refresh(0, session.terminal.rows - 1); } catch (_) {}
9418
9511
  }
9419
9512
  session.scrollbackRestoreTimer = null;
9420
9513
  }, 3000);
@@ -9441,6 +9534,40 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
9441
9534
  } else {
9442
9535
  terminal.write(combined);
9443
9536
  }
9537
+
9538
+ // Guarantee the screen converges to the buffer once this output burst
9539
+ // settles (see _scheduleSettleRefresh for the full rationale).
9540
+ this._scheduleSettleRefresh(session);
9541
+ }
9542
+
9543
+ // Full-viewport repaint shortly after an output burst settles.
9544
+ //
9545
+ // Under heavy output floods (TUI streaming + per-line scrollback trims
9546
+ // while throttled + 32KB/frame capped writes) the WebGL renderer can
9547
+ // miss dirty-row updates: some rows keep showing STALE content (old
9548
+ // backgrounds / leftover fragments) even though the terminal BUFFER is
9549
+ // correct. Line-diff TUI renderers (OpenCode, Bubble Tea apps, ...)
9550
+ // never rewrite lines they consider unchanged, so those stale rows then
9551
+ // persist indefinitely — visible as "interlaced black lines between
9552
+ // text lines" where the app's painted background alternates with the
9553
+ // terminal's default background. A font-size change or window resize
9554
+ // "fixed" it because both force a full re-render from the buffer.
9555
+ //
9556
+ // This debounced refresh(0, rows-1) after the LAST write of a burst
9557
+ // provides that same guarantee automatically: within ~350ms of any
9558
+ // burst ending, every row is re-rendered from the (correct) buffer.
9559
+ // Cost: one extra full-viewport render per burst — negligible.
9560
+ _scheduleSettleRefresh(session) {
9561
+ if (!session || !session.terminal) return;
9562
+ if (session.settleRefreshTimer) {
9563
+ clearTimeout(session.settleRefreshTimer);
9564
+ }
9565
+ session.settleRefreshTimer = setTimeout(() => {
9566
+ session.settleRefreshTimer = null;
9567
+ const term = session.terminal;
9568
+ if (!term) return;
9569
+ try { term.refresh(0, term.rows - 1); } catch (_) {}
9570
+ }, 350);
9444
9571
  }
9445
9572
 
9446
9573
  // SFTP Session Management
@@ -10343,6 +10470,11 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
10343
10470
  clearTimeout(session.scrollbackRestoreTimer);
10344
10471
  session.scrollbackRestoreTimer = null;
10345
10472
  }
10473
+ // Clean up settle-refresh timer
10474
+ if (session.settleRefreshTimer) {
10475
+ clearTimeout(session.settleRefreshTimer);
10476
+ session.settleRefreshTimer = null;
10477
+ }
10346
10478
  // Restore scrollback if it was dynamically reduced
10347
10479
  if (session.originalScrollback && session.terminal) {
10348
10480
  session.terminal.options.scrollback = session.originalScrollback;
@@ -10442,6 +10574,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
10442
10574
  this.socket.emit('ssh-disconnect', { sessionId });
10443
10575
  if (session.writeRAF) cancelAnimationFrame(session.writeRAF);
10444
10576
  if (session.scrollbackRestoreTimer) clearTimeout(session.scrollbackRestoreTimer);
10577
+ if (session.settleRefreshTimer) clearTimeout(session.settleRefreshTimer);
10445
10578
  if (session.originalScrollback && session.terminal) {
10446
10579
  session.terminal.options.scrollback = session.originalScrollback;
10447
10580
  }