@leo-alvarenga/pi-zen-frame 0.19.8 → 0.20.0

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.
@@ -1,4 +1,4 @@
1
- import { matchesKey } from "@earendil-works/pi-tui";
1
+ import { Key, matchesKey } from "@earendil-works/pi-tui";
2
2
 
3
3
  import { filterPalette, MAX_VISIBLE } from "./items";
4
4
  import type { PaletteState } from "./types";
@@ -14,17 +14,23 @@ export function handlePaletteInput(
14
14
  state: PaletteState,
15
15
  data: string,
16
16
  ): PaletteInputResult {
17
- if (matchesKey(data, "escape")) {
17
+ if (matchesKey(data, Key.esc)) {
18
18
  return { next: null, submit: null };
19
19
  }
20
20
 
21
+ const item = state.items[state.selected];
21
22
  if (data === "\r" || data === "\n") {
22
- const item = state.items[state.selected];
23
-
24
23
  return { next: null, submit: item ? item.name : null };
25
24
  }
26
25
 
27
- if (data === "\x7f" || data === "\b") {
26
+ if (matchesKey(data, Key.tab)) {
27
+ return {
28
+ submit: null,
29
+ next: { ...state, query: item.name.replace("/", "") },
30
+ };
31
+ }
32
+
33
+ if (matchesKey(data, Key.backspace) || matchesKey(data, Key.delete)) {
28
34
  if (state.query.length > 0) {
29
35
  const query = state.query.slice(0, -1);
30
36
 
@@ -48,7 +54,10 @@ export function handlePaletteInput(
48
54
  const selected = Math.max(0, state.selected - 1);
49
55
  const viewTop = selected < state.viewTop ? selected : state.viewTop;
50
56
 
51
- return { next: { ...state, selected, viewTop }, submit: null };
57
+ return {
58
+ submit: null,
59
+ next: { ...state, selected, viewTop },
60
+ };
52
61
  }
53
62
 
54
63
  if (matchesKey(data, "down")) {
@@ -62,7 +71,10 @@ export function handlePaletteInput(
62
71
  viewTop = selected - MAX_VISIBLE + 1;
63
72
  }
64
73
 
65
- return { next: { ...state, selected, viewTop }, submit: null };
74
+ return {
75
+ submit: null,
76
+ next: { ...state, selected, viewTop },
77
+ };
66
78
  }
67
79
 
68
80
  if (data.length === 1 && data >= " ") {
@@ -70,7 +82,6 @@ export function handlePaletteInput(
70
82
 
71
83
  return {
72
84
  submit: null,
73
-
74
85
  next: {
75
86
  ...state,
76
87
  query,
@@ -7,12 +7,29 @@ import type { PaletteState } from "./types";
7
7
  const ACTIVE_PREFIX = " → ";
8
8
  const INACTIVE_PREFIX = " ";
9
9
 
10
+ function getMaxWidth(width: number, offset: number): number {
11
+ let modifier = 0.8;
12
+
13
+ if (width >= 120) {
14
+ modifier = 0.6;
15
+ } else if (width >= 100) {
16
+ modifier = 0.7;
17
+ } else if (width >= 80) {
18
+ modifier = 0.8;
19
+ } else if (width >= 60) {
20
+ modifier = 0.9;
21
+ }
22
+
23
+ const maxSize = Math.floor(Math.max(0, width - offset) * modifier);
24
+ return Math.max(36, maxSize);
25
+ }
26
+
10
27
  export function renderPalette(
11
28
  state: PaletteState,
12
29
  width: number,
13
30
  theme: Theme,
14
31
  ): string[] {
15
- const boxW = Math.min(68, Math.max(36, width - 4));
32
+ const boxW = getMaxWidth(width, 4);
16
33
 
17
34
  const inner = boxW - 2;
18
35
  const lPad = " ".repeat(Math.max(0, Math.floor((width - boxW) / 2)));
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@leo-alvarenga/pi-zen-frame",
3
3
  "description": "A pi-coding-agent extension that gives the TUI editor a simple yet polished look and feel",
4
4
  "author": "Leonardo A. Alvarenga",
5
- "version": "0.19.8",
5
+ "version": "0.20.0",
6
6
  "license": "MIT",
7
7
  "repository": "github.com/leo-alvarenga/pi-mono",
8
8
  "publishConfig": {
@@ -26,7 +26,7 @@
26
26
  "typebox": "*"
27
27
  },
28
28
  "dependencies": {
29
- "@leo-alvarenga/pi-ext-core": "0.5.0"
29
+ "@leo-alvarenga/pi-ext-core": "0.5.1"
30
30
  },
31
31
  "pi": {
32
32
  "extensions": [