fix(bare-openssh): stop syncing TERM from PTY to fix SSH TUIs (baretop)

PTY env sync now only updates COLUMNS and LINES. Writing the client TERM
(e.g. xterm-256color) into the forked session env enabled baretop’s default
incremental line-diff, which mis-renders over SSH. Inherited guest TERM is
unchanged, matching in-app terminal behavior.
This commit is contained in:
Raven Scott
2026-04-09 01:03:19 -04:00
parent 2b9a10e371
commit 01eddc84bf
+6 -8
View File
@@ -395,7 +395,7 @@ const SSH_PTY_DIM_CAP = 4096
* @param {import('events').EventEmitter} session
*/
function wireSshSessionTerminalDims(session) {
const termSize = { cols: 80, rows: 24, term: /** @type {string} */ ('') }
const termSize = { cols: 80, rows: 24 }
/** @type {import('stream').Duplex | null} */
let channelStream = null
/** @type {Record<string, string | undefined> | null} */
@@ -405,7 +405,9 @@ function wireSshSessionTerminalDims(session) {
if (!ptyEnvTarget || typeof ptyEnvTarget !== 'object') return
ptyEnvTarget.COLUMNS = String(termSize.cols)
ptyEnvTarget.LINES = String(termSize.rows)
if (termSize.term) ptyEnvTarget.TERM = termSize.term
// Do not set TERM from pty-req: the client often sends xterm*, which makes baretop(1)
// default to incremental line-diff; those patches mis-render on some SSH PTY paths.
// Keep the forked session's inherited TERM (same as the in-app terminal guest env).
}
function bindDimsToStream(stream) {
@@ -415,7 +417,7 @@ function wireSshSessionTerminalDims(session) {
syncPtyEnvTarget()
}
/** @param {{ cols?: number, rows?: number, term?: string } | null | undefined} info */
/** @param {{ cols?: number, rows?: number } | null | undefined} info */
function mergeDims(info) {
if (!info || typeof info !== 'object') return
const c = Number(info.cols)
@@ -426,10 +428,6 @@ function wireSshSessionTerminalDims(session) {
if (Number.isFinite(r) && r > 0) {
termSize.rows = Math.min(Math.floor(r), SSH_PTY_DIM_CAP)
}
if (typeof info.term === 'string') {
const t = info.term.trim()
if (t) termSize.term = t.slice(0, 512)
}
}
session.on('pty', (accept, _reject, info) => {
@@ -455,7 +453,7 @@ function wireSshSessionTerminalDims(session) {
if (channelStream === stream) channelStream = null
},
/**
* Forked session `vfs.env` — updated whenever PTY dimensions or TERM change.
* Forked session `vfs.env` — `COLUMNS` / `LINES` updated when PTY dimensions change.
* @param {Record<string, string | undefined> | null | undefined} env
*/
setPtyEnvTarget(env) {