@lethevimlet/sshift 1.4.0 → 1.4.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 +1 -1
- package/src/webapp/js/app.js +117 -21
package/package.json
CHANGED
package/src/webapp/js/app.js
CHANGED
|
@@ -995,6 +995,36 @@ 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 the CSS cell width × devicePixelRatio is fractional,
|
|
1000
|
+
// adjacent cells alternate between N and N+1 device pixels, leaving 1px
|
|
1001
|
+
// vertical seams in block/box-drawing characters. Adding a tiny
|
|
1002
|
+
// letterSpacing pad rounds the device-pixel width up to a whole number,
|
|
1003
|
+
// eliminating seams regardless of zoom level or DPR.
|
|
1004
|
+
_snapCellWidth(session) {
|
|
1005
|
+
if (!session || !session.terminal || !session.fitAddon) return;
|
|
1006
|
+
const term = session.terminal;
|
|
1007
|
+
const core = term._core;
|
|
1008
|
+
if (!core?._renderService?.dimensions?.css?.cell) return;
|
|
1009
|
+
|
|
1010
|
+
const cellCssW = core._renderService.dimensions.css.cell.width;
|
|
1011
|
+
if (!cellCssW || cellCssW <= 0) return;
|
|
1012
|
+
|
|
1013
|
+
const dpr = window.devicePixelRatio || 1;
|
|
1014
|
+
const deviceW = cellCssW * dpr;
|
|
1015
|
+
const fraction = deviceW - Math.floor(deviceW);
|
|
1016
|
+
|
|
1017
|
+
if (fraction > 0.01) {
|
|
1018
|
+
// Pad up to the next whole device pixel, converted back to CSS px.
|
|
1019
|
+
const padCss = (1 - fraction) / dpr;
|
|
1020
|
+
// Clamp to avoid excessive spacing — 0.5 CSS px is generous.
|
|
1021
|
+
const clampedPad = Math.min(padCss, 0.5);
|
|
1022
|
+
term.options.letterSpacing = clampedPad;
|
|
1023
|
+
} else {
|
|
1024
|
+
term.options.letterSpacing = 0;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
998
1028
|
// Initialize (or re-initialize) the WebGL renderer addon for a session.
|
|
999
1029
|
// Handles context-loss tracking with a retry cap: after 3 losses the session
|
|
1000
1030
|
// permanently falls back to the canvas renderer so we don't loop endlessly.
|
|
@@ -1083,6 +1113,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1083
1113
|
if (session.webglAddon) {
|
|
1084
1114
|
try { session.webglAddon.clearTextureAtlas(); } catch (_) {}
|
|
1085
1115
|
}
|
|
1116
|
+
this._snapCellWidth(session);
|
|
1086
1117
|
if (session.terminal) {
|
|
1087
1118
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1088
1119
|
}
|
|
@@ -1135,6 +1166,9 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1135
1166
|
// Watch for devicePixelRatio changes (zoom, monitor move, DPI switch).
|
|
1136
1167
|
// When DPR changes the WebGL glyph atlas is built for the old pixel ratio
|
|
1137
1168
|
// and every glyph becomes mis-scaled; clearing the atlas forces a rebuild.
|
|
1169
|
+
// We also refit and re-snap letterSpacing so cells remain integer-width
|
|
1170
|
+
// in device pixels at the new DPR, eliminating seams on fractional-DPR
|
|
1171
|
+
// displays.
|
|
1138
1172
|
_setupDPRListener() {
|
|
1139
1173
|
let currentDPR = window.devicePixelRatio;
|
|
1140
1174
|
const query = matchMedia(`(resolution: ${currentDPR}dppx)`);
|
|
@@ -1143,8 +1177,21 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1143
1177
|
if (newDPR !== currentDPR) {
|
|
1144
1178
|
console.log('[SSHIFT] devicePixelRatio changed from', currentDPR, 'to', newDPR);
|
|
1145
1179
|
currentDPR = newDPR;
|
|
1146
|
-
this.sessions.forEach(session =>
|
|
1147
|
-
|
|
1180
|
+
this.sessions.forEach(session => {
|
|
1181
|
+
this._resetWebGLAtlas(session);
|
|
1182
|
+
this._snapCellWidth(session);
|
|
1183
|
+
if (session.fitAddon && session.terminal && session.isController) {
|
|
1184
|
+
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
1185
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
1186
|
+
this._fitTerminal(session);
|
|
1187
|
+
} else if (wrapper) {
|
|
1188
|
+
session.needsResize = true;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
this.sftpSessions.forEach(session => {
|
|
1193
|
+
this._resetWebGLAtlas(session);
|
|
1194
|
+
});
|
|
1148
1195
|
}
|
|
1149
1196
|
// Re-register for the new DPR value
|
|
1150
1197
|
this._setupDPRListener();
|
|
@@ -1175,12 +1222,14 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1175
1222
|
return false;
|
|
1176
1223
|
}
|
|
1177
1224
|
|
|
1178
|
-
// Guard: refuse to fit if the container has
|
|
1225
|
+
// Guard: refuse to fit if the container has near-zero dimensions.
|
|
1179
1226
|
// A zero-size container produces bogus col/row counts that propagate to
|
|
1180
1227
|
// the remote PTY and cause narrow-wrap / garbled output bugs.
|
|
1228
|
+
// We use 2px as the threshold to catch truly collapsed containers while
|
|
1229
|
+
// allowing containers that are mid-layout-transition but already have
|
|
1230
|
+
// meaningful size.
|
|
1181
1231
|
const rect = container.getBoundingClientRect();
|
|
1182
|
-
if (rect.width <
|
|
1183
|
-
console.warn(`[SSHIFT] Container too small to fit (${rect.width.toFixed(1)}x${rect.height.toFixed(1)}px), deferring`);
|
|
1232
|
+
if (rect.width < 2 || rect.height < 2) {
|
|
1184
1233
|
session.needsResize = true;
|
|
1185
1234
|
if (retryCount < 3) {
|
|
1186
1235
|
requestAnimationFrame(() => this._fitTerminal(session, retryCount + 1));
|
|
@@ -1217,6 +1266,10 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1217
1266
|
|
|
1218
1267
|
console.log('[SSHIFT] Terminal fitted, cols:', terminal.cols, 'rows:', terminal.rows);
|
|
1219
1268
|
|
|
1269
|
+
// Snap cell width to an integer number of device pixels so block/box
|
|
1270
|
+
// drawing characters tile without 1px seams on fractional-DPR displays.
|
|
1271
|
+
this._snapCellWidth(session);
|
|
1272
|
+
|
|
1220
1273
|
// Resize changes cell metrics; clear the WebGL atlas so glyphs are
|
|
1221
1274
|
// re-rasterised at the new size rather than stretched from the old cache.
|
|
1222
1275
|
this._resetWebGLAtlas(session);
|
|
@@ -4158,10 +4211,11 @@ const wheelHandler = (e) => {
|
|
|
4158
4211
|
if (!session.terminal || !session.fitAddon || !session.isController) return;
|
|
4159
4212
|
try {
|
|
4160
4213
|
session.isResyncing = true;
|
|
4161
|
-
this._fitTerminal(session);
|
|
4214
|
+
const fitted = this._fitTerminal(session);
|
|
4162
4215
|
session.isResyncing = false;
|
|
4163
4216
|
|
|
4164
|
-
if
|
|
4217
|
+
// Only send the resize if we actually fitted successfully.
|
|
4218
|
+
if (fitted && session.terminal && session.connected) {
|
|
4165
4219
|
this.socket.emit('ssh-resize', {
|
|
4166
4220
|
sessionId: data.sessionId,
|
|
4167
4221
|
cols: session.terminal.cols,
|
|
@@ -4175,9 +4229,9 @@ const wheelHandler = (e) => {
|
|
|
4175
4229
|
session.isResyncing = true;
|
|
4176
4230
|
const prevCols = session.terminal.cols;
|
|
4177
4231
|
const prevRows = session.terminal.rows;
|
|
4178
|
-
this._fitTerminal(session);
|
|
4232
|
+
const corrected = this._fitTerminal(session);
|
|
4179
4233
|
session.isResyncing = false;
|
|
4180
|
-
if (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows) {
|
|
4234
|
+
if (corrected && (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows)) {
|
|
4181
4235
|
this.socket.emit('ssh-resize', {
|
|
4182
4236
|
sessionId: data.sessionId,
|
|
4183
4237
|
cols: session.terminal.cols,
|
|
@@ -4250,10 +4304,15 @@ const wheelHandler = (e) => {
|
|
|
4250
4304
|
if (!session.terminal || !session.fitAddon || !session.isController) return;
|
|
4251
4305
|
try {
|
|
4252
4306
|
session.isResyncing = true;
|
|
4253
|
-
this._fitTerminal(session);
|
|
4307
|
+
const fitted = this._fitTerminal(session);
|
|
4254
4308
|
session.isResyncing = false;
|
|
4255
4309
|
|
|
4256
|
-
if
|
|
4310
|
+
// Only send the resize to the server if we actually fitted the
|
|
4311
|
+
// terminal. If _fitTerminal returned false (container too small,
|
|
4312
|
+
// not visible, etc.), the cols/rows are stale and would confuse
|
|
4313
|
+
// the remote PTY. A successful retry will trigger onResize
|
|
4314
|
+
// which emits ssh-resize via the debounced handler.
|
|
4315
|
+
if (fitted && session.terminal && session.connected) {
|
|
4257
4316
|
this.socket.emit('ssh-resize', {
|
|
4258
4317
|
sessionId: data.sessionId,
|
|
4259
4318
|
cols: session.terminal.cols,
|
|
@@ -4267,9 +4326,9 @@ const wheelHandler = (e) => {
|
|
|
4267
4326
|
session.isResyncing = true;
|
|
4268
4327
|
const prevCols = session.terminal.cols;
|
|
4269
4328
|
const prevRows = session.terminal.rows;
|
|
4270
|
-
this._fitTerminal(session);
|
|
4329
|
+
const corrected = this._fitTerminal(session);
|
|
4271
4330
|
session.isResyncing = false;
|
|
4272
|
-
if (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows) {
|
|
4331
|
+
if (corrected && (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows)) {
|
|
4273
4332
|
this.socket.emit('ssh-resize', {
|
|
4274
4333
|
sessionId: data.sessionId,
|
|
4275
4334
|
cols: session.terminal.cols,
|
|
@@ -7192,6 +7251,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7192
7251
|
fontFamily: "'JetBrains Mono', 'Fira Code', 'Consolas', 'Courier New', monospace",
|
|
7193
7252
|
fontSize: this.terminalFontSize,
|
|
7194
7253
|
lineHeight: 1.0,
|
|
7254
|
+
letterSpacing: 0,
|
|
7195
7255
|
cursorBlink: false,
|
|
7196
7256
|
cursorStyle: 'block',
|
|
7197
7257
|
scrollback: this.scrollback || 10000,
|
|
@@ -7203,7 +7263,8 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7203
7263
|
fastScrollModifier: 'alt',
|
|
7204
7264
|
fastScrollSensitivity: 5,
|
|
7205
7265
|
smoothScrollDuration: 80,
|
|
7206
|
-
overviewRuler: { width: 14 }
|
|
7266
|
+
overviewRuler: { width: 14 },
|
|
7267
|
+
customGlyphs: true
|
|
7207
7268
|
});
|
|
7208
7269
|
|
|
7209
7270
|
// Set wrapper background color
|
|
@@ -7772,12 +7833,18 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7772
7833
|
// hold. The PTY on the server wraps at those bogus dimensions.
|
|
7773
7834
|
const sendResize = () => {
|
|
7774
7835
|
if (session.fitAddon) {
|
|
7775
|
-
this._fitTerminal(session);
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7836
|
+
const fitted = this._fitTerminal(session);
|
|
7837
|
+
// Only send the resize to the server if we actually fitted
|
|
7838
|
+
// successfully — otherwise the remote PTY would get stale
|
|
7839
|
+
// dimensions. A deferred retry will trigger onResize which
|
|
7840
|
+
// sends ssh-resize via the debounced handler.
|
|
7841
|
+
if (fitted) {
|
|
7842
|
+
this.socket.emit('ssh-resize', {
|
|
7843
|
+
sessionId: data.sessionId,
|
|
7844
|
+
cols: session.terminal.cols,
|
|
7845
|
+
rows: session.terminal.rows
|
|
7846
|
+
});
|
|
7847
|
+
}
|
|
7781
7848
|
}
|
|
7782
7849
|
};
|
|
7783
7850
|
|
|
@@ -8804,7 +8871,36 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8804
8871
|
session.needsResize = false;
|
|
8805
8872
|
}
|
|
8806
8873
|
|
|
8807
|
-
this._fitTerminal(session);
|
|
8874
|
+
const fitted = this._fitTerminal(session);
|
|
8875
|
+
|
|
8876
|
+
// If fitting failed (e.g. container not yet laid out), retry
|
|
8877
|
+
// with delays until the browser commits the layout change.
|
|
8878
|
+
if (!fitted) {
|
|
8879
|
+
console.log('[SSHIFT] Initial fit failed during tab switch, scheduling retries');
|
|
8880
|
+
let retriesLeft = 4;
|
|
8881
|
+
const retryFit = () => {
|
|
8882
|
+
if (!session.terminal || !session.fitAddon || !session.isController) return;
|
|
8883
|
+
const ok = this._fitTerminal(session);
|
|
8884
|
+
if (!ok && retriesLeft > 0) {
|
|
8885
|
+
retriesLeft--;
|
|
8886
|
+
setTimeout(retryFit, 100);
|
|
8887
|
+
}
|
|
8888
|
+
};
|
|
8889
|
+
setTimeout(retryFit, 50);
|
|
8890
|
+
}
|
|
8891
|
+
|
|
8892
|
+
// Safety net: always schedule a delayed refit after tab switch.
|
|
8893
|
+
// Sometimes the initial fit succeeds at a small intermediate size
|
|
8894
|
+
// (e.g. 100×100px) because the browser hasn't fully committed the
|
|
8895
|
+
// display:none → display:flex layout change. A delayed refit
|
|
8896
|
+
// corrects this once the layout has settled.
|
|
8897
|
+
setTimeout(() => {
|
|
8898
|
+
if (!session.terminal || !session.fitAddon || !session.isController) return;
|
|
8899
|
+
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
8900
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
8901
|
+
this._fitTerminal(session);
|
|
8902
|
+
}
|
|
8903
|
+
}, 150);
|
|
8808
8904
|
|
|
8809
8905
|
// Focus the terminal so user can type
|
|
8810
8906
|
if (session.terminal) {
|