@lethevimlet/sshift 1.6.0 → 1.6.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 +1 -1
- package/src/webapp/js/app.js +169 -15
package/package.json
CHANGED
package/src/webapp/js/app.js
CHANGED
|
@@ -1043,6 +1043,34 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1043
1043
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1044
1044
|
}
|
|
1045
1045
|
|
|
1046
|
+
// Synchronously commit the renderer's cell dimensions after a font-size
|
|
1047
|
+
// (or font-family) option change, then clear the glyph atlas.
|
|
1048
|
+
//
|
|
1049
|
+
// xterm.js v6 invalidates _renderService.dimensions ASYNCHRONOUSLY when an
|
|
1050
|
+
// option like fontSize is set: the CharSizeService only re-measures on the
|
|
1051
|
+
// next change tick. If fitAddon.fit() runs in the same synchronous frame
|
|
1052
|
+
// it reads the STALE (pre-invalidation) cell height/width, so cols/rows are
|
|
1053
|
+
// computed for one cell size while the renderer later paints at another.
|
|
1054
|
+
// That mismatch paints every other row as an empty black band — the
|
|
1055
|
+
// "interlace" bug (see comments at the Terminal construction path and at
|
|
1056
|
+
// _fitTerminal). Calling _charSizeService.measure() fires
|
|
1057
|
+
// onCharSizeChange synchronously, which the RenderService forwards to the
|
|
1058
|
+
// renderer's handleCharSizeChanged so _updateDimensions runs BEFORE fit.
|
|
1059
|
+
// This mirrors the proven fix used after document.fonts.ready at
|
|
1060
|
+
// construction time. Without this, switchTab/setSessionFontSize race the
|
|
1061
|
+
// fit and the terminal renders interlaced until a window resize forces a
|
|
1062
|
+
// clean re-fit.
|
|
1063
|
+
_syncCharSizeThenClearAtlas(session) {
|
|
1064
|
+
if (!session || !session.terminal) return;
|
|
1065
|
+
const core = session.terminal._core;
|
|
1066
|
+
if (core && core._charSizeService && typeof core._charSizeService.measure === 'function') {
|
|
1067
|
+
try { core._charSizeService.measure(); } catch (_) {}
|
|
1068
|
+
}
|
|
1069
|
+
if (session.webglAddon) {
|
|
1070
|
+
try { session.webglAddon.clearTextureAtlas(); } catch (_) {}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1046
1074
|
// Sub-pixel seam mitigation is handled by canvas/WebGL renderer +
|
|
1047
1075
|
// customGlyphs: true, which draws block/box characters as vector fills
|
|
1048
1076
|
// that meet exactly. letterSpacing nudging doesn't work because xterm.js
|
|
@@ -1342,12 +1370,103 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1342
1370
|
|
|
1343
1371
|
if (!wrapper.classList.contains('active')) {
|
|
1344
1372
|
this.switchTab(sessionId);
|
|
1345
|
-
setTimeout(() => this.
|
|
1373
|
+
setTimeout(() => this.forceResizeLikeRefit(session), 50);
|
|
1346
1374
|
} else {
|
|
1347
|
-
|
|
1375
|
+
// Use the resize-like refit (synchronous reflow + measure + fit +
|
|
1376
|
+
// clearTextureAtlas + refresh) — this is the user-facing "terminal
|
|
1377
|
+
// looks wrong, force a resize" button, so it should do everything a
|
|
1378
|
+
// real window resize does, not just fit().
|
|
1379
|
+
this.forceResizeLikeRefit(session);
|
|
1348
1380
|
}
|
|
1349
1381
|
}
|
|
1350
1382
|
|
|
1383
|
+
// Force a refit that behaves like a real window resize for one session.
|
|
1384
|
+
//
|
|
1385
|
+
// A real browser resize reliably clears the interlace ("black band")
|
|
1386
|
+
// rendering artefact because it:
|
|
1387
|
+
// 1. forces the browser to COMMIT any pending layout synchronously before
|
|
1388
|
+
// any handler reads dimensions, and
|
|
1389
|
+
// 2. fires the terminal's ResizeObserver + the global `resize` event.
|
|
1390
|
+
//
|
|
1391
|
+
// The existing safety refits (setTimeout/requestAnimationFrame in switchTab
|
|
1392
|
+
// and the take-control paths) can run BEFORE the browser has committed the
|
|
1393
|
+
// post-visibility / post-font-swap layout, so _fitTerminal measures a
|
|
1394
|
+
// transient container size and the WebGL atlas ends up rasterising glyphs
|
|
1395
|
+
// at a cell pitch that no longer matches the committed cell layout → bands.
|
|
1396
|
+
//
|
|
1397
|
+
// This helper replicates the two guarantees of a real resize, in order:
|
|
1398
|
+
// a) read offsetWidth/offsetHeight on the wrapper AND container — a
|
|
1399
|
+
// synchronous reflow that forces layout to commit NOW,
|
|
1400
|
+
// b) synchronously commit the renderer's cell metrics (measure()) so
|
|
1401
|
+
// fit() reads the current cell size, not a stale one,
|
|
1402
|
+
// c) fitAddon.fit() (which internally calls resize() / onResize),
|
|
1403
|
+
// d) clearTextureAtlas() + refresh() so the WebGL glyph cache is rebuilt
|
|
1404
|
+
// at the committed cell pitch (this is what actually kills the bands),
|
|
1405
|
+
// e) notify the remote PTY of the corrected cols/rows if this is a
|
|
1406
|
+
// connected controller session.
|
|
1407
|
+
//
|
|
1408
|
+
// Returns true on success, false if the session/container isn't usable.
|
|
1409
|
+
forceResizeLikeRefit(session, { emit = true } = {}) {
|
|
1410
|
+
if (!session || !session.terminal || !session.fitAddon) return false;
|
|
1411
|
+
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
1412
|
+
const container = document.getElementById(`terminal-${session.id}`);
|
|
1413
|
+
if (!wrapper || !container) return false;
|
|
1414
|
+
|
|
1415
|
+
// (a) Synchronous reflow — force the browser to commit layout NOW.
|
|
1416
|
+
// This is what a real window resize does implicitly before handlers
|
|
1417
|
+
// run, and what setTimeout-based refits cannot guarantee.
|
|
1418
|
+
void wrapper.offsetWidth;
|
|
1419
|
+
void wrapper.offsetHeight;
|
|
1420
|
+
void container.offsetWidth;
|
|
1421
|
+
void container.offsetHeight;
|
|
1422
|
+
|
|
1423
|
+
// (b) Commit the renderer's cell metrics before fit reads them.
|
|
1424
|
+
this._syncCharSizeThenClearAtlas(session);
|
|
1425
|
+
|
|
1426
|
+
// (c) Fit (resize the terminal buffer to the now-committed container).
|
|
1427
|
+
let ok = false;
|
|
1428
|
+
try {
|
|
1429
|
+
session.fitAddon.fit();
|
|
1430
|
+
ok = true;
|
|
1431
|
+
} catch (e) {
|
|
1432
|
+
console.warn('[SSHIFT] forceResizeLikeRefit: fit failed:', e.message);
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// (d) Rebuild the WebGL glyph atlas at the committed cell pitch + repaint.
|
|
1436
|
+
// This is the step that actually clears the interlace bands: a stale
|
|
1437
|
+
// atlas rasters glyphs at the old (smaller) row pitch and the renderer
|
|
1438
|
+
// paints them at the new (taller) pitch, leaving every other row dark.
|
|
1439
|
+
if (session.terminal) {
|
|
1440
|
+
if (session.webglAddon) {
|
|
1441
|
+
try { session.webglAddon.clearTextureAtlas(); } catch (_) {}
|
|
1442
|
+
}
|
|
1443
|
+
try { session.terminal.refresh(0, session.terminal.rows - 1); } catch (_) {}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
// (e) Notify the remote PTY of the corrected dimensions. Mirror the
|
|
1447
|
+
// debounced onResize handler but fire immediately so the server's
|
|
1448
|
+
// PTY matches our terminal within this frame. Only emit for a
|
|
1449
|
+
// connected controller SSH/SFTP session (non-controllers get the
|
|
1450
|
+
// resize via the sticky sync).
|
|
1451
|
+
if (emit && ok && session.connected && session.isController && session.terminal) {
|
|
1452
|
+
const sid = session.id;
|
|
1453
|
+
const cols = session.terminal.cols;
|
|
1454
|
+
const rows = session.terminal.rows;
|
|
1455
|
+
if (cols && rows) {
|
|
1456
|
+
try {
|
|
1457
|
+
if (session.resizeTimeout) {
|
|
1458
|
+
clearTimeout(session.resizeTimeout);
|
|
1459
|
+
session.resizeTimeout = null;
|
|
1460
|
+
}
|
|
1461
|
+
// Emit synchronously (we already debounced upstream by only calling
|
|
1462
|
+
// this on discrete events: take-control / panel grab settlement).
|
|
1463
|
+
this.socket.emit('ssh-resize', { sessionId: sid, cols, rows });
|
|
1464
|
+
} catch (_) {}
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return ok;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1351
1470
|
// Set font size for a specific session
|
|
1352
1471
|
setSessionFontSize(sessionId, size) {
|
|
1353
1472
|
const session = this.sessions.get(sessionId);
|
|
@@ -1362,12 +1481,13 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1362
1481
|
// Update session's font size
|
|
1363
1482
|
session.fontSize = size;
|
|
1364
1483
|
|
|
1365
|
-
// Update the terminal
|
|
1484
|
+
// Update the terminal. Setting fontSize async-invalidates the
|
|
1485
|
+
// renderer dimensions; commit the new cell size synchronously
|
|
1486
|
+
// (measure) before fit() reads it, otherwise cols/rows are
|
|
1487
|
+
// computed from a stale cell height and the terminal paints
|
|
1488
|
+
// interlaced black bands (the "interlace" bug).
|
|
1366
1489
|
session.terminal.options.fontSize = size;
|
|
1367
|
-
|
|
1368
|
-
// Font-size changes invalidate the glyph atlas — clear it so
|
|
1369
|
-
// glyphs are re-rasterised at the new size.
|
|
1370
|
-
this._resetWebGLAtlas(session);
|
|
1490
|
+
this._syncCharSizeThenClearAtlas(session);
|
|
1371
1491
|
|
|
1372
1492
|
if (session.fitAddon && session.isController) {
|
|
1373
1493
|
this._fitTerminal(session);
|
|
@@ -1392,11 +1512,13 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1392
1512
|
|
|
1393
1513
|
this.terminalFontSize = size;
|
|
1394
1514
|
|
|
1395
|
-
// Update all active SSH terminals
|
|
1515
|
+
// Update all active SSH terminals. Commit the new cell size
|
|
1516
|
+
// synchronously (measure) before fit() so it doesn't read the
|
|
1517
|
+
// stale pre-invalidation cell height and paint interlaced bands.
|
|
1396
1518
|
this.sessions.forEach((session) => {
|
|
1397
1519
|
if (session.terminal) {
|
|
1398
1520
|
session.terminal.options.fontSize = size;
|
|
1399
|
-
this.
|
|
1521
|
+
this._syncCharSizeThenClearAtlas(session);
|
|
1400
1522
|
if (session.fitAddon && session.isController) {
|
|
1401
1523
|
this._fitTerminal(session);
|
|
1402
1524
|
}
|
|
@@ -1409,7 +1531,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1409
1531
|
this.sftpSessions.forEach((session) => {
|
|
1410
1532
|
if (session.terminal) {
|
|
1411
1533
|
session.terminal.options.fontSize = size;
|
|
1412
|
-
this.
|
|
1534
|
+
this._syncCharSizeThenClearAtlas(session);
|
|
1413
1535
|
if (session.fitAddon) {
|
|
1414
1536
|
this._fitTerminal(session);
|
|
1415
1537
|
}
|
|
@@ -2619,10 +2741,12 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2619
2741
|
const currentSize = sftpSession.fontSize || this.terminalFontSize;
|
|
2620
2742
|
const newSize = currentSize + delta;
|
|
2621
2743
|
|
|
2622
|
-
// Set font size for this SFTP session
|
|
2744
|
+
// Set font size for this SFTP session. Commit the new cell size
|
|
2745
|
+
// synchronously (measure) before fit() so it doesn't read a stale
|
|
2746
|
+
// cell height and paint interlaced black bands (the "interlace" bug).
|
|
2623
2747
|
sftpSession.fontSize = Math.max(this.minFontSize, Math.min(this.maxFontSize, newSize));
|
|
2624
2748
|
sftpSession.terminal.options.fontSize = sftpSession.fontSize;
|
|
2625
|
-
this.
|
|
2749
|
+
this._syncCharSizeThenClearAtlas(sftpSession);
|
|
2626
2750
|
|
|
2627
2751
|
if (sftpSession.fitAddon) {
|
|
2628
2752
|
this._fitTerminal(sftpSession);
|
|
@@ -4667,6 +4791,14 @@ const wheelHandler = (e) => {
|
|
|
4667
4791
|
|
|
4668
4792
|
setTimeout(() => {
|
|
4669
4793
|
if (session.terminal && session.connected && session.isController) {
|
|
4794
|
+
// Force a resize-like refit before requesting the screen
|
|
4795
|
+
// sync: clearTextureAtlas()+refresh() at the committed
|
|
4796
|
+
// cell pitch clears the interlace "black band" artefact
|
|
4797
|
+
// that can form when becoming the controller (the take-
|
|
4798
|
+
// control overlay hide is a display change that can
|
|
4799
|
+
// leave the WebGL atlas desynced from the cell layout).
|
|
4800
|
+
console.log('[SSHIFT] Force-resize refit before screen sync after becoming controller');
|
|
4801
|
+
this.forceResizeLikeRefit(session);
|
|
4670
4802
|
console.log('[SSHIFT] Requesting screen sync after becoming controller to redraw at local dimensions');
|
|
4671
4803
|
this.requestScreenSync(data.sessionId);
|
|
4672
4804
|
}
|
|
@@ -4764,6 +4896,14 @@ const wheelHandler = (e) => {
|
|
|
4764
4896
|
|
|
4765
4897
|
setTimeout(() => {
|
|
4766
4898
|
if (session.terminal && session.connected && session.isController) {
|
|
4899
|
+
// Force a resize-like refit before requesting the screen
|
|
4900
|
+
// sync: clearTextureAtlas()+refresh() at the committed cell
|
|
4901
|
+
// pitch clears the interlace "black band" artefact that can
|
|
4902
|
+
// form on take-control (the control-overlay hide is a
|
|
4903
|
+
// display change that can leave the WebGL atlas desynced
|
|
4904
|
+
// from the cell layout — same family as the panel-grab bug).
|
|
4905
|
+
console.log('[SSHIFT] Force-resize refit before screen sync after taking control');
|
|
4906
|
+
this.forceResizeLikeRefit(session);
|
|
4767
4907
|
console.log('[SSHIFT] Requesting screen sync after taking control to redraw at local dimensions');
|
|
4768
4908
|
this.requestScreenSync(data.sessionId);
|
|
4769
4909
|
}
|
|
@@ -9817,9 +9957,15 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
9817
9957
|
// Clearing + refreshing forces a clean redraw at the correct size.
|
|
9818
9958
|
this._resetWebGLAtlas(session);
|
|
9819
9959
|
|
|
9820
|
-
// Restore font size for this session
|
|
9960
|
+
// Restore font size for this session. Setting fontSize async-
|
|
9961
|
+
// invalidates _renderService.dimensions; we must commit the new
|
|
9962
|
+
// cell size synchronously (via _charSizeService.measure()) BEFORE
|
|
9963
|
+
// fit() below reads it, otherwise fit computes cols/rows from a
|
|
9964
|
+
// stale cell height and the renderer paints interlaced black bands
|
|
9965
|
+
// (the "interlace" bug — see _syncCharSizeThenClearAtlas).
|
|
9821
9966
|
if (session.fontSize && session.terminal) {
|
|
9822
9967
|
session.terminal.options.fontSize = session.fontSize;
|
|
9968
|
+
this._syncCharSizeThenClearAtlas(session);
|
|
9823
9969
|
console.log('[SSHIFT] Restored font size', session.fontSize, 'for session', sessionId);
|
|
9824
9970
|
}
|
|
9825
9971
|
|
|
@@ -9851,11 +9997,19 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
9851
9997
|
// (e.g. 100×100px) because the browser hasn't fully committed the
|
|
9852
9998
|
// display:none → display:flex layout change. A delayed refit
|
|
9853
9999
|
// corrects this once the layout has settled.
|
|
10000
|
+
//
|
|
10001
|
+
// This uses forceResizeLikeRefit (not plain _fitTerminal) because
|
|
10002
|
+
// it replicates what a real window resize does — a synchronous
|
|
10003
|
+
// layout commit via offsetWidth reflow, then measure()+fit()+
|
|
10004
|
+
// clearTextureAtlas() + refresh(). That is exactly what clears
|
|
10005
|
+
// the interlace "black band" artefact after a panel/tab switch
|
|
10006
|
+
// (the artefact self-heals on manual resize; this gives the same
|
|
10007
|
+
// self-heal without requiring the user to resize).
|
|
9854
10008
|
setTimeout(() => {
|
|
9855
10009
|
if (!session.terminal || !session.fitAddon || !session.isController) return;
|
|
9856
10010
|
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
9857
10011
|
if (wrapper && wrapper.classList.contains('active')) {
|
|
9858
|
-
this.
|
|
10012
|
+
this.forceResizeLikeRefit(session);
|
|
9859
10013
|
}
|
|
9860
10014
|
}, 150);
|
|
9861
10015
|
|
|
@@ -9896,7 +10050,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
9896
10050
|
if (sftpSession && sftpSession.terminal) {
|
|
9897
10051
|
if (sftpSession.fontSize) {
|
|
9898
10052
|
sftpSession.terminal.options.fontSize = sftpSession.fontSize;
|
|
9899
|
-
this.
|
|
10053
|
+
this._syncCharSizeThenClearAtlas(sftpSession);
|
|
9900
10054
|
}
|
|
9901
10055
|
}
|
|
9902
10056
|
|