@lethevimlet/sshift 1.4.5 → 1.4.7

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.4.5",
3
+ "version": "1.4.7",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -995,41 +995,17 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
995
995
  session.terminal.refresh(0, session.terminal.rows - 1);
996
996
  }
997
997
 
998
- // Snap cell width to an integer number of device pixels by adjusting
999
- // letterSpacing. When cellWidth × DPR is fractional, adjacent cells
1000
- // land on sub-pixel boundaries, causing 1px vertical seams in block
1001
- // characters. Adding a tiny letterSpacing rounds the device-pixel cell
1002
- // width up to a whole number, eliminating seams.
1003
- //
1004
- // Only applies when the needed padding is <= 0.15 CSS px — larger
1005
- // padding is visually noticeable as extra character spacing, so we
1006
- // skip it and accept the occasional 1px seam instead.
1007
- _snapCellWidth(session) {
1008
- if (!session || !session.terminal || !session.fitAddon) return;
1009
- const term = session.terminal;
1010
- const core = term._core;
1011
- if (!core?._renderService?.dimensions?.css?.cell) return;
1012
-
1013
- const cellCssW = core._renderService.dimensions.css.cell.width;
1014
- if (!cellCssW || cellCssW <= 0) return;
1015
-
1016
- const dpr = window.devicePixelRatio || 1;
1017
- const deviceW = cellCssW * dpr;
1018
- const fraction = deviceW - Math.floor(deviceW);
1019
-
1020
- if (fraction > 0.01 && fraction < 0.99) {
1021
- const padCss = (1 - fraction) / dpr;
1022
- // Only snap if the padding needed is tiny (imperceptible).
1023
- // Larger padding creates visible gaps between characters.
1024
- if (padCss <= 0.15) {
1025
- term.options.letterSpacing = padCss;
1026
- } else {
1027
- term.options.letterSpacing = 0;
1028
- }
1029
- } else {
1030
- term.options.letterSpacing = 0;
1031
- }
1032
- }
998
+ // Sub-pixel seam mitigation is handled by canvas/WebGL renderer +
999
+ // customGlyphs: true, which draws block/box characters as vector fills
1000
+ // that meet exactly. letterSpacing nudging doesn't work because xterm.js
1001
+ // only accepts integer letterSpacing values. Origin-snapping transforms
1002
+ // are also unnecessary because the canvas/WebGL renderer paints the cell
1003
+ // grid in its own coordinate system. The remaining mitigation is:
1004
+ // - customGlyphs: true (set in Terminal options)
1005
+ // - canvas or WebGL renderer as default (not DOM)
1006
+ // - clearTextureAtlas() on DPR change (handled by _setupDPRListener)
1007
+ // - clean base metrics: letterSpacing: 0, lineHeight: 1.0 in _fitTerminal
1008
+ _snapCellWidth() { /* no-op: see comment above */ }
1033
1009
 
1034
1010
  // Initialize (or re-initialize) the WebGL renderer addon for a session.
1035
1011
  // Handles context-loss tracking with a retry cap: after 3 losses the session
@@ -1119,7 +1095,6 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1119
1095
  if (session.webglAddon) {
1120
1096
  try { session.webglAddon.clearTextureAtlas(); } catch (_) {}
1121
1097
  }
1122
- this._snapCellWidth(session);
1123
1098
  if (session.terminal) {
1124
1099
  session.terminal.refresh(0, session.terminal.rows - 1);
1125
1100
  }
@@ -1183,7 +1158,6 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1183
1158
  currentDPR = newDPR;
1184
1159
  this.sessions.forEach(session => {
1185
1160
  this._resetWebGLAtlas(session);
1186
- this._snapCellWidth(session);
1187
1161
  if (session.fitAddon && session.terminal && session.isController) {
1188
1162
  const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
1189
1163
  if (wrapper && wrapper.classList.contains('active')) {
@@ -1226,21 +1200,34 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1226
1200
  return false;
1227
1201
  }
1228
1202
 
1229
- // Guard: refuse to fit if the container has near-zero dimensions.
1230
- // A zero-size container produces bogus col/row counts that propagate to
1231
- // the remote PTY and cause narrow-wrap / garbled output bugs.
1232
- // We use 2px as the threshold to catch truly collapsed containers while
1233
- // allowing containers that are mid-layout-transition but already have
1234
- // meaningful size.
1203
+ // Guard: refuse to fit if the container hasn't reached a usable size.
1204
+ // A zero/very small container (e.g. a pane mid-layout-transition that
1205
+ // is briefly ~100x100px) produces bogus col/row counts. Those propagate
1206
+ // to the remote PTY and cause the "tiny ~10-column terminal" bug.
1207
+ //
1208
+ // 50px is below every real pane size (terms-container min-height 200px,
1209
+ // layout-panel min-width/height enforce 200px+ even on mobile) but above
1210
+ // transient collapsed states (display:none, mid-flex-grow). Retrying on
1211
+ // the next animation frame lets the browser finish laying out first.
1235
1212
  const rect = container.getBoundingClientRect();
1236
- if (rect.width < 2 || rect.height < 2) {
1213
+ if (rect.width < 50 || rect.height < 50) {
1237
1214
  session.needsResize = true;
1238
- if (retryCount < 3) {
1215
+ if (retryCount < 5) {
1239
1216
  requestAnimationFrame(() => this._fitTerminal(session, retryCount + 1));
1240
1217
  }
1241
1218
  return false;
1242
1219
  }
1243
1220
 
1221
+ // Note: do NOT mutate term.options.lineHeight / letterSpacing here.
1222
+ // Both options are set to their base values (1, 0) at Terminal construction
1223
+ // and nothing else modifies them, so a reset would be a no-op — except that
1224
+ // xterm.js's option setter invalidates _renderService.dimensions
1225
+ // asynchronously. Then fitAddon.fit() can read the stale (pre-invalidation)
1226
+ // cell height, computing cols/rows for one cell height while the renderer
1227
+ // paints at another. That mismatch shows every other row empty (the
1228
+ // "alternating black band" rendering bug).
1229
+ const term = session.terminal;
1230
+
1244
1231
  void container.offsetHeight;
1245
1232
  void wrapper.offsetHeight;
1246
1233
 
@@ -1258,7 +1245,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1258
1245
  const containerWidth = container.getBoundingClientRect().width;
1259
1246
  if (cellWidth > 0 && containerWidth > 80) {
1260
1247
  const expectedCols = Math.floor(containerWidth / cellWidth);
1261
- if (terminal.cols < expectedCols * 0.5 && retryCount < 3) {
1248
+ if (terminal.cols < expectedCols * 0.5 && retryCount < 5) {
1262
1249
  console.warn(`[SSHIFT] Terminal fit seems incorrect (cols: ${terminal.cols}, expected: ~${expectedCols}, container: ${containerWidth}px), retrying (attempt ${retryCount + 1})...`);
1263
1250
  requestAnimationFrame(() => {
1264
1251
  this._fitTerminal(session, retryCount + 1);
@@ -1268,22 +1255,6 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1268
1255
  }
1269
1256
  }
1270
1257
 
1271
- // Snap cell width to an integer number of device pixels so block/box
1272
- // drawing characters tile without 1px seams on fractional-DPR displays.
1273
- // This MUST be followed by a refit because letterSpacing changes the
1274
- // cell width, which changes how many columns fit in the container.
1275
- const letterSpacingBefore = terminal.options.letterSpacing || 0;
1276
- this._snapCellWidth(session);
1277
- const letterSpacingAfter = terminal.options.letterSpacing || 0;
1278
-
1279
- // If letterSpacing changed, refit so xterm recalculates column count
1280
- // with the new (snapped) cell width.
1281
- if (letterSpacingAfter !== letterSpacingBefore) {
1282
- try {
1283
- session.fitAddon.fit();
1284
- } catch (_) {}
1285
- }
1286
-
1287
1258
  console.log('[SSHIFT] Terminal fitted, cols:', terminal.cols, 'rows:', terminal.rows);
1288
1259
 
1289
1260
  // Resize changes cell metrics; clear the WebGL atlas so glyphs are
@@ -7219,10 +7190,19 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
7219
7190
  console.log('[SSHIFT] Container dimensions:', container.offsetWidth, 'x', container.offsetHeight);
7220
7191
  console.log('[SSHIFT] Wrapper visible:', isVisible, 'Display:', wrapper ? getComputedStyle(wrapper).display : 'N/A');
7221
7192
 
7222
- // Ensure container has dimensions and is visible
7223
- if (container.offsetWidth === 0 || container.offsetHeight === 0 || !isVisible) {
7193
+ // Ensure container has dimensions large enough for a usable terminal
7194
+ // before opening it. A pane that is mid-layout-transition can briefly
7195
+ // measure ~100x100px; terminal.open() at that size computes bogus
7196
+ // cols/rows that get sent to the remote PTY, and the terminal stays
7197
+ // tiny from then on. See _fitTerminal's matching threshold comment.
7198
+ const rect = container.getBoundingClientRect();
7199
+ if (
7200
+ !isVisible ||
7201
+ rect.width < 50 || rect.height < 50 ||
7202
+ container.offsetWidth === 0 || container.offsetHeight === 0
7203
+ ) {
7224
7204
  if (retryCount < 10) {
7225
- console.warn(`[SSHIFT] Container not ready (attempt ${retryCount + 1}/10), waiting...`);
7205
+ console.warn(`[SSHIFT] Container not ready (attempt ${retryCount + 1}/10, ${rect.width}x${rect.height}px), waiting...`);
7226
7206
  setTimeout(() => this.initTerminal(sessionId, retryCount + 1), 100);
7227
7207
  return;
7228
7208
  } else {
@@ -7343,10 +7323,16 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
7343
7323
 
7344
7324
  console.log('[SSHIFT] Opening terminal in container...');
7345
7325
 
7346
- // Ensure container has valid dimensions before opening
7326
+ // Ensure container has valid dimensions before opening.
7327
+ // xterm.js's terminal.open() inlines a sized <div> based on whatever
7328
+ // cols/rows the Terminal was constructed with; if the container is
7329
+ // collapsed at open() time the inline styles get pinned to near-zero
7330
+ // pixels and subsequent fit()s can fail to recover from that state.
7331
+ // The matching load-time retry above already keeps us waiting until
7332
+ // the container is usable; re-check here as a hard invariant.
7347
7333
  const rect = container.getBoundingClientRect();
7348
- if (rect.width === 0 || rect.height === 0) {
7349
- console.error('[SSHIFT] Container has zero dimensions:', rect.width, 'x', rect.height);
7334
+ if (rect.width < 50 || rect.height < 50) {
7335
+ console.error('[SSHIFT] Container not usable before open():', rect.width, 'x', rect.height);
7350
7336
  this.showToast('Terminal container has invalid dimensions', 'error');
7351
7337
  return;
7352
7338
  }
@@ -7487,6 +7473,27 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
7487
7473
  // it will have set needsResize = true so switchTab() picks it up.
7488
7474
  console.log('[SSHIFT] Could not fit after fonts ready — deferred to tab activation');
7489
7475
  }
7476
+
7477
+ // Safety net: the first fit may have measured a pane mid-layout
7478
+ // (Browser is still committing display:none -> display:flex, or a
7479
+ // sidebar is collapsing/opening). Re-fit after layout settles so
7480
+ // a transient small pane size doesn't leave the terminal stuck in
7481
+ // a ~100x100px box (the "tiny terminal" bug). Mirrors the same
7482
+ // fix already used in switchTab().
7483
+ setTimeout(() => {
7484
+ if (!session.terminal || !session.fitAddon || !session.isController) return;
7485
+ const w = document.getElementById(`terminal-wrapper-${session.id}`);
7486
+ if (w && w.classList.contains('active')) {
7487
+ this._fitTerminal(session);
7488
+ }
7489
+ }, 250);
7490
+ setTimeout(() => {
7491
+ if (!session.terminal || !session.fitAddon || !session.isController) return;
7492
+ const w = document.getElementById(`terminal-wrapper-${session.id}`);
7493
+ if (w && w.classList.contains('active')) {
7494
+ this._fitTerminal(session);
7495
+ }
7496
+ }, 600);
7490
7497
  });
7491
7498
  });
7492
7499