oh-pi 0.1.82 → 0.1.83

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.
@@ -10,5 +10,13 @@ interface HorizontalTabsOptions {
10
10
  canFinish: () => boolean;
11
11
  finishBlockedMessage?: () => string;
12
12
  }
13
+ type TabAction = "left" | "right" | "edit" | "finish" | "cancel" | {
14
+ jump: number;
15
+ };
16
+ interface KeypressLike {
17
+ name?: string;
18
+ ctrl?: boolean;
19
+ }
20
+ export declare function mapTabAction(str: string, key: KeypressLike, tabCount: number): TabAction | null;
13
21
  export declare function runHorizontalTabs(opts: HorizontalTabsOptions): Promise<void>;
14
22
  export {};
@@ -5,6 +5,24 @@ import { t } from "../i18n.js";
5
5
  function clearScreen() {
6
6
  process.stdout.write("\x1b[2J\x1b[H");
7
7
  }
8
+ export function mapTabAction(str, key, tabCount) {
9
+ if (key.ctrl && key.name === "c")
10
+ return "cancel";
11
+ if (key.name === "left")
12
+ return "left";
13
+ if (key.name === "right")
14
+ return "right";
15
+ if (key.name === "return" || key.name === "enter" || key.name === "space" || key.name === "e")
16
+ return "edit";
17
+ if (key.name === "f")
18
+ return "finish";
19
+ if (/^[1-9]$/.test(str)) {
20
+ const idx = Number(str) - 1;
21
+ if (idx >= 0 && idx < tabCount)
22
+ return { jump: idx };
23
+ }
24
+ return null;
25
+ }
8
26
  function waitForAction(tabCount) {
9
27
  return new Promise((resolve) => {
10
28
  const stdin = process.stdin;
@@ -19,21 +37,9 @@ function waitForAction(tabCount) {
19
37
  resolve(action);
20
38
  };
21
39
  const onKeypress = (str, key) => {
22
- if (key.ctrl && key.name === "c")
23
- return done("cancel");
24
- if (key.name === "left")
25
- return done("left");
26
- if (key.name === "right")
27
- return done("right");
28
- if (key.name === "return" || key.name === "space" || key.name === "e")
29
- return done("edit");
30
- if (key.name === "f")
31
- return done("finish");
32
- if (/^[1-9]$/.test(str)) {
33
- const idx = Number(str) - 1;
34
- if (idx >= 0 && idx < tabCount)
35
- return done({ jump: idx });
36
- }
40
+ const action = mapTabAction(str, key, tabCount);
41
+ if (action)
42
+ done(action);
37
43
  };
38
44
  stdin.on("keypress", onKeypress);
39
45
  if (!stdin.isTTY) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { mapTabAction } from "./horizontal-tabs.js";
3
+ describe("mapTabAction", () => {
4
+ it("maps enter and return to edit", () => {
5
+ expect(mapTabAction("", { name: "enter" }, 5)).toBe("edit");
6
+ expect(mapTabAction("", { name: "return" }, 5)).toBe("edit");
7
+ });
8
+ it("maps arrows and finish", () => {
9
+ expect(mapTabAction("", { name: "left" }, 5)).toBe("left");
10
+ expect(mapTabAction("", { name: "right" }, 5)).toBe("right");
11
+ expect(mapTabAction("", { name: "f" }, 5)).toBe("finish");
12
+ });
13
+ it("maps jump index within range", () => {
14
+ expect(mapTabAction("3", { name: "3" }, 5)).toEqual({ jump: 2 });
15
+ expect(mapTabAction("9", { name: "9" }, 5)).toBeNull();
16
+ });
17
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-pi",
3
- "version": "0.1.82",
3
+ "version": "0.1.83",
4
4
  "description": "One-click setup for pi-coding-agent. Like oh-my-zsh for pi.",
5
5
  "type": "module",
6
6
  "bin": {