mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-14 13:22:37 +00:00
* Improve mobile terminal typing and selection * Address mobile terminal review feedback * Remove dead native terminal input branch * Replay bracketed paste in terminal preamble * Stop per-key terminal resize claims * Stabilize terminal resize browser test * Use tracked terminal mode for native paste * Restore terminal toolbar focus handling * Adapt native terminal to active visibility state * Stabilize native mobile terminal interactions * Add native terminal fallback boundary * test(app): expect explicit terminal resize reclaim * fix(app): stabilize terminal buffer coordinates * fix(app): restrict terminal resize ownership * fix(terminal): gate restored input modes * fix(app): recover stalled terminal WebViews * chore(app): remove obsolete terminal harnesses * fix(app): make terminal resize claims explicit * test(app): stabilize native terminal device flows * test(app): track absolute scrollback coordinates * fix(app): isolate terminal WebView streams * fix(terminal): arbitrate size ownership across clients The daemon now distinguishes explicit ownership claims from passive geometry updates. This keeps the active client authoritative while allowing its split, viewport, and keyboard changes to resize the PTY without idle clients stealing it. * test(server): make worker resize assertion portable Query the worker's authoritative terminal snapshot instead of invoking a Unix-only shell command, so the resize regression exercises the same boundary on Windows and Unix.
141 lines
3.4 KiB
TypeScript
141 lines
3.4 KiB
TypeScript
import type { TextStyle } from "react-native";
|
|
import type { TerminalCell } from "@getpaseo/protocol/messages";
|
|
|
|
import type { TerminalCellStyleResolver } from "./colors";
|
|
|
|
const WIDE_CHAR_RANGES: ReadonlyArray<readonly [number, number]> = [
|
|
[0x1100, 0x115f],
|
|
[0x2329, 0x232a],
|
|
[0x2e80, 0xa4cf],
|
|
[0xac00, 0xd7a3],
|
|
[0xf900, 0xfaff],
|
|
[0xfe10, 0xfe19],
|
|
[0xfe30, 0xfe6f],
|
|
[0xff00, 0xff60],
|
|
[0xffe0, 0xffe6],
|
|
[0x1f300, 0x1faff],
|
|
];
|
|
|
|
export interface TerminalRun {
|
|
key: string;
|
|
text: string;
|
|
cellCount: number;
|
|
styleKey: string;
|
|
style: TextStyle;
|
|
}
|
|
|
|
export interface TerminalRowModel {
|
|
index: number;
|
|
hash: string;
|
|
runs: TerminalRun[];
|
|
}
|
|
|
|
type TerminalRenderableCell = TerminalCell & { width?: number };
|
|
|
|
function hashStringPart(hash: number, value: string): number {
|
|
let nextHash = hash;
|
|
for (let index = 0; index < value.length; index += 1) {
|
|
nextHash = Math.imul(nextHash ^ value.charCodeAt(index), 16777619);
|
|
}
|
|
return nextHash;
|
|
}
|
|
|
|
function finishHash(hash: number): string {
|
|
return (hash >>> 0).toString(36);
|
|
}
|
|
|
|
function terminalCharWidth(char: string): number {
|
|
const codePoint = char.codePointAt(0);
|
|
if (codePoint === undefined) return 1;
|
|
const isWide = WIDE_CHAR_RANGES.some(([start, end]) => codePoint >= start && codePoint <= end);
|
|
return isWide ? 2 : 1;
|
|
}
|
|
|
|
function shouldSkipSpacerCell(cells: TerminalRenderableCell[], col: number, char: string): boolean {
|
|
if (terminalCharWidth(char) < 2) {
|
|
return false;
|
|
}
|
|
return cells[col + 1]?.char === " ";
|
|
}
|
|
|
|
function terminalCellCount(cells: TerminalRenderableCell[], col: number, char: string): number {
|
|
const authoritativeWidth = cells[col]?.width;
|
|
if (authoritativeWidth !== undefined) {
|
|
return Math.max(1, authoritativeWidth);
|
|
}
|
|
if (shouldSkipSpacerCell(cells, col, char)) {
|
|
return 2;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
function appendRun(input: {
|
|
runs: TerminalRun[];
|
|
text: string;
|
|
cellCount: number;
|
|
styleKey: string;
|
|
style: TextStyle;
|
|
col: number;
|
|
}): void {
|
|
const previousRun = input.runs[input.runs.length - 1];
|
|
if (previousRun && previousRun.styleKey === input.styleKey) {
|
|
previousRun.text += input.text;
|
|
previousRun.cellCount += input.cellCount;
|
|
return;
|
|
}
|
|
|
|
input.runs.push({
|
|
key: `${input.col}:${input.styleKey}`,
|
|
text: input.text,
|
|
cellCount: input.cellCount,
|
|
styleKey: input.styleKey,
|
|
style: input.style,
|
|
});
|
|
}
|
|
|
|
function buildRowModel(input: {
|
|
cells: TerminalRenderableCell[];
|
|
index: number;
|
|
resolver: TerminalCellStyleResolver;
|
|
}): TerminalRowModel {
|
|
const runs: TerminalRun[] = [];
|
|
let hash = 2166136261;
|
|
|
|
for (let col = 0; col < input.cells.length; col += 1) {
|
|
const cell = input.cells[col];
|
|
const text = cell.char || " ";
|
|
const resolvedStyle = input.resolver.resolve(cell);
|
|
const cellCount = terminalCellCount(input.cells, col, text);
|
|
appendRun({
|
|
runs,
|
|
text,
|
|
cellCount,
|
|
styleKey: resolvedStyle.key,
|
|
style: resolvedStyle.style,
|
|
col,
|
|
});
|
|
hash = hashStringPart(hash, text);
|
|
hash = hashStringPart(hash, String(cellCount));
|
|
hash = hashStringPart(hash, resolvedStyle.key);
|
|
|
|
if (cellCount > 1) {
|
|
col += 1;
|
|
}
|
|
}
|
|
|
|
return {
|
|
index: input.index,
|
|
hash: finishHash(hash),
|
|
runs,
|
|
};
|
|
}
|
|
|
|
export function buildRows(input: {
|
|
grid: TerminalRenderableCell[][];
|
|
resolver: TerminalCellStyleResolver;
|
|
}): TerminalRowModel[] {
|
|
return input.grid.map((cells, index) =>
|
|
buildRowModel({ cells, index, resolver: input.resolver }),
|
|
);
|
|
}
|