multiline output (e.g. man, bare-slice pager) matches real PTY behavior and avoids misaligned lines vs the peer terminal. Mirror pty-req TERM and dimensions into forked session vfs.env (COLUMNS, LINES) when bareOsForkShellEnv is used; clear target on session end. Add bare-openssh-pty-console helper module and brittle tests; re-export formatter from bare-openssh for API parity.
24 lines
716 B
JavaScript
24 lines
716 B
JavaScript
/**
|
|
* SSH PTY console newline helpers (no bare-ssh2 import — safe for brittle-node tests).
|
|
*/
|
|
|
|
/**
|
|
* Normalize embedded newlines to CRLF for SSH PTY output (multiline `console.log`, e.g. `man`).
|
|
* @param {unknown} s
|
|
* @returns {string}
|
|
*/
|
|
export function bareOpensshFormatConsoleTextForPty(s) {
|
|
return String(s).replace(/\r?\n/g, '\r\n')
|
|
}
|
|
|
|
/**
|
|
* @param {import('stream').Duplex} stream
|
|
* @param {unknown[]} args
|
|
*/
|
|
export function bareOpensshWritePtyConsoleLine(stream, args) {
|
|
const body = args.map(String).join(' ')
|
|
const normalized = bareOpensshFormatConsoleTextForPty(body)
|
|
const out = normalized.endsWith('\r\n') ? normalized : normalized + '\r\n'
|
|
if (stream.writable) stream.write(out)
|
|
}
|