dsh-yazi 0.2.2 → 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 +106 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/client.js +91 -15
- package/hero.png +0 -0
- package/package.json +2 -1
- package/src/client/main.js +19 -1
- package/src/client/terminal.js +72 -14
- package/src/host/pty.js +8 -1
package/DECISIONS.md
CHANGED
|
@@ -1,6 +1,112 @@
|
|
|
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
|
+
- 版本不变(补丁级修复,随下次发布)。
|
|
74
|
+
## DEC-029 2026-11-28 Yazi 视图挂载时主动聚焦终端(修复切 tab 后键盘无响应)
|
|
75
|
+
|
|
76
|
+
用户报告:切到 Yazi 标签后 yazi 不接收键盘,必须先用鼠标点一下面板。根因不是 WebSocket 或 PTY,
|
|
77
|
+
而是浏览器焦点:`mountYaziTerminal` 只调用 `term.open(stage)`,而 xterm 的 `open()` 不会移动焦点。
|
|
78
|
+
|
|
79
|
+
- **实测证据**:用 Playwright + 真 Chrome 跑同一段 xterm 代码,先让一个 composer 类元素持有焦点再
|
|
80
|
+
`open()`,`document.activeElement` 仍是那个元素;此时敲 `abc`,字符全部落进 composer
|
|
81
|
+
(`oldTyped: "|composer:abc"`)。改成 `open()` 后显式 `term.focus()`,焦点落到
|
|
82
|
+
`.xterm-helper-textarea`,`abc` 进入终端且 composer 保持空(`composerUntouched: true`)。
|
|
83
|
+
- **为什么之前"点一下就好"**:鼠标点击落在 xterm 的 helper textarea 上,是浏览器默认行为替我们做了
|
|
84
|
+
这件事。焦点本来就没有交给终端,点击只是补上了缺失的那一步。
|
|
85
|
+
- **为什么必须挂载时聚焦**:DSH 的 `conversation.view` 槽位用 `{ only: viewId }` 渲染(见
|
|
86
|
+
dsh-client-ui-renderer),切走即卸载、切回即重新挂载。所以"只在 ready 后聚焦一次"会漏掉
|
|
87
|
+
第二次切回;挂在挂载路径上才与卸载/挂载的节奏一致。
|
|
88
|
+
- **在 greeting 之前聚焦,不等到 ready**:终端对象在 `open()` 后就接受按键,早聚焦可以避免
|
|
89
|
+
yazi 还在绘制时敲的键落进 composer。已有测试断言 greeting 不会二次聚焦。
|
|
90
|
+
- **`autoFocus` 是参数而非硬编码**:默认 `true`,传 `false` 可挂载但不抢焦点。这样"切过去只是想
|
|
91
|
+
看 yazi 状态、不想打字"的场景仍有出口,也让测试能分别验证两条路径。
|
|
92
|
+
- **`focus()` 收敛为一个函数**:原先返回对象里的内联 `focus` 与新增的挂载路径会各写一份,合并成
|
|
93
|
+
模块内 `focus()`,并统一加 `disposed` 守卫——否则 dispose 后调用会对已销毁的终端操作。
|
|
94
|
+
- **测试**:新增 5 条(挂载即聚焦、greeting 不二次聚焦、dispose 后不聚焦、`autoFocus: false`
|
|
95
|
+
不抢焦点、视图确实传 `autoFocus: true` 的产物断言)。先跑确认 3 条 focus 用例因行为缺失而红,
|
|
96
|
+
改后 194 条全绿(`make check`)。
|
|
97
|
+
- 版本不变(补丁级修复,随下次发布)。
|
|
98
|
+
|
|
99
|
+
## DEC-028 2026-11-27 统一 README hero 图约定:hero.png(PNG / 根目录 / README 引用 / files 收录)
|
|
100
|
+
|
|
101
|
+
用户要求把 hero 图统一到约定:文件名恰好为 `hero.png`、PNG 格式、位于仓库根目录、由 README.md 与 README.zh.md 以 `./hero.png` 引用,并收录进 package.json 的 `files`。
|
|
102
|
+
|
|
103
|
+
- **用 `git mv` 而非删除+新增**:`git mv hero-yazi.png hero.png` 保留文件历史,避免产生「删旧建新」的假象,符合同类资源替换(DEC-020 图标换 WebP)一贯做法。
|
|
104
|
+
- **格式与位置**:原文件已是合法 PNG(1536×656、8-bit RGB,PNG magic bytes `89 50 4E 47 0D 0A 1A 0A`),无需转码;仅改名为 `hero.png` 并留在仓库根目录。
|
|
105
|
+
- **引用点**:README.md 与 README.zh.md 的 hero 图引用都从 `./hero-yazi.png` 改为 `./hero.png`,alt 文案保持 `dsh-yazi hero` 不变(中立且简单)。全仓 grep 确认只有这两处引用 hero 图。
|
|
106
|
+
- **随包发布**:package.json 的 `files` 数组新增 `hero.png`(放在 `icon.webp` 之后),确保 npm 包内带上这张图,README 在 registry 上的图片链接可用。
|
|
107
|
+
- **测试先行**:新增 `test/hero.test.js`(4 条),断言 hero.png 存在且带 PNG magic bytes、旧名 hero-yazi.png 已消失、两份 README 都引用 `./hero.png` 且不出现旧名、package.json 收录 `hero.png` 且不收录旧名。改前先跑确认 4 条全红(行为缺失,非环境问题),改后全绿。
|
|
108
|
+
- 测试:`make test`(node --test)全部通过。
|
|
109
|
+
|
|
4
110
|
## DEC-027 2026-11-27 ⛔️ 进入 worktree 后 yazi 仍打开工作区路径(取代: DEC-004 的解析顺序)
|
|
5
111
|
|
|
6
112
|
用户报告:会话当场处于 worktree 时,yazi 打开的是 worktree 目录,这是错的,应该打开工作区自身的路径。
|
package/README.md
CHANGED
package/README.zh.md
CHANGED
package/client.js
CHANGED
|
@@ -547,11 +547,23 @@ function reportDiagnostic(phase, detail) {
|
|
|
547
547
|
* { type: 'error', kind }
|
|
548
548
|
* { type: 'closed' }
|
|
549
549
|
* @param options.win Window-like object (defaults to `window`).
|
|
550
|
-
* @
|
|
550
|
+
* @param options.autoFocus
|
|
551
|
+
* Take the keyboard on mount. Defaults to true: DSH renders a view without
|
|
552
|
+
* moving focus into it, so without this the panel is visible but deaf until
|
|
553
|
+
* the user clicks it. Pass false to mount without stealing focus.
|
|
554
|
+
* @returns {{ dispose: Function, resize: Function, kill: Function, send: Function, focus: Function }}
|
|
551
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
|
+
|
|
552
563
|
function mountYaziTerminal(options) {
|
|
553
564
|
const { stage, bundle, query, notify } = options
|
|
554
565
|
const win = options.win ?? window
|
|
566
|
+
const autoFocus = options.autoFocus !== false
|
|
555
567
|
const { Terminal, FitAddon } = bundle
|
|
556
568
|
// assets.js supplies the reporter in the built bundle; a unit test may load
|
|
557
569
|
// this file alone, so the reference is guarded rather than assumed.
|
|
@@ -580,17 +592,32 @@ function mountYaziTerminal(options) {
|
|
|
580
592
|
term.loadAddon(fit)
|
|
581
593
|
term.open(stage)
|
|
582
594
|
// The panel may still be off-screen on the first frame; fit again once the
|
|
583
|
-
// 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.
|
|
584
598
|
fitQuietly()
|
|
585
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
|
+
|
|
586
610
|
let url = ''
|
|
587
611
|
try {
|
|
588
|
-
url = socketUrl(
|
|
612
|
+
url = socketUrl(opening)
|
|
589
613
|
} catch (error) {
|
|
590
614
|
report('url-failed', { message: error?.message })
|
|
591
615
|
throw error
|
|
592
616
|
}
|
|
593
|
-
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
|
+
})
|
|
594
621
|
const socket = new win.WebSocket(url)
|
|
595
622
|
socket.binaryType = 'arraybuffer'
|
|
596
623
|
|
|
@@ -618,7 +645,7 @@ function mountYaziTerminal(options) {
|
|
|
618
645
|
|
|
619
646
|
function syncSize() {
|
|
620
647
|
fitQuietly()
|
|
621
|
-
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 })
|
|
622
649
|
}
|
|
623
650
|
|
|
624
651
|
function scheduleFit() {
|
|
@@ -641,8 +668,13 @@ function mountYaziTerminal(options) {
|
|
|
641
668
|
const cols = message.cols
|
|
642
669
|
const rows = message.rows
|
|
643
670
|
if (Number.isInteger(cols) && Number.isInteger(rows)) {
|
|
644
|
-
|
|
645
|
-
|
|
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)
|
|
646
678
|
}
|
|
647
679
|
return
|
|
648
680
|
}
|
|
@@ -705,6 +737,38 @@ function mountYaziTerminal(options) {
|
|
|
705
737
|
|
|
706
738
|
const inputSubscription = term.onData((data) => send({ t: 'in', d: data }))
|
|
707
739
|
|
|
740
|
+
/**
|
|
741
|
+
* Give the keyboard to the terminal.
|
|
742
|
+
*
|
|
743
|
+
* xterm's `focus()` targets its hidden helper textarea, which is what makes
|
|
744
|
+
* keystrokes reach the PTY. DSH itself never moves focus into a view it just
|
|
745
|
+
* rendered, so this is the panel's own job — the shortcut path and the mount
|
|
746
|
+
* path both end up here.
|
|
747
|
+
*/
|
|
748
|
+
function focus() {
|
|
749
|
+
if (disposed) return
|
|
750
|
+
try {
|
|
751
|
+
term.focus?.()
|
|
752
|
+
} catch {
|
|
753
|
+
// A disposed terminal has nothing to focus.
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// Take the keyboard as soon as the panel exists rather than waiting for the
|
|
758
|
+
// greeting: typing while yazi is still painting should not be dropped, and
|
|
759
|
+
// the browser only routes keys to a focused element.
|
|
760
|
+
if (autoFocus) focus()
|
|
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
|
+
|
|
708
772
|
if (typeof win.ResizeObserver === 'function') {
|
|
709
773
|
observer = new win.ResizeObserver(scheduleFit)
|
|
710
774
|
observer.observe(stage)
|
|
@@ -716,13 +780,7 @@ function mountYaziTerminal(options) {
|
|
|
716
780
|
return {
|
|
717
781
|
resize: scheduleFit,
|
|
718
782
|
send,
|
|
719
|
-
focus
|
|
720
|
-
try {
|
|
721
|
-
term.focus?.()
|
|
722
|
-
} catch {
|
|
723
|
-
// A disposed terminal has nothing to focus.
|
|
724
|
-
}
|
|
725
|
-
},
|
|
783
|
+
focus,
|
|
726
784
|
kill() {
|
|
727
785
|
send({ t: 'kill' })
|
|
728
786
|
},
|
|
@@ -799,6 +857,9 @@ window.__ModuleLoader__.load({
|
|
|
799
857
|
// mirrored live, so toggling one never needs a page reload.
|
|
800
858
|
const [options, setOptions] = React.useState(() => readPanelOptions(form))
|
|
801
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)
|
|
802
863
|
const [serverEpoch, setServerEpoch] = React.useState(null)
|
|
803
864
|
|
|
804
865
|
// A Host restart rebuilds its routes, so a long-lived page must reconnect
|
|
@@ -868,6 +929,13 @@ window.__ModuleLoader__.load({
|
|
|
868
929
|
// No cwd hint: the Host reads the session's workspace itself. A
|
|
869
930
|
// hint from here would be the live directory, i.e. the worktree.
|
|
870
931
|
query: { sid: sessionId },
|
|
932
|
+
// Selecting the Yazi tab mounts this view, and DSH moves no focus
|
|
933
|
+
// into a view it just rendered — so without this the panel showed
|
|
934
|
+
// yazi but ignored the keyboard until the user clicked it. Safe to
|
|
935
|
+
// take focus here: this effect only runs while the panel is the
|
|
936
|
+
// selected view, so the composer it might otherwise steal from is
|
|
937
|
+
// not on screen.
|
|
938
|
+
autoFocus: true,
|
|
871
939
|
notify(event) {
|
|
872
940
|
if (event.type === 'connecting') return
|
|
873
941
|
if (event.type === 'ready') {
|
|
@@ -894,9 +962,11 @@ window.__ModuleLoader__.load({
|
|
|
894
962
|
}
|
|
895
963
|
|
|
896
964
|
focusRef.current = () => terminal.focus()
|
|
965
|
+
killRef.current = () => terminal.kill()
|
|
897
966
|
|
|
898
967
|
return () => {
|
|
899
968
|
focusRef.current = null
|
|
969
|
+
killRef.current = null
|
|
900
970
|
terminal.dispose()
|
|
901
971
|
}
|
|
902
972
|
}, [generation, sessionId, projected, serverEpoch])
|
|
@@ -920,7 +990,13 @@ window.__ModuleLoader__.load({
|
|
|
920
990
|
key: 'restart',
|
|
921
991
|
type: 'button',
|
|
922
992
|
className: 'dshyz-btn',
|
|
923
|
-
|
|
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
|
+
},
|
|
924
1000
|
}, t('panel.restart')),
|
|
925
1001
|
]),
|
|
926
1002
|
h('div', { key: 'stage', className: 'dshyz-stage' }, [
|
package/hero.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-yazi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Adds a Yazi tab to the navigation bar that runs the local yazi file manager in a real PTY inside the main panel.",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"cordis.patch.yml",
|
|
19
19
|
"locale/*.json",
|
|
20
20
|
"icon.webp",
|
|
21
|
+
"hero.png",
|
|
21
22
|
"README.md",
|
|
22
23
|
"DECISIONS.md"
|
|
23
24
|
],
|
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
|
|
@@ -114,6 +117,13 @@ window.__ModuleLoader__.load({
|
|
|
114
117
|
// No cwd hint: the Host reads the session's workspace itself. A
|
|
115
118
|
// hint from here would be the live directory, i.e. the worktree.
|
|
116
119
|
query: { sid: sessionId },
|
|
120
|
+
// Selecting the Yazi tab mounts this view, and DSH moves no focus
|
|
121
|
+
// into a view it just rendered — so without this the panel showed
|
|
122
|
+
// yazi but ignored the keyboard until the user clicked it. Safe to
|
|
123
|
+
// take focus here: this effect only runs while the panel is the
|
|
124
|
+
// selected view, so the composer it might otherwise steal from is
|
|
125
|
+
// not on screen.
|
|
126
|
+
autoFocus: true,
|
|
117
127
|
notify(event) {
|
|
118
128
|
if (event.type === 'connecting') return
|
|
119
129
|
if (event.type === 'ready') {
|
|
@@ -140,9 +150,11 @@ window.__ModuleLoader__.load({
|
|
|
140
150
|
}
|
|
141
151
|
|
|
142
152
|
focusRef.current = () => terminal.focus()
|
|
153
|
+
killRef.current = () => terminal.kill()
|
|
143
154
|
|
|
144
155
|
return () => {
|
|
145
156
|
focusRef.current = null
|
|
157
|
+
killRef.current = null
|
|
146
158
|
terminal.dispose()
|
|
147
159
|
}
|
|
148
160
|
}, [generation, sessionId, projected, serverEpoch])
|
|
@@ -166,7 +178,13 @@ window.__ModuleLoader__.load({
|
|
|
166
178
|
key: 'restart',
|
|
167
179
|
type: 'button',
|
|
168
180
|
className: 'dshyz-btn',
|
|
169
|
-
|
|
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
|
+
},
|
|
170
188
|
}, t('panel.restart')),
|
|
171
189
|
]),
|
|
172
190
|
h('div', { key: 'stage', className: 'dshyz-stage' }, [
|
package/src/client/terminal.js
CHANGED
|
@@ -18,11 +18,23 @@
|
|
|
18
18
|
* { type: 'error', kind }
|
|
19
19
|
* { type: 'closed' }
|
|
20
20
|
* @param options.win Window-like object (defaults to `window`).
|
|
21
|
-
* @
|
|
21
|
+
* @param options.autoFocus
|
|
22
|
+
* Take the keyboard on mount. Defaults to true: DSH renders a view without
|
|
23
|
+
* moving focus into it, so without this the panel is visible but deaf until
|
|
24
|
+
* the user clicks it. Pass false to mount without stealing focus.
|
|
25
|
+
* @returns {{ dispose: Function, resize: Function, kill: Function, send: Function, focus: Function }}
|
|
22
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
|
+
|
|
23
34
|
function mountYaziTerminal(options) {
|
|
24
35
|
const { stage, bundle, query, notify } = options
|
|
25
36
|
const win = options.win ?? window
|
|
37
|
+
const autoFocus = options.autoFocus !== false
|
|
26
38
|
const { Terminal, FitAddon } = bundle
|
|
27
39
|
// assets.js supplies the reporter in the built bundle; a unit test may load
|
|
28
40
|
// this file alone, so the reference is guarded rather than assumed.
|
|
@@ -51,17 +63,32 @@ function mountYaziTerminal(options) {
|
|
|
51
63
|
term.loadAddon(fit)
|
|
52
64
|
term.open(stage)
|
|
53
65
|
// The panel may still be off-screen on the first frame; fit again once the
|
|
54
|
-
// 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.
|
|
55
69
|
fitQuietly()
|
|
56
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
|
+
|
|
57
81
|
let url = ''
|
|
58
82
|
try {
|
|
59
|
-
url = socketUrl(
|
|
83
|
+
url = socketUrl(opening)
|
|
60
84
|
} catch (error) {
|
|
61
85
|
report('url-failed', { message: error?.message })
|
|
62
86
|
throw error
|
|
63
87
|
}
|
|
64
|
-
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
|
+
})
|
|
65
92
|
const socket = new win.WebSocket(url)
|
|
66
93
|
socket.binaryType = 'arraybuffer'
|
|
67
94
|
|
|
@@ -89,7 +116,7 @@ function mountYaziTerminal(options) {
|
|
|
89
116
|
|
|
90
117
|
function syncSize() {
|
|
91
118
|
fitQuietly()
|
|
92
|
-
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 })
|
|
93
120
|
}
|
|
94
121
|
|
|
95
122
|
function scheduleFit() {
|
|
@@ -112,8 +139,13 @@ function mountYaziTerminal(options) {
|
|
|
112
139
|
const cols = message.cols
|
|
113
140
|
const rows = message.rows
|
|
114
141
|
if (Number.isInteger(cols) && Number.isInteger(rows)) {
|
|
115
|
-
|
|
116
|
-
|
|
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)
|
|
117
149
|
}
|
|
118
150
|
return
|
|
119
151
|
}
|
|
@@ -176,6 +208,38 @@ function mountYaziTerminal(options) {
|
|
|
176
208
|
|
|
177
209
|
const inputSubscription = term.onData((data) => send({ t: 'in', d: data }))
|
|
178
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Give the keyboard to the terminal.
|
|
213
|
+
*
|
|
214
|
+
* xterm's `focus()` targets its hidden helper textarea, which is what makes
|
|
215
|
+
* keystrokes reach the PTY. DSH itself never moves focus into a view it just
|
|
216
|
+
* rendered, so this is the panel's own job — the shortcut path and the mount
|
|
217
|
+
* path both end up here.
|
|
218
|
+
*/
|
|
219
|
+
function focus() {
|
|
220
|
+
if (disposed) return
|
|
221
|
+
try {
|
|
222
|
+
term.focus?.()
|
|
223
|
+
} catch {
|
|
224
|
+
// A disposed terminal has nothing to focus.
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Take the keyboard as soon as the panel exists rather than waiting for the
|
|
229
|
+
// greeting: typing while yazi is still painting should not be dropped, and
|
|
230
|
+
// the browser only routes keys to a focused element.
|
|
231
|
+
if (autoFocus) focus()
|
|
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
|
+
|
|
179
243
|
if (typeof win.ResizeObserver === 'function') {
|
|
180
244
|
observer = new win.ResizeObserver(scheduleFit)
|
|
181
245
|
observer.observe(stage)
|
|
@@ -187,13 +251,7 @@ function mountYaziTerminal(options) {
|
|
|
187
251
|
return {
|
|
188
252
|
resize: scheduleFit,
|
|
189
253
|
send,
|
|
190
|
-
focus
|
|
191
|
-
try {
|
|
192
|
-
term.focus?.()
|
|
193
|
-
} catch {
|
|
194
|
-
// A disposed terminal has nothing to focus.
|
|
195
|
-
}
|
|
196
|
-
},
|
|
254
|
+
focus,
|
|
197
255
|
kill() {
|
|
198
256
|
send({ t: 'kill' })
|
|
199
257
|
},
|
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
|
}
|