dsh-yazi 0.2.3 → 0.2.4
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/DECISIONS.md +70 -0
- package/client.js +55 -7
- package/hero.png +0 -0
- package/package.json +1 -1
- package/src/client/main.js +12 -1
- package/src/client/terminal.js +43 -6
- package/src/host/pty.js +8 -1
package/DECISIONS.md
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
# DECISIONS
|
|
2
2
|
|
|
3
3
|
<!-- APPEND-ONLY LOG: 新条目插入到此行之后 -->
|
|
4
|
+
## DEC-033 2026-11-28 右缘仍裁一个汉字:余量加到 3 列并记录实测数字
|
|
5
|
+
|
|
6
|
+
用户复报:DEC-030 的 1 列余量把裁剪从两个汉字减到一个,但仍缺字——`wall_ms` 表格行末是 `最慢,`,下一行开头的高亮 `须` 之前应是 `必`,却没显示。
|
|
7
|
+
|
|
8
|
+
- **为什么 1 列不够**:一个 CJK 字占 **2 个单元格**。余量只有 1 列时,若一个宽字正好落在预览区最后一列,它需要的第二格已在可视区之外,于是整字被丢。真 PTY(node-pty 起真 yazi + glow -w=$w)复现确认:这是宽字落在边界的裁剪,不是字体加载竞态。
|
|
9
|
+
- **余量改为 3 列**:`PTY_COLUMN_SLACK` 从 1 增到 3,给宽字及其换行留足缓冲。Playwright + 真 xterm 实测三种视口宽度下,PTY 网格比可视区窄约 23px(3 格),足以容纳边界上的宽字。
|
|
10
|
+
- **记录实测数字**:`connecting` 诊断现在带 `gridCols / ptyCols / slack`。万一再裁字,日志会立刻告诉我们是网格、余量还是 PTY 宽度漂移,不必再次盲猜。
|
|
11
|
+
- **测试**:断言直接从源码读 `PTY_COLUMN_SLACK`(不再硬编码 1),并明确要求余量 ≥2;`make check` 200 条全绿。版本不变。
|
|
12
|
+
## DEC-032 2026-11-28 重挂时补发 cols/rows 才让 resync 生效,并修掉重复的列余量
|
|
13
|
+
|
|
14
|
+
用户在 DEC-031 修复后报告第二层症状:切回来状态确实保住了,但整屏全黑,只有按 `hl` 移动光标时被碰到的那几行才重绘。
|
|
15
|
+
|
|
16
|
+
- **根因:`resync` 从来没被发出过。** 路由只在升级请求的 query 里带整数 `cols`/`rows` 时才回 `resync`,
|
|
17
|
+
而客户端 `socketUrl(query)` 只传了 `sid`(见 `main.js` 的 `query: { sid: sessionId }`),于是那条整屏重绘路径是死代码。
|
|
18
|
+
第一层 bug 存在时它被掩盖了:切标签会杀掉 yazi,下次得到的是全新进程的完整首绘,没人需要 resync。
|
|
19
|
+
DEC-031 让进程活下来之后,重挂拿到的是一个"已经画过、且屏幕内容只在旧 xterm 里"的 yazi,新 xterm 是空白,
|
|
20
|
+
而 Host 又不发 resync → 全黑,直到按键触发局部重绘。这与用户描述逐字吻合。
|
|
21
|
+
- **修复一:开连接时就带上尺寸。** `terminal.js` 在构建 URL 前先 `fitQuietly()`,把 `term.cols - 1`、`term.rows`
|
|
22
|
+
写进 query,路由因此能发 `resync`。
|
|
23
|
+
- **修复二:resync 不再重复扣列余量。** 原先 `safeCols = cols - PTY_COLUMN_SLACK`,而 `cols` 已经是客户端扣过余量的
|
|
24
|
+
PTY 宽度;修一之后每次重挂都会再多扣一列,悄悄把 PTY 变窄、抵消 DEC-030 的一列纪律。现在 `resync` 原样采用
|
|
25
|
+
上报宽度,只做 ±1 列抖动:`cols → cols - 1 → cols`。
|
|
26
|
+
- **验证方式(关键)**:不能只看"收到字节"。用 `@xterm/headless` 在两侧各建一个**真实 xterm**,第二个从空白开始,
|
|
27
|
+
经真实路由 + 真实 `YaziSessions` + 真实 PTY + 真实 yazi 驱动,然后**逐行比对两块屏幕**:30 行全非空、逐行一致,
|
|
28
|
+
共 6/6 通过。测试过程中两个坑值得记:xterm 的 `write` 是异步的,读屏前必须等回调;以及 in-harness 若在 resync
|
|
29
|
+
之后立刻再发一次同尺寸,会把 ±1 列抖动抹平,从而假性失败(这正是真实客户端不会做的顺序,因为 `onopen` 先于 resync)。
|
|
30
|
+
- **测试先行**:`test/terminal.test.js` 新增/重写 4 条(开连接 query 必须带 cols/rows、connecting 上报的 URL 同时带
|
|
31
|
+
sid/cols/rows、resync 只抖一列并回到上报宽度、resync 不得二次扣余量),并把 `socketUrl` 测试桩改成真实反射 query
|
|
32
|
+
(否则新用例观察不到 URL)。先确认全红,改后 `make check` 200 条全绿。
|
|
33
|
+
- **代价**:客户端 2 处(开连接带尺寸、resync 去重扣列);无协议、路由、配置变化。每个重挂多一次 `fitQuietly()`,
|
|
34
|
+
本来就要在字体就绪后做一次,成本可忽略。
|
|
35
|
+
- 版本不变(补丁级修复,随下次发布)。
|
|
36
|
+
|
|
37
|
+
## DEC-031 2026-11-28 浏览器关闭 socket 只结束挂接,绝不再顺带终止 yazi
|
|
38
|
+
|
|
39
|
+
用户报告:在 yazi 标签里移动光标、进入子目录,切到别的标签再切回来,yazi 像被 reset 一样回到工作区第一个条目。
|
|
40
|
+
README 的表格本来承诺「Switch to another view tab → Socket detaches; yazi keeps running」,实际行为与文档相反。
|
|
41
|
+
|
|
42
|
+
- **根因在 Host 的 close 分支**:`YaziSessions._dispatchFrame` 收到 WebSocket `close` 帧时,除了回 echo 还调用
|
|
43
|
+
`this._terminate(entry)`。DSH 的 `conversation.view` 槽用 `{ only: viewId }` 渲染(切走即卸载),
|
|
44
|
+
面板卸载时 `terminal.dispose()` 执行 `socket.close(1000, 'panel closed')`,于是每次切标签都真的 kill 掉了 PTY。
|
|
45
|
+
下次切回来,`obtain()` 找不到活会话 → 重新 spawn 一个 yazi,cwd 仍是工作区根、光标回到第一个条目。
|
|
46
|
+
- **日志证据**:`$TMPDIR/dsh-yazi.log` 里 session `48392126…` 一个会话留下 21 组 connect→spawn 记录,
|
|
47
|
+
即 21 次切标签 = 21 个 yazi 进程,这与「一会话一 PTY」的设计直接矛盾。
|
|
48
|
+
- **修复**:close 帧只回 echo + `socket.destroy()`,挂接由 `attach()` 的 close 监听摘除;PTY 的生命周期改由
|
|
49
|
+
空闲回收(`idleMinutes`,默认 30 分钟)和显式 `kill`(工具栏「退出 yazi」)负责。这正是「一条 socket 只是一次挂接」
|
|
50
|
+
的本意,也与 README 的承诺一致。
|
|
51
|
+
- **真机端到端验证**:用 node-pty 起真 yazi(真 PTY、真 xterm 协议帧)驱动真实 `YaziSessions`,11 项检查全绿:
|
|
52
|
+
切标签后 `spawns=1` 且 `isLive=true`,返回后重绘仍是同一子目录、同一光标条目;`kill` 仍能结束会话。
|
|
53
|
+
同一套用例跑修复前代码(`/tmp/prefix-src`)得 6/11:第二只 yazi 被 spawn(`spawns=2`)、返回后画面回到
|
|
54
|
+
`alpha.txt,inner.txt` 根目录、光标落到 `sub1`——与用户描述完全一致,证明这是该 bug 而非环境问题。
|
|
55
|
+
- **测试先行**:`test/pty.test.js` 新增 3 条(close 帧不杀 PTY、重开不二次 spawn、kill 仍生效;`fakeSocket`
|
|
56
|
+
补 `destroy()` 与 `clientCloseFrame()`),`test/client.test.js` 新增 1 条(Reopen 必须先 kill)。先跑确认对应用例为红(pty 2 条、client 1 条),改后 `make check` 199 条全绿。
|
|
57
|
+
- **Reopen 必须显式 kill**:原来工具栏 Reopen 只 bump `generation`,重挂时靠「关闭 socket 会杀 PTY」顺带拿到新进程;
|
|
58
|
+
这条隐式路径被修复后不复存在,若不补,Reopen 会退化成「重连同一个 yazi」的空操作。现在视图持有一个 `killRef`
|
|
59
|
+
(`terminal.kill()`),点击时先发 `kill` 再 bump `generation`,重挂后 `obtain()` 因会话已终止而 spawn 新 yazi。
|
|
60
|
+
真机验证:kill 后 `isLive=false`,随后 obtain 得到**新 pid**并重新落在工作区根目录(4/4 通过)。
|
|
61
|
+
- **副产物是好的**:浏览器刷新/页面跳转关掉 socket 时 yazi 也不再被误杀,回来仍是原状态;真正回收靠空闲回收与插件卸载。
|
|
62
|
+
- **代价**:Host 侧 1 处分支(删 1 行加注释),客户端 Reopen 补 1 处 `killRef` 接线;无协议、配置变化,不新增进程或状态。
|
|
63
|
+
- 版本不变(补丁级修复,随下次发布)。
|
|
64
|
+
|
|
65
|
+
## DEC-030 2026-11-28 终端列数留 1 列余量,避免 yazi 右缘被裁
|
|
66
|
+
|
|
67
|
+
用户报告:yazi 视图里 README 预览的右缘被截断——`**实` 右边应是 `验期` 却看不到。根因方向:xterm 的 FitAddon 用**分数 CSS 单元格宽度**算列数(`floor(可用宽 / css.cell.width)`),而 xterm 实际按设备像素取整后的网格绘制;再叠加字体度量在挂载后才稳定(主题字体 / `@font-face`),初始算出的列数会偏大,yazi 按偏大的 PTY 列数排版,最右 1~数个字符被容器裁掉。
|
|
68
|
+
|
|
69
|
+
- **PTY 列数保留 1 列余量**:`syncSize()` 发送 `term.cols - 1` 而不是 `term.cols`;`resync` 的 ±1 列抖动同样整体下移一格。xterm 自己的网格仍是满列,yazi 少画一列,右侧永远留出一个单元格的空白,不再出现裁字。
|
|
70
|
+
- **字体就绪后重排**:挂载时挂 `document.fonts.ready.then(scheduleFit)`(带 `disposed` 守卫),字体度量稳定后再 fit 一次并把新尺寸同步给 PTY。这两件事分别覆盖「稳态余量」与「字体加载竞态」。
|
|
71
|
+
- **Playwright 实测**:在真实 xterm + FitAddon 上,2314/900/380 三种容器宽度下调 fit 后,PTY 像素宽(`ptyCols * cellW`)都比可视 `.xterm-screen` 窄约 7.8px(恰好一个单元格),`xtermOverflow` 为 0。修复前两者相等,任何取整/字体误差都会直接裁字。
|
|
72
|
+
- **测试先行**:新增 3 条断言(socket 尺寸带余量、resync 抖动保持余量、fonts.ready 触发重排),先确认全红,改后连同原有用例共 195 条全绿(`make check`)。
|
|
73
|
+
- 版本不变(补丁级修复,随下次发布)。
|
|
4
74
|
## DEC-029 2026-11-28 Yazi 视图挂载时主动聚焦终端(修复切 tab 后键盘无响应)
|
|
5
75
|
|
|
6
76
|
用户报告:切到 Yazi 标签后 yazi 不接收键盘,必须先用鼠标点一下面板。根因不是 WebSocket 或 PTY,
|
package/client.js
CHANGED
|
@@ -553,6 +553,13 @@ function reportDiagnostic(phase, detail) {
|
|
|
553
553
|
* the user clicks it. Pass false to mount without stealing focus.
|
|
554
554
|
* @returns {{ dispose: Function, resize: Function, kill: Function, send: Function, focus: Function }}
|
|
555
555
|
*/
|
|
556
|
+
// FitAddon measures the container with a fractional CSS cell width, while xterm
|
|
557
|
+
// paints on a device-pixel-rounded grid. The rightmost glyphs can land past the
|
|
558
|
+
// visible edge (a CJK glyph needs two cells, so one cell of slack is not enough
|
|
559
|
+
// when it lands at the last column). Keep a few columns in reserve so yazi's
|
|
560
|
+
// preview never paints into the clipped zone.
|
|
561
|
+
const PTY_COLUMN_SLACK = 3
|
|
562
|
+
|
|
556
563
|
function mountYaziTerminal(options) {
|
|
557
564
|
const { stage, bundle, query, notify } = options
|
|
558
565
|
const win = options.win ?? window
|
|
@@ -585,17 +592,32 @@ function mountYaziTerminal(options) {
|
|
|
585
592
|
term.loadAddon(fit)
|
|
586
593
|
term.open(stage)
|
|
587
594
|
// The panel may still be off-screen on the first frame; fit again once the
|
|
588
|
-
// layout has real dimensions.
|
|
595
|
+
// layout has real dimensions. Fit before the URL exists: the opening query
|
|
596
|
+
// has to carry the grid size, because that is what lets the Host tell a
|
|
597
|
+
// fresh yazi apart from a reattached one that already painted.
|
|
589
598
|
fitQuietly()
|
|
590
599
|
|
|
600
|
+
// The Host's `resync` (its only repaint trigger) requires cols/rows on the
|
|
601
|
+
// connection. Sending `sid` alone made that message unreachable: a returning
|
|
602
|
+
// panel found a live yazi with nothing to redraw it and stayed black until a
|
|
603
|
+
// keypress forced a partial repaint. The safe-column slack applies here too.
|
|
604
|
+
const opening = {
|
|
605
|
+
...query,
|
|
606
|
+
cols: Math.max(1, term.cols - PTY_COLUMN_SLACK),
|
|
607
|
+
rows: term.rows,
|
|
608
|
+
}
|
|
609
|
+
|
|
591
610
|
let url = ''
|
|
592
611
|
try {
|
|
593
|
-
url = socketUrl(
|
|
612
|
+
url = socketUrl(opening)
|
|
594
613
|
} catch (error) {
|
|
595
614
|
report('url-failed', { message: error?.message })
|
|
596
615
|
throw error
|
|
597
616
|
}
|
|
598
|
-
report('connecting', {
|
|
617
|
+
report('connecting', {
|
|
618
|
+
url, cwd: query?.cwd, sid: query?.sid,
|
|
619
|
+
gridCols: term.cols, ptyCols: opening.cols, slack: PTY_COLUMN_SLACK,
|
|
620
|
+
})
|
|
599
621
|
const socket = new win.WebSocket(url)
|
|
600
622
|
socket.binaryType = 'arraybuffer'
|
|
601
623
|
|
|
@@ -623,7 +645,7 @@ function mountYaziTerminal(options) {
|
|
|
623
645
|
|
|
624
646
|
function syncSize() {
|
|
625
647
|
fitQuietly()
|
|
626
|
-
send({ t: 'size', cols: term.cols, rows: term.rows })
|
|
648
|
+
send({ t: 'size', cols: Math.max(1, term.cols - PTY_COLUMN_SLACK), rows: term.rows })
|
|
627
649
|
}
|
|
628
650
|
|
|
629
651
|
function scheduleFit() {
|
|
@@ -646,8 +668,13 @@ function mountYaziTerminal(options) {
|
|
|
646
668
|
const cols = message.cols
|
|
647
669
|
const rows = message.rows
|
|
648
670
|
if (Number.isInteger(cols) && Number.isInteger(rows)) {
|
|
649
|
-
|
|
650
|
-
|
|
671
|
+
// `cols` is the PTY width this connection already reported, slack
|
|
672
|
+
// included. Detour by exactly one column to fire SIGWINCH, then settle
|
|
673
|
+
// back on it — subtracting the slack again would make every reattach
|
|
674
|
+
// one column narrower than the panel.
|
|
675
|
+
const safeCols = Math.max(2, cols)
|
|
676
|
+
send({ t: 'size', cols: Math.max(1, safeCols - 1), rows })
|
|
677
|
+
win.setTimeout(() => send({ t: 'size', cols: safeCols, rows }), 60)
|
|
651
678
|
}
|
|
652
679
|
return
|
|
653
680
|
}
|
|
@@ -732,6 +759,16 @@ function mountYaziTerminal(options) {
|
|
|
732
759
|
// the browser only routes keys to a focused element.
|
|
733
760
|
if (autoFocus) focus()
|
|
734
761
|
|
|
762
|
+
// The terminal font can arrive after mount (theme font or @font-face). When
|
|
763
|
+
// its metrics settle, xterm recalculates the cell size without changing the
|
|
764
|
+
// container: re-fit here so the grid never stays wider than the view.
|
|
765
|
+
const fonts = win.document?.fonts
|
|
766
|
+
if (fonts && typeof fonts.ready?.then === 'function') {
|
|
767
|
+
void fonts.ready.then(() => {
|
|
768
|
+
if (!disposed) scheduleFit()
|
|
769
|
+
})
|
|
770
|
+
}
|
|
771
|
+
|
|
735
772
|
if (typeof win.ResizeObserver === 'function') {
|
|
736
773
|
observer = new win.ResizeObserver(scheduleFit)
|
|
737
774
|
observer.observe(stage)
|
|
@@ -820,6 +857,9 @@ window.__ModuleLoader__.load({
|
|
|
820
857
|
// mirrored live, so toggling one never needs a page reload.
|
|
821
858
|
const [options, setOptions] = React.useState(() => readPanelOptions(form))
|
|
822
859
|
const focusRef = React.useRef(null)
|
|
860
|
+
// Ending the PTY is an explicit act now: a socket close only detaches the
|
|
861
|
+
// panel, so Reopen must ask the Host for a fresh yazi itself.
|
|
862
|
+
const killRef = React.useRef(null)
|
|
823
863
|
const [serverEpoch, setServerEpoch] = React.useState(null)
|
|
824
864
|
|
|
825
865
|
// A Host restart rebuilds its routes, so a long-lived page must reconnect
|
|
@@ -922,9 +962,11 @@ window.__ModuleLoader__.load({
|
|
|
922
962
|
}
|
|
923
963
|
|
|
924
964
|
focusRef.current = () => terminal.focus()
|
|
965
|
+
killRef.current = () => terminal.kill()
|
|
925
966
|
|
|
926
967
|
return () => {
|
|
927
968
|
focusRef.current = null
|
|
969
|
+
killRef.current = null
|
|
928
970
|
terminal.dispose()
|
|
929
971
|
}
|
|
930
972
|
}, [generation, sessionId, projected, serverEpoch])
|
|
@@ -948,7 +990,13 @@ window.__ModuleLoader__.load({
|
|
|
948
990
|
key: 'restart',
|
|
949
991
|
type: 'button',
|
|
950
992
|
className: 'dshyz-btn',
|
|
951
|
-
|
|
993
|
+
// Kill first: the remount only detaches and reattaches, so without
|
|
994
|
+
// an explicit kill Reopen would show the same yazi again instead of
|
|
995
|
+
// the fresh one the label promises.
|
|
996
|
+
onClick: () => {
|
|
997
|
+
killRef.current?.()
|
|
998
|
+
setGeneration((n) => n + 1)
|
|
999
|
+
},
|
|
952
1000
|
}, t('panel.restart')),
|
|
953
1001
|
]),
|
|
954
1002
|
h('div', { key: 'stage', className: 'dshyz-stage' }, [
|
package/hero.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/client/main.js
CHANGED
|
@@ -45,6 +45,9 @@ window.__ModuleLoader__.load({
|
|
|
45
45
|
// mirrored live, so toggling one never needs a page reload.
|
|
46
46
|
const [options, setOptions] = React.useState(() => readPanelOptions(form))
|
|
47
47
|
const focusRef = React.useRef(null)
|
|
48
|
+
// Ending the PTY is an explicit act now: a socket close only detaches the
|
|
49
|
+
// panel, so Reopen must ask the Host for a fresh yazi itself.
|
|
50
|
+
const killRef = React.useRef(null)
|
|
48
51
|
const [serverEpoch, setServerEpoch] = React.useState(null)
|
|
49
52
|
|
|
50
53
|
// A Host restart rebuilds its routes, so a long-lived page must reconnect
|
|
@@ -147,9 +150,11 @@ window.__ModuleLoader__.load({
|
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
focusRef.current = () => terminal.focus()
|
|
153
|
+
killRef.current = () => terminal.kill()
|
|
150
154
|
|
|
151
155
|
return () => {
|
|
152
156
|
focusRef.current = null
|
|
157
|
+
killRef.current = null
|
|
153
158
|
terminal.dispose()
|
|
154
159
|
}
|
|
155
160
|
}, [generation, sessionId, projected, serverEpoch])
|
|
@@ -173,7 +178,13 @@ window.__ModuleLoader__.load({
|
|
|
173
178
|
key: 'restart',
|
|
174
179
|
type: 'button',
|
|
175
180
|
className: 'dshyz-btn',
|
|
176
|
-
|
|
181
|
+
// Kill first: the remount only detaches and reattaches, so without
|
|
182
|
+
// an explicit kill Reopen would show the same yazi again instead of
|
|
183
|
+
// the fresh one the label promises.
|
|
184
|
+
onClick: () => {
|
|
185
|
+
killRef.current?.()
|
|
186
|
+
setGeneration((n) => n + 1)
|
|
187
|
+
},
|
|
177
188
|
}, t('panel.restart')),
|
|
178
189
|
]),
|
|
179
190
|
h('div', { key: 'stage', className: 'dshyz-stage' }, [
|
package/src/client/terminal.js
CHANGED
|
@@ -24,6 +24,13 @@
|
|
|
24
24
|
* the user clicks it. Pass false to mount without stealing focus.
|
|
25
25
|
* @returns {{ dispose: Function, resize: Function, kill: Function, send: Function, focus: Function }}
|
|
26
26
|
*/
|
|
27
|
+
// FitAddon measures the container with a fractional CSS cell width, while xterm
|
|
28
|
+
// paints on a device-pixel-rounded grid. The rightmost glyphs can land past the
|
|
29
|
+
// visible edge (a CJK glyph needs two cells, so one cell of slack is not enough
|
|
30
|
+
// when it lands at the last column). Keep a few columns in reserve so yazi's
|
|
31
|
+
// preview never paints into the clipped zone.
|
|
32
|
+
const PTY_COLUMN_SLACK = 3
|
|
33
|
+
|
|
27
34
|
function mountYaziTerminal(options) {
|
|
28
35
|
const { stage, bundle, query, notify } = options
|
|
29
36
|
const win = options.win ?? window
|
|
@@ -56,17 +63,32 @@ function mountYaziTerminal(options) {
|
|
|
56
63
|
term.loadAddon(fit)
|
|
57
64
|
term.open(stage)
|
|
58
65
|
// The panel may still be off-screen on the first frame; fit again once the
|
|
59
|
-
// layout has real dimensions.
|
|
66
|
+
// layout has real dimensions. Fit before the URL exists: the opening query
|
|
67
|
+
// has to carry the grid size, because that is what lets the Host tell a
|
|
68
|
+
// fresh yazi apart from a reattached one that already painted.
|
|
60
69
|
fitQuietly()
|
|
61
70
|
|
|
71
|
+
// The Host's `resync` (its only repaint trigger) requires cols/rows on the
|
|
72
|
+
// connection. Sending `sid` alone made that message unreachable: a returning
|
|
73
|
+
// panel found a live yazi with nothing to redraw it and stayed black until a
|
|
74
|
+
// keypress forced a partial repaint. The safe-column slack applies here too.
|
|
75
|
+
const opening = {
|
|
76
|
+
...query,
|
|
77
|
+
cols: Math.max(1, term.cols - PTY_COLUMN_SLACK),
|
|
78
|
+
rows: term.rows,
|
|
79
|
+
}
|
|
80
|
+
|
|
62
81
|
let url = ''
|
|
63
82
|
try {
|
|
64
|
-
url = socketUrl(
|
|
83
|
+
url = socketUrl(opening)
|
|
65
84
|
} catch (error) {
|
|
66
85
|
report('url-failed', { message: error?.message })
|
|
67
86
|
throw error
|
|
68
87
|
}
|
|
69
|
-
report('connecting', {
|
|
88
|
+
report('connecting', {
|
|
89
|
+
url, cwd: query?.cwd, sid: query?.sid,
|
|
90
|
+
gridCols: term.cols, ptyCols: opening.cols, slack: PTY_COLUMN_SLACK,
|
|
91
|
+
})
|
|
70
92
|
const socket = new win.WebSocket(url)
|
|
71
93
|
socket.binaryType = 'arraybuffer'
|
|
72
94
|
|
|
@@ -94,7 +116,7 @@ function mountYaziTerminal(options) {
|
|
|
94
116
|
|
|
95
117
|
function syncSize() {
|
|
96
118
|
fitQuietly()
|
|
97
|
-
send({ t: 'size', cols: term.cols, rows: term.rows })
|
|
119
|
+
send({ t: 'size', cols: Math.max(1, term.cols - PTY_COLUMN_SLACK), rows: term.rows })
|
|
98
120
|
}
|
|
99
121
|
|
|
100
122
|
function scheduleFit() {
|
|
@@ -117,8 +139,13 @@ function mountYaziTerminal(options) {
|
|
|
117
139
|
const cols = message.cols
|
|
118
140
|
const rows = message.rows
|
|
119
141
|
if (Number.isInteger(cols) && Number.isInteger(rows)) {
|
|
120
|
-
|
|
121
|
-
|
|
142
|
+
// `cols` is the PTY width this connection already reported, slack
|
|
143
|
+
// included. Detour by exactly one column to fire SIGWINCH, then settle
|
|
144
|
+
// back on it — subtracting the slack again would make every reattach
|
|
145
|
+
// one column narrower than the panel.
|
|
146
|
+
const safeCols = Math.max(2, cols)
|
|
147
|
+
send({ t: 'size', cols: Math.max(1, safeCols - 1), rows })
|
|
148
|
+
win.setTimeout(() => send({ t: 'size', cols: safeCols, rows }), 60)
|
|
122
149
|
}
|
|
123
150
|
return
|
|
124
151
|
}
|
|
@@ -203,6 +230,16 @@ function mountYaziTerminal(options) {
|
|
|
203
230
|
// the browser only routes keys to a focused element.
|
|
204
231
|
if (autoFocus) focus()
|
|
205
232
|
|
|
233
|
+
// The terminal font can arrive after mount (theme font or @font-face). When
|
|
234
|
+
// its metrics settle, xterm recalculates the cell size without changing the
|
|
235
|
+
// container: re-fit here so the grid never stays wider than the view.
|
|
236
|
+
const fonts = win.document?.fonts
|
|
237
|
+
if (fonts && typeof fonts.ready?.then === 'function') {
|
|
238
|
+
void fonts.ready.then(() => {
|
|
239
|
+
if (!disposed) scheduleFit()
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
|
|
206
243
|
if (typeof win.ResizeObserver === 'function') {
|
|
207
244
|
observer = new win.ResizeObserver(scheduleFit)
|
|
208
245
|
observer.observe(stage)
|
package/src/host/pty.js
CHANGED
|
@@ -169,8 +169,15 @@ export class YaziSessions {
|
|
|
169
169
|
}
|
|
170
170
|
if (frame.type === 'pong') return
|
|
171
171
|
if (frame.type === 'close') {
|
|
172
|
+
// A socket close ends an ATTACHMENT, not the process. DSH renders the
|
|
173
|
+
// selected view with `{ only: viewId }`, so switching to another tab
|
|
174
|
+
// unmounts the panel and the browser closes its socket with 1000 —
|
|
175
|
+
// terminating here would kill yazi on every tab switch and the next visit
|
|
176
|
+
// would spawn a fresh one at the workspace root, losing the directory and
|
|
177
|
+
// cursor the one-PTY-per-session design exists to keep. Echo the close and
|
|
178
|
+
// release the socket; the 'close' handler in attach() detaches it, and the
|
|
179
|
+
// idle reaper or `kill` (the toolbar's Quit yazi) is what ends yazi.
|
|
172
180
|
writeSocket(socket, encodeFrame(OPCODES.close, frame.code ?? CLOSE_CODES.normal))
|
|
173
|
-
this._terminate(entry)
|
|
174
181
|
socket.destroy?.()
|
|
175
182
|
}
|
|
176
183
|
}
|