pi-sakura-cyberdeck 1.5.3 → 1.5.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/CHANGELOG.md +102 -0
- package/README.md +18 -12
- package/README.zh-CN.md +2 -2
- package/extensions/changelog/index.ts +186 -42
- package/extensions/claude-shimmer/index.ts +336 -140
- package/extensions/header/index.ts +84 -41
- package/extensions/matrix/index.ts +221 -69
- package/extensions/shared/color.ts +90 -36
- package/extensions/shared/config-file.ts +324 -0
- package/extensions/shared/tui-context.ts +78 -0
- package/extensions/zentui/config.ts +87 -128
- package/extensions/zentui/extension-status.ts +158 -19
- package/extensions/zentui/footer-format.ts +279 -85
- package/extensions/zentui/footer-segments.ts +630 -0
- package/extensions/zentui/footer.ts +668 -525
- package/extensions/zentui/format.ts +43 -19
- package/extensions/zentui/git.ts +362 -167
- package/extensions/zentui/gradient.ts +100 -50
- package/extensions/zentui/index.ts +172 -59
- package/extensions/zentui/live-context.ts +2 -1
- package/extensions/zentui/package-version.ts +102 -14
- package/extensions/zentui/project-refresh.ts +42 -20
- package/extensions/zentui/project-state.ts +2 -2
- package/extensions/zentui/runtime.ts +140 -51
- package/extensions/zentui/selector-border.ts +96 -16
- package/extensions/zentui/session-lifecycle.ts +3 -1
- package/extensions/zentui/settings-command.ts +403 -245
- package/extensions/zentui/shell-call.ts +140 -26
- package/extensions/zentui/style.ts +109 -40
- package/extensions/zentui/thinking-trail.ts +129 -17
- package/extensions/zentui/tool-execution.ts +144 -64
- package/extensions/zentui/ui.ts +698 -145
- package/extensions/zentui/user-message.ts +24 -12
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,108 @@
|
|
|
3
3
|
All notable changes to pi-sakura-cyberdeck. Pi >= 1.5.0 shows new package entries
|
|
4
4
|
once after updating; run `/sakura-changelog` on any supported Pi to read this file.
|
|
5
5
|
|
|
6
|
+
## [1.5.4] - 2026-12-03
|
|
7
|
+
|
|
8
|
+
### Highlights
|
|
9
|
+
|
|
10
|
+
- **Full Pi 1.7.0 compatibility**: honors Pi's `readonly string[]` render contract and `Container`
|
|
11
|
+
frame-identity caching, adapts `/zentui` to Pi 1.7.0's lowercase keybinding-driven `SettingsList`
|
|
12
|
+
hints, adds mouse and keybinding support to dialogs, and resolves config paths lazily for
|
|
13
|
+
`--agent-dir`.
|
|
14
|
+
- **Faster rendering & non-blocking probes**: identity-preserving frame caches for the footer,
|
|
15
|
+
editor and selector borders, gradient/style caching with SGR coalescing, linear parsing for custom
|
|
16
|
+
footer formats and Thought trails, and fully async git, runtime and package-version probes with
|
|
17
|
+
cancellation.
|
|
18
|
+
- **Hardened persistence & lifecycle**: atomic symlink- and size-guarded config saves, live `/theme`
|
|
19
|
+
switches without restarting Pi, BiDi/SGR sanitization for extension statuses, and zero hanging
|
|
20
|
+
timers across all five extensions.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Mouse and keybinding support in interactive dialogs:
|
|
25
|
+
- `/zentui` settings modal supports clicking section tabs, clicking list items and mouse-wheel
|
|
26
|
+
scrolling with overscroll containment.
|
|
27
|
+
- `/sakura-changelog` supports mouse-wheel scrolling, `Ctrl+C` close and Pi's `tui.select.*`
|
|
28
|
+
keybindings.
|
|
29
|
+
- Atomic JSON config persistence (`extensions/shared/config-file.ts`) with automatic parent
|
|
30
|
+
directory creation, symlink and file-mode preservation, pre-read regular-file and size guards,
|
|
31
|
+
`fsync` + atomic rename and rollback on failure; corrupt config files are never overwritten.
|
|
32
|
+
- Shared TUI context and color-math utilities (`extensions/shared/tui-context.ts`) unifying
|
|
33
|
+
interactive TUI gating, finite width normalization and gradient interpolation across all
|
|
34
|
+
extensions.
|
|
35
|
+
|
|
36
|
+
### Performance
|
|
37
|
+
|
|
38
|
+
- **Identity-preserving render caches**: static footer renders, `PolishedEditor`,
|
|
39
|
+
`WrappedPolishedEditor` and selector border wrappers reuse cached line arrays on unchanged frames
|
|
40
|
+
so Pi 1.6.0+ `Container` skips redundant redraws. Default segments and `cwd` labels are skipped
|
|
41
|
+
when unused by a custom `footerFormat`, and text-only `$context` no longer wakes the footer pulse
|
|
42
|
+
timer.
|
|
43
|
+
- **Color, gradient & style hot paths**: scalar RGB-to-256 conversion without per-call tuple
|
|
44
|
+
allocations, bounded LRU caches for Sakura gradients, static Macaron gauges and Starship style
|
|
45
|
+
specs, and consecutive-SGR coalescing to reduce ANSI sequences on 256-color terminals.
|
|
46
|
+
- **Non-blocking project probes**: `git`, runtime and package-version probes now use async
|
|
47
|
+
`fs/promises` with `AbortSignal` cancellation and bounded mtime-aware caching instead of
|
|
48
|
+
synchronous filesystem calls.
|
|
49
|
+
- **Linear parsers**: `footer-format` now uses an iterative parser and linear orphan-separator
|
|
50
|
+
cleanup (preventing stack overflows on deeply nested `(` and regex backtracking); `thinking-trail`
|
|
51
|
+
adds a plain-text fast path and linear code-fence scanning.
|
|
52
|
+
- **Streaming & standalone extensions**: `live-context` skips redundant updates when token counts
|
|
53
|
+
are unchanged; `claude-shimmer` skips full-text estimation scans when authoritative usage is
|
|
54
|
+
present; `header` slices artwork to the active width before painting; `matrix` precomputes its
|
|
55
|
+
candy ANSI palette table.
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- **Pi 1.7.0 & dialogs**:
|
|
60
|
+
- Restored the `Tab/Shift+Tab to switch sections` hint in `/zentui` on Pi 1.7.0 (where
|
|
61
|
+
`SettingsList` renders lowercase keybinding hints) while staying compatible with Pi 1.5.x and
|
|
62
|
+
never rewriting item descriptions at narrow widths.
|
|
63
|
+
- Zentui and Matrix resolve config paths lazily via `getAgentDir()`, honoring Pi 1.7.0's
|
|
64
|
+
`--agent-dir` flag and runtime `PI_CODING_AGENT_DIR` changes.
|
|
65
|
+
- Fixed strict TypeScript compatibility with Pi 1.6.0+'s `Component.render(): readonly string[]`
|
|
66
|
+
and ensured render helpers never mutate frozen caller arrays.
|
|
67
|
+
- **Zentui core, footer & chrome**:
|
|
68
|
+
- Mid-session `/theme` switches now propagate immediately to the editor, footer, tool cards and
|
|
69
|
+
color mode without restarting Pi.
|
|
70
|
+
- Narrow-footer layout no longer overflows its column budget; non-finite context values format
|
|
71
|
+
cleanly as `--`; `toHomePath` matches Windows drive and UNC prefixes case-insensitively.
|
|
72
|
+
- Bare git repositories and `.git/` subdirectories are handled cleanly without spurious errors,
|
|
73
|
+
and transient `git status --show-stash` probe failures are retried instead of cached for the
|
|
74
|
+
whole process.
|
|
75
|
+
- `thinking-trail` handles CRLF fenced code blocks and closing tags inside fenced code cleanly.
|
|
76
|
+
- `tool-execution` resets SGR before the right rail, handles CRLF and empty context lines in diff
|
|
77
|
+
stats, preserves grapheme clusters in card titles, and forwards captured mouse drag/release
|
|
78
|
+
events (matching `PolishedEditor`).
|
|
79
|
+
- Extension statuses strip BiDi override characters, terminate unclosed original SGR spans and
|
|
80
|
+
strip SGR when `colorMode === "none"` (`NO_COLOR` / `TERM=dumb`).
|
|
81
|
+
- Prototype patches roll back atomically on partial install failure, and disabling features across
|
|
82
|
+
`session_start` switches cleanly uninstalls prior UI and timers.
|
|
83
|
+
- Added `thinking-trail` to `/zentui` usage help and argument completions, and validated inputs
|
|
84
|
+
when saving path-display and extension-status settings.
|
|
85
|
+
- **Color detection & standalone extensions**:
|
|
86
|
+
- `detectColorMode` and `syncColorMode` handle `TERM=dumb`, `PI_TRUE_COLOR`, `TMUX`/`screen`
|
|
87
|
+
precedence, `"none"` theme modes and non-finite RGB channels cleanly.
|
|
88
|
+
- `claude-shimmer` pauses its clock and freezes stall timing during `ui_prompt_start` /
|
|
89
|
+
`ui_prompt_end`, suppresses false completion notices after pre-message API errors, resets active
|
|
90
|
+
tool counts across turns and sessions, and restores Pi's working UI on `session_shutdown`.
|
|
91
|
+
- `matrix` pauses during UI prompts, reloads config on `session_start`, rejects extra tokens in
|
|
92
|
+
`/sakura-matrix` commands, and guards invalid widths/heights and `ctx.isIdle?.()`.
|
|
93
|
+
- `header` emits zero ANSI sequences in `NO_COLOR` mode across all widths and only clears a header
|
|
94
|
+
it owns on shutdown.
|
|
95
|
+
- `changelog` handles fenced code blocks, narrow/non-finite widths, empty `0/0` states and
|
|
96
|
+
headless `notify` fallbacks safely.
|
|
97
|
+
- Every timer across all five extensions calls `.unref?.()` so background timers never hold the
|
|
98
|
+
Node process open on exit.
|
|
99
|
+
|
|
100
|
+
### Development
|
|
101
|
+
|
|
102
|
+
- Bumped `scripts/dev-setup.mjs` default Pi host to `1.7.0`, honored `PI_HOST_ROOT` in
|
|
103
|
+
`test/theme.test.ts`, upgraded `scripts/check.mjs` to a lexer-based import scanner, removed the
|
|
104
|
+
`style.ts` ↔ `config.ts` type import cycle, decomposed high-complexity modules
|
|
105
|
+
(`footer-segments.ts`, `git.ts`, `settings-command.ts`), and added static invariant tests plus an
|
|
106
|
+
end-to-end test suite (`npm run test:e2e`) wired into CI.
|
|
107
|
+
|
|
6
108
|
## [1.5.3] - 2026-11-28
|
|
7
109
|
|
|
8
110
|
### Highlights
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Then pick the theme in `/settings` → **sakura-macaron** and restart Pi once. D
|
|
|
18
18
|
<sub>Real Pi 1.5.2 session rendered by this pack (scripted demo model; GohuFont uni14 Nerd Font Mono).</sub>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
|
-
**v1.5.
|
|
21
|
+
**v1.5.4** — full Pi 1.7.0 compatibility, identity-preserving render caches, async non-blocking probes, atomic config persistence and broad robustness hardening. See [what changed](#154).
|
|
22
22
|
|
|
23
23
|
## What’s inside
|
|
24
24
|
|
|
@@ -99,7 +99,7 @@ Other editor extensions (e.g. `pi-fff`) keep their input and autocomplete inside
|
|
|
99
99
|
|
|
100
100
|
## Requirements
|
|
101
101
|
|
|
102
|
-
- Pi **>= 0.87.1** (tested on 0.87.1, 0.99.1 and 1.
|
|
102
|
+
- Pi **>= 0.87.1** (tested on 0.87.1, 0.99.1, 1.5.2 and 1.7.0)
|
|
103
103
|
- Dark terminal background (the theme does not paint a background)
|
|
104
104
|
- Truecolor recommended; 256-color terminals get the nearest palette colors, `NO_COLOR` disables the pack’s own colors
|
|
105
105
|
- Nerd Font for the default icons (`icons.mode: "ascii"` works without)
|
|
@@ -147,9 +147,9 @@ Restart Pi after updating. Pi **>= 1.5.0** shows what changed under **Extension
|
|
|
147
147
|
Pi does not push package updates automatically. Users who pinned a version, tag or commit must explicitly select the new version:
|
|
148
148
|
|
|
149
149
|
```bash
|
|
150
|
-
pi install npm:pi-sakura-cyberdeck@1.5.
|
|
150
|
+
pi install npm:pi-sakura-cyberdeck@1.5.4
|
|
151
151
|
# or
|
|
152
|
-
pi install git:github.com/beautifulrem/pi-sakura-cyberdeck@v1.5.
|
|
152
|
+
pi install git:github.com/beautifulrem/pi-sakura-cyberdeck@v1.5.4
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
Notes for 1.2.0:
|
|
@@ -175,7 +175,7 @@ Or start with `pi --tui-mode fullscreen`. Pack styling (editor chrome, footer, s
|
|
|
175
175
|
|
|
176
176
|
### Load only some pieces
|
|
177
177
|
|
|
178
|
-
Pi can filter a package's resources. Replace the plain source string in `~/.pi/agent/settings.json` with an object. Keep `source` exactly as it is in your settings (a Git source, or an npm version pin such as `npm:pi-sakura-cyberdeck@1.5.
|
|
178
|
+
Pi can filter a package's resources. Replace the plain source string in `~/.pi/agent/settings.json` with an object. Keep `source` exactly as it is in your settings (a Git source, or an npm version pin such as `npm:pi-sakura-cyberdeck@1.5.4`); changing it installs a different package rather than filtering the one you have.
|
|
179
179
|
|
|
180
180
|
```jsonc
|
|
181
181
|
{
|
|
@@ -239,23 +239,29 @@ Avoid stacking with `pi-zentui`, `pi-powerline-footer`, stock `pi-claude-shimmer
|
|
|
239
239
|
|
|
240
240
|
Full history: [CHANGELOG.md](CHANGELOG.md) (also available in Pi via `/sakura-changelog`).
|
|
241
241
|
|
|
242
|
-
### 1.5.
|
|
242
|
+
### 1.5.4
|
|
243
243
|
|
|
244
|
-
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
-
|
|
244
|
+
- Full Pi 1.7.0 support: `readonly string[]` render contract and `Container` identity caching,
|
|
245
|
+
lowercase `SettingsList` hints in `/zentui`, mouse and keybinding controls for `/zentui` and
|
|
246
|
+
`/sakura-changelog`, and lazy `getAgentDir()` resolution for `--agent-dir`.
|
|
247
|
+
- Performance: identity-preserving frame caches for the footer, editor and selector borders; scalar
|
|
248
|
+
RGB-to-256 conversion with LRU gradient/style caching and SGR coalescing; non-blocking async git,
|
|
249
|
+
runtime and package-version probes with `AbortSignal`; iterative `footer-format` parsing and
|
|
250
|
+
linear `thinking-trail` fence scanning (fixing CRLF fences).
|
|
251
|
+
- Robustness: atomic symlink- and size-guarded config saves, immediate mid-session `/theme` updates,
|
|
252
|
+
BiDi/SGR sanitization for extension statuses, `.unref()` across all timers, and standalone
|
|
253
|
+
extension hardening across `claude-shimmer`, `matrix`, `header` and `changelog`.
|
|
249
254
|
|
|
250
255
|
### Earlier versions
|
|
251
256
|
|
|
252
|
-
See [CHANGELOG.md](CHANGELOG.md) for 1.0.0 – 1.5.
|
|
257
|
+
See [CHANGELOG.md](CHANGELOG.md) for 1.0.0 – 1.5.3.
|
|
253
258
|
|
|
254
259
|
## Development
|
|
255
260
|
|
|
256
261
|
```bash
|
|
257
262
|
npm run dev:setup # installs Pi + TypeScript into .dev/ (not shipped, no package deps)
|
|
258
263
|
npm run verify # package check + strict typecheck + unit tests
|
|
264
|
+
npm run test:e2e # end-to-end suite against the installed Pi host
|
|
259
265
|
PI_HOST_ROOT=/path/to/node_modules/@earendil-works/pi-coding-agent npm test # test against another Pi
|
|
260
266
|
```
|
|
261
267
|
|
package/README.zh-CN.md
CHANGED
|
@@ -42,7 +42,7 @@ pi install npm:pi-sakura-cyberdeck
|
|
|
42
42
|
|
|
43
43
|
## 要求
|
|
44
44
|
|
|
45
|
-
- Pi **>= 0.87.1**(在 0.87.1、0.99.1、1.5.2 上测试过)
|
|
45
|
+
- Pi **>= 0.87.1**(在 0.87.1、0.99.1、1.5.2、1.7.0 上测试过)
|
|
46
46
|
- 深色终端背景;推荐真彩色终端
|
|
47
47
|
- 默认图标需要 Nerd Font(没有的话设置 `icons.mode: "ascii"`)
|
|
48
48
|
|
|
@@ -50,7 +50,7 @@ pi install npm:pi-sakura-cyberdeck
|
|
|
50
50
|
|
|
51
51
|
## 只加载部分组件
|
|
52
52
|
|
|
53
|
-
在 `~/.pi/agent/settings.json` 里把包来源写成对象,可以按需过滤。`source` 保持你设置里原来的写法(比如 Git 来源,或者 `npm:pi-sakura-cyberdeck@1.5.
|
|
53
|
+
在 `~/.pi/agent/settings.json` 里把包来源写成对象,可以按需过滤。`source` 保持你设置里原来的写法(比如 Git 来源,或者 `npm:pi-sakura-cyberdeck@1.5.4` 这样锁定版本的写法);改了它就等于装了另一个包,而不是过滤现有的这个。
|
|
54
54
|
|
|
55
55
|
```jsonc
|
|
56
56
|
{
|
|
@@ -9,8 +9,18 @@
|
|
|
9
9
|
import { existsSync, readFileSync } from "node:fs";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
import type { ExtensionAPI,
|
|
13
|
-
import {
|
|
12
|
+
import type { ExtensionAPI, Theme } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import {
|
|
14
|
+
type Component,
|
|
15
|
+
type Keybinding,
|
|
16
|
+
type KeyId,
|
|
17
|
+
matchesKey,
|
|
18
|
+
type TuiMouseEvent,
|
|
19
|
+
type TuiMouseEventResult,
|
|
20
|
+
truncateToWidth,
|
|
21
|
+
wrapTextWithAnsi,
|
|
22
|
+
} from "@earendil-works/pi-tui";
|
|
23
|
+
import { isInteractiveTui, normalizeWidth } from "../shared/tui-context";
|
|
14
24
|
|
|
15
25
|
export interface ChangelogSection {
|
|
16
26
|
title: string;
|
|
@@ -28,6 +38,26 @@ const packageRoot = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
|
28
38
|
// ---------------------------------------------------------------------------
|
|
29
39
|
// Parsing (pure)
|
|
30
40
|
|
|
41
|
+
const FENCE_OPEN = /^\s*(`{3,}|~{3,})/;
|
|
42
|
+
const FENCE_CLOSE = /^\s*(`{3,}|~{3,})[ \t]*$/;
|
|
43
|
+
|
|
44
|
+
function matchFenceOpen(line: string): string | undefined {
|
|
45
|
+
const match = FENCE_OPEN.exec(line);
|
|
46
|
+
if (!match) return undefined;
|
|
47
|
+
const marker = match[1]!;
|
|
48
|
+
// CommonMark §4.5: backtick fence info strings cannot contain backticks
|
|
49
|
+
// (single-line inline spans like ```code``` do not open a fenced block).
|
|
50
|
+
if (marker[0] === "`" && line.indexOf("`", match.index + match[0].length) !== -1) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return marker;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function closesFence(line: string, fence: string): boolean {
|
|
57
|
+
const match = FENCE_CLOSE.exec(line);
|
|
58
|
+
return !!match && match[1]![0] === fence[0] && match[1]!.length >= fence.length;
|
|
59
|
+
}
|
|
60
|
+
|
|
31
61
|
/** Parses `## [1.2.0] - 2026-09-30` / `## 1.2.0` headings with `###` sections and `-` bullets. */
|
|
32
62
|
export function parseChangelog(markdown: string): ChangelogEntry[] {
|
|
33
63
|
const entries: ChangelogEntry[] = [];
|
|
@@ -36,8 +66,36 @@ export function parseChangelog(markdown: string): ChangelogEntry[] {
|
|
|
36
66
|
// Markdown soft line breaks: a hard-wrapped bullet or paragraph continues on the next
|
|
37
67
|
// non-bullet line until a blank line or heading ends it.
|
|
38
68
|
let open = false;
|
|
69
|
+
let fence: string | undefined;
|
|
70
|
+
|
|
71
|
+
const pushLineToSection = (line: string) => {
|
|
72
|
+
if (!entry) return;
|
|
73
|
+
if (!section) {
|
|
74
|
+
section = { title: "", lines: [] };
|
|
75
|
+
entry.sections.push(section);
|
|
76
|
+
}
|
|
77
|
+
section.lines.push(line);
|
|
78
|
+
};
|
|
79
|
+
|
|
39
80
|
for (const raw of markdown.split(/\r?\n/)) {
|
|
40
81
|
const line = raw.trimEnd();
|
|
82
|
+
if (fence !== undefined) {
|
|
83
|
+
if (closesFence(line, fence)) {
|
|
84
|
+
fence = undefined;
|
|
85
|
+
open = false;
|
|
86
|
+
}
|
|
87
|
+
pushLineToSection(line);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const fenceOpen = matchFenceOpen(line);
|
|
92
|
+
if (fenceOpen !== undefined) {
|
|
93
|
+
fence = fenceOpen;
|
|
94
|
+
open = false;
|
|
95
|
+
pushLineToSection(line);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
41
99
|
const heading = line.match(/^##\s+\[?v?(\d+\.\d+\.\d+[^\]\s]*)\]?(?:\s+[-–—]\s+(.+))?\s*$/);
|
|
42
100
|
if (heading) {
|
|
43
101
|
entry = { version: heading[1]!, date: heading[2]?.trim(), sections: [] };
|
|
@@ -69,11 +127,7 @@ export function parseChangelog(markdown: string): ChangelogEntry[] {
|
|
|
69
127
|
continue;
|
|
70
128
|
}
|
|
71
129
|
open = true;
|
|
72
|
-
|
|
73
|
-
section = { title: "", lines: [] };
|
|
74
|
-
entry.sections.push(section);
|
|
75
|
-
}
|
|
76
|
-
section.lines.push(line);
|
|
130
|
+
pushLineToSection(line);
|
|
77
131
|
}
|
|
78
132
|
return entries;
|
|
79
133
|
}
|
|
@@ -97,28 +151,51 @@ function bulletText(line: string): string {
|
|
|
97
151
|
|
|
98
152
|
/** Full changelog lines (used by the scrollable viewer). */
|
|
99
153
|
export function renderChangelogLines(entries: ChangelogEntry[], width: number, theme: Paint): string[] {
|
|
154
|
+
const safeWidth = normalizeWidth(width);
|
|
155
|
+
if (safeWidth <= 0) return [];
|
|
156
|
+
const compact = safeWidth < 16;
|
|
157
|
+
const baseIndent = compact ? "" : " ";
|
|
100
158
|
const out: string[] = [];
|
|
101
159
|
const wrap = (text: string, indent: string, hanging: string) => {
|
|
102
|
-
const body = wrapTextWithAnsi(text, Math.max(
|
|
160
|
+
const body = wrapTextWithAnsi(text, Math.max(1, safeWidth - hanging.length));
|
|
103
161
|
body.forEach((part, index) => out.push(`${index === 0 ? indent : hanging}${part}`));
|
|
104
162
|
};
|
|
105
163
|
for (const entry of entries) {
|
|
106
164
|
if (out.length) out.push("");
|
|
107
165
|
out.push(theme.bold(theme.fg("accent", `✿ ${entry.version}`)) + (entry.date ? theme.fg("dim", ` ${entry.date}`) : ""));
|
|
108
166
|
for (const section of entry.sections) {
|
|
109
|
-
if (section.title) out.push(theme.fg("mdHeading", ` ${section.title}`));
|
|
167
|
+
if (section.title) out.push(theme.fg("mdHeading", compact ? section.title : ` ${section.title}`));
|
|
168
|
+
let fence: string | undefined;
|
|
110
169
|
for (const line of section.lines) {
|
|
170
|
+
if (fence !== undefined) {
|
|
171
|
+
if (closesFence(line, fence)) {
|
|
172
|
+
fence = undefined;
|
|
173
|
+
wrap(theme.fg("dim", line.trim()), baseIndent, baseIndent);
|
|
174
|
+
} else if (!line.trim()) {
|
|
175
|
+
out.push("");
|
|
176
|
+
} else {
|
|
177
|
+
wrap(line, baseIndent, baseIndent);
|
|
178
|
+
}
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const fenceOpen = matchFenceOpen(line);
|
|
182
|
+
if (fenceOpen !== undefined) {
|
|
183
|
+
fence = fenceOpen;
|
|
184
|
+
wrap(theme.fg("dim", line.trim()), baseIndent, baseIndent);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
111
187
|
const nested = /^\s{2,}[-*]\s+/.test(line);
|
|
112
188
|
if (isBullet(line)) {
|
|
113
|
-
const indent = nested ? " " : " ";
|
|
114
|
-
|
|
189
|
+
const indent = compact ? "" : nested ? " " : " ";
|
|
190
|
+
const hanging = compact ? "" : `${indent} `;
|
|
191
|
+
wrap(`${theme.fg("dim", nested ? "◦" : "•")} ${bulletText(line)}`, indent, hanging);
|
|
115
192
|
} else {
|
|
116
|
-
wrap(stripInlineMarkdown(line.trim()),
|
|
193
|
+
wrap(stripInlineMarkdown(line.trim()), baseIndent, baseIndent);
|
|
117
194
|
}
|
|
118
195
|
}
|
|
119
196
|
}
|
|
120
197
|
}
|
|
121
|
-
return out.map((line) => truncateToWidth(line,
|
|
198
|
+
return out.map((line) => truncateToWidth(line, safeWidth, ""));
|
|
122
199
|
}
|
|
123
200
|
|
|
124
201
|
export type Paint = Pick<Theme, "fg" | "bold">;
|
|
@@ -139,83 +216,149 @@ function readChangelog(): ChangelogEntry[] {
|
|
|
139
216
|
// ---------------------------------------------------------------------------
|
|
140
217
|
// Scrollable viewer
|
|
141
218
|
|
|
142
|
-
|
|
219
|
+
type KeybindingsMatcher = {
|
|
220
|
+
matches?: (data: string, keybinding: Keybinding) => boolean;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export class ChangelogViewer implements Component {
|
|
224
|
+
readonly capturesViewportInput = true;
|
|
143
225
|
private offset = 0;
|
|
144
226
|
private lastWidth = 0;
|
|
145
227
|
private cache: string[] = [];
|
|
228
|
+
private lastFrameKey = "";
|
|
229
|
+
private lastFrameLines: string[] = [];
|
|
146
230
|
private readonly entries: ChangelogEntry[];
|
|
147
|
-
private readonly theme:
|
|
231
|
+
private readonly theme: Paint;
|
|
148
232
|
private readonly rows: () => number;
|
|
149
233
|
private readonly requestRender: () => void;
|
|
150
234
|
private readonly done: () => void;
|
|
235
|
+
private readonly keybindings: KeybindingsMatcher | undefined;
|
|
151
236
|
|
|
152
237
|
constructor(
|
|
153
238
|
entries: ChangelogEntry[],
|
|
154
|
-
theme:
|
|
239
|
+
theme: Paint,
|
|
155
240
|
rows: () => number,
|
|
156
241
|
requestRender: () => void,
|
|
157
242
|
done: () => void,
|
|
243
|
+
keybindings?: KeybindingsMatcher,
|
|
158
244
|
) {
|
|
159
245
|
this.entries = entries;
|
|
160
246
|
this.theme = theme;
|
|
161
247
|
this.rows = rows;
|
|
162
248
|
this.requestRender = requestRender;
|
|
163
249
|
this.done = done;
|
|
250
|
+
this.keybindings = keybindings;
|
|
164
251
|
}
|
|
165
252
|
|
|
166
253
|
private pageSize(): number {
|
|
167
|
-
|
|
254
|
+
const rawRows = this.rows();
|
|
255
|
+
const safeRows = typeof rawRows === "number" && Number.isFinite(rawRows) && rawRows > 0 ? Math.floor(rawRows) : 24;
|
|
256
|
+
return Math.max(5, Math.min(40, safeRows - 8));
|
|
168
257
|
}
|
|
169
258
|
|
|
170
259
|
private maxOffset(): number {
|
|
171
260
|
return Math.max(0, this.cache.length - this.pageSize());
|
|
172
261
|
}
|
|
173
262
|
|
|
263
|
+
private matchesBinding(data: string, binding: Keybinding, fallbackKeys: readonly KeyId[]): boolean {
|
|
264
|
+
if (typeof this.keybindings?.matches === "function") {
|
|
265
|
+
return this.keybindings.matches(data, binding);
|
|
266
|
+
}
|
|
267
|
+
return fallbackKeys.some((key) => matchesKey(data, key));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private isCloseInput(data: string): boolean {
|
|
271
|
+
return (
|
|
272
|
+
this.matchesBinding(data, "tui.select.cancel", ["escape", "ctrl+c"]) ||
|
|
273
|
+
matchesKey(data, "ctrl+c") ||
|
|
274
|
+
data === "q" ||
|
|
275
|
+
matchesKey(data, "return")
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private nextScrollOffset(data: string, max: number): number | undefined {
|
|
280
|
+
if (this.matchesBinding(data, "tui.select.up", ["up"]) || data === "k") return this.offset - 1;
|
|
281
|
+
if (this.matchesBinding(data, "tui.select.down", ["down"]) || data === "j") return this.offset + 1;
|
|
282
|
+
if (this.matchesBinding(data, "tui.select.pageUp", ["pageUp"])) return this.offset - this.pageSize();
|
|
283
|
+
if (this.matchesBinding(data, "tui.select.pageDown", ["pageDown"]) || data === " ") return this.offset + this.pageSize();
|
|
284
|
+
if (matchesKey(data, "home") || data === "g") return 0;
|
|
285
|
+
if (matchesKey(data, "end") || data === "G") return max;
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
|
|
174
289
|
handleInput(data: string): void {
|
|
175
|
-
|
|
176
|
-
if (matchesKey(data, "escape") || data === "q" || matchesKey(data, "return")) {
|
|
290
|
+
if (this.isCloseInput(data)) {
|
|
177
291
|
this.done();
|
|
178
292
|
return;
|
|
179
293
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
294
|
+
const max = this.maxOffset();
|
|
295
|
+
const target = this.nextScrollOffset(data, max);
|
|
296
|
+
if (target === undefined) return;
|
|
297
|
+
const previous = this.offset;
|
|
298
|
+
this.offset = Math.max(0, Math.min(max, target));
|
|
299
|
+
if (this.offset !== previous) this.requestRender();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
303
|
+
if (event.type !== "wheel") return undefined;
|
|
304
|
+
const rawDelta = event.wheelDelta;
|
|
305
|
+
if (typeof rawDelta !== "number" || !Number.isFinite(rawDelta) || rawDelta === 0) {
|
|
306
|
+
return { handled: true, render: false };
|
|
307
|
+
}
|
|
308
|
+
const step = rawDelta < 0 ? Math.min(-1, Math.trunc(rawDelta)) : Math.max(1, Math.trunc(rawDelta));
|
|
309
|
+
const previous = this.offset;
|
|
310
|
+
this.offset = Math.max(0, Math.min(this.maxOffset(), this.offset + step));
|
|
311
|
+
const changed = this.offset !== previous;
|
|
312
|
+
if (changed) this.requestRender();
|
|
313
|
+
return { handled: true, render: changed };
|
|
188
314
|
}
|
|
189
315
|
|
|
190
316
|
render(width: number): string[] {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
317
|
+
const safeWidth = normalizeWidth(width);
|
|
318
|
+
if (safeWidth <= 0) return [];
|
|
319
|
+
if (safeWidth !== this.lastWidth) {
|
|
320
|
+
this.cache = renderChangelogLines(this.entries, safeWidth, this.theme);
|
|
321
|
+
this.lastWidth = safeWidth;
|
|
322
|
+
this.lastFrameKey = "";
|
|
194
323
|
}
|
|
195
324
|
// A wider width shortens the text and a taller terminal grows the page, so the offset
|
|
196
325
|
// a key press clamped earlier can point past the end: clamp again on every render.
|
|
197
326
|
this.offset = Math.max(0, Math.min(this.maxOffset(), this.offset));
|
|
198
327
|
const size = this.pageSize();
|
|
328
|
+
const frameKey = `${safeWidth}:${this.offset}:${size}`;
|
|
329
|
+
if (frameKey === this.lastFrameKey) return this.lastFrameLines;
|
|
199
330
|
const visible = this.cache.slice(this.offset, this.offset + size);
|
|
200
331
|
const end = Math.min(this.cache.length, this.offset + size);
|
|
332
|
+
const range = this.cache.length === 0 ? "0/0" : `${this.offset + 1}-${end}/${this.cache.length}`;
|
|
201
333
|
const footer = this.theme.fg(
|
|
202
334
|
"muted",
|
|
203
|
-
` ${
|
|
335
|
+
` ${range} · ↑↓ j/k scroll · PgUp/PgDn · q/Esc close`,
|
|
204
336
|
);
|
|
205
|
-
|
|
337
|
+
this.lastFrameLines = [...visible, "", truncateToWidth(footer, safeWidth, "…")];
|
|
338
|
+
this.lastFrameKey = frameKey;
|
|
339
|
+
return this.lastFrameLines;
|
|
206
340
|
}
|
|
207
341
|
|
|
208
342
|
invalidate(): void {
|
|
209
343
|
this.lastWidth = 0;
|
|
344
|
+
this.lastFrameKey = "";
|
|
210
345
|
}
|
|
211
346
|
}
|
|
212
347
|
|
|
213
348
|
// ---------------------------------------------------------------------------
|
|
214
349
|
// Extension
|
|
215
350
|
|
|
216
|
-
function
|
|
217
|
-
|
|
218
|
-
|
|
351
|
+
function safeNotify(
|
|
352
|
+
ctx: { hasUI?: boolean; ui?: { notify?: (message: string, type?: "info" | "warning" | "error") => void } } | null | undefined,
|
|
353
|
+
message: string,
|
|
354
|
+
type: "info" | "warning" | "error",
|
|
355
|
+
): void {
|
|
356
|
+
if (!ctx?.hasUI || typeof ctx.ui?.notify !== "function") return;
|
|
357
|
+
try {
|
|
358
|
+
ctx.ui.notify(message, type);
|
|
359
|
+
} catch {
|
|
360
|
+
// Headless/disposed UI: fail soft.
|
|
361
|
+
}
|
|
219
362
|
}
|
|
220
363
|
|
|
221
364
|
export default function sakuraChangelog(pi: ExtensionAPI) {
|
|
@@ -223,26 +366,27 @@ export default function sakuraChangelog(pi: ExtensionAPI) {
|
|
|
223
366
|
description: "Show the pi-sakura-cyberdeck changelog (optionally for one version)",
|
|
224
367
|
handler: async (args, ctx) => {
|
|
225
368
|
const all = readChangelog();
|
|
226
|
-
const wanted = args.trim().replace(/^v/, "");
|
|
369
|
+
const wanted = (typeof args === "string" ? args : "").trim().replace(/^v/, "");
|
|
227
370
|
const entries = wanted ? all.filter((e) => e.version === wanted) : all;
|
|
228
371
|
if (!entries.length) {
|
|
229
|
-
|
|
372
|
+
safeNotify(
|
|
373
|
+
ctx,
|
|
230
374
|
wanted ? `No changelog entry for ${wanted}.` : "Changelog not found in this installation.",
|
|
231
375
|
"warning",
|
|
232
376
|
);
|
|
233
377
|
return;
|
|
234
378
|
}
|
|
235
|
-
if (!
|
|
379
|
+
if (!isInteractiveTui(ctx)) {
|
|
236
380
|
const plain = renderChangelogLines(entries, 100, { fg: (_c: string, t: string) => t, bold: (t: string) => t });
|
|
237
|
-
ctx
|
|
381
|
+
safeNotify(ctx, plain.slice(0, 40).join("\n"), "info");
|
|
238
382
|
return;
|
|
239
383
|
}
|
|
240
|
-
await ctx.ui.custom<void>((tui, theme,
|
|
384
|
+
await ctx.ui.custom<void>((tui, theme, kb, done) => {
|
|
241
385
|
const rows = () => {
|
|
242
386
|
const value = (tui as { terminal?: { rows?: number } }).terminal?.rows;
|
|
243
|
-
return typeof value === "number" && value > 0 ? value : 24;
|
|
387
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : 24;
|
|
244
388
|
};
|
|
245
|
-
return new ChangelogViewer(entries, theme, rows, () => tui.requestRender(), () => done());
|
|
389
|
+
return new ChangelogViewer(entries, theme, rows, () => tui.requestRender(), () => done(), kb);
|
|
246
390
|
});
|
|
247
391
|
},
|
|
248
392
|
});
|