pi-spark 0.3.0 → 0.3.1

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.
@@ -39,18 +39,33 @@ export default function (pi: ExtensionAPI) {
39
39
  let pendingClear = false;
40
40
  let previousClearOnShrink: boolean | undefined;
41
41
 
42
- /**
43
- * Mount a persistent filler above the editor. The widget factory receives the TUI handle
44
- * (otherwise unavailable via `ctx.ui`), so it both captures the TUI for clearing and pins the
45
- * editor and footer to the bottom of the screen.
46
- */
47
- function mountFiller(ctx: ExtensionContext): void {
42
+ pi.on("session_start", (_event, ctx) => {
43
+ if (!ctx.hasUI) return;
44
+
45
+ const config = loadConfig(ctx, "fullscreen");
46
+ if (!config) return;
47
+
48
+ enabled = true;
49
+ pendingClear = true;
50
+
51
+ // The TUI handle isn't exposed via `ctx.ui`; the widget factory is the only place that
52
+ // receives it. Mounting a persistent filler above the editor both captures the TUI and
53
+ // pins the editor and footer to the bottom of the screen.
48
54
  ctx.ui.setWidget(WIDGET_KEY, (capturedTui) => {
49
55
  tui = capturedTui;
50
56
 
51
- previousClearOnShrink ??= tui.getClearOnShrink();
52
- tui.setClearOnShrink(true);
53
-
57
+ // Enable `clearOnShrink`, but defer it to a macrotask. On `/reload`, pi resets
58
+ // `clearOnShrink` to the settings value right after `session_start`, inside the reload's
59
+ // microtask continuation. A `setTimeout` callback runs only after that microtask queue
60
+ // drains, so it lands last and sticks. `queueMicrotask` (or a synchronous call) would run
61
+ // before the reset and get clobbered.
62
+ previousClearOnShrink ??= capturedTui.getClearOnShrink();
63
+ setTimeout(() => capturedTui.setClearOnShrink(true));
64
+
65
+ // Clear the screen once on entry. `session_start` has no TUI to repaint with, and a
66
+ // synchronous repaint here is too early (the filler isn't in the render tree until
67
+ // `setWidget` returns), so defer to a microtask. `pendingClear` limits this to the
68
+ // `session_start`-triggered mount rather than every widget rebuild.
54
69
  if (pendingClear) {
55
70
  pendingClear = false;
56
71
  queueMicrotask(() => capturedTui.requestRender(true));
@@ -58,29 +73,12 @@ export default function (pi: ExtensionAPI) {
58
73
 
59
74
  return new BottomFiller(capturedTui);
60
75
  });
61
- }
62
-
63
- pi.on("session_start", (_event, ctx) => {
64
- if (!ctx.hasUI) return;
65
-
66
- const config = loadConfig(ctx, "fullscreen");
67
- if (!config) return;
68
-
69
- enabled = true;
70
-
71
- if (tui) {
72
- tui.setClearOnShrink(true);
73
- tui.requestRender(true);
74
- return;
75
- }
76
-
77
- pendingClear = true;
78
- mountFiller(ctx);
79
76
  });
80
77
 
81
78
  pi.on("session_shutdown", (event, ctx) => {
82
79
  if (!enabled) return;
83
80
 
81
+ // Restore `clearOnShrink` to its pre-fullscreen value.
84
82
  if (previousClearOnShrink !== undefined) {
85
83
  tui?.setClearOnShrink(previousClearOnShrink);
86
84
  previousClearOnShrink = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spark",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A small, opinionated collection of pi extensions",
5
5
  "keywords": [
6
6
  "pi-coding-agent",