@mak-98/tmux-ts 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -41,24 +41,24 @@ The original application stays running in its pane. The returned string is the n
41
41
  `split` takes two arguments:
42
42
 
43
43
  - **Pane options**
44
- - `direction`: `"left"`, `"right"`, `"up"`, or `"down"`.
45
- - `focus`: Whether to focus the new pane. Defaults to `false`.
44
+ - `direction`: `"left"`, `"right"`, `"up"`, or `"down"`.
45
+ - `focus`: Whether to focus the new pane. Defaults to `false`.
46
46
  - **Terminal options**
47
- - `command`: The executable to run.
48
- - `args`: Optional command arguments.
49
- - `cwd`: Working directory for the new pane. Defaults to the current process's working directory.
47
+ - `command`: The executable to run.
48
+ - `args`: Optional command arguments.
49
+ - `cwd`: Working directory for the new pane. Defaults to the current process's working directory.
50
50
 
51
51
  ### Errors
52
52
 
53
53
  `split` throws an error named `SplitError` with one of these `code` values:
54
54
 
55
- | Code | Meaning |
56
- | --- | --- |
57
- | `not-installed` | The tmux executable was not found. |
58
- | `not-in-tmux` | The process does not have the expected tmux environment variables. |
59
- | `pane-unreachable` | The process's tmux pane could not be reached. |
60
- | `status-check-failed` | An unexpected error occurred while checking tmux status. |
61
- | `split-failed` | The tmux split command failed. |
55
+ | Code | Meaning |
56
+ | --------------------- | ------------------------------------------------------------------ |
57
+ | `not-installed` | The tmux executable was not found. |
58
+ | `not-in-tmux` | The process does not have the expected tmux environment variables. |
59
+ | `pane-unreachable` | The process's tmux pane could not be reached. |
60
+ | `status-check-failed` | An unexpected error occurred while checking tmux status. |
61
+ | `split-failed` | The tmux split command failed. |
62
62
 
63
63
  The underlying error is available as `cause` when applicable. A successful split returns a pane ID; it does not guarantee that the command running in the new pane will remain running.
64
64
 
@@ -84,4 +84,4 @@ npm run build
84
84
 
85
85
  ## License
86
86
 
87
- MIT
87
+ MIT
package/dist/cli.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { split } from "./index.js";
2
2
  import { getPaneStatus } from "./infrastructure/get-pane-status.js";
3
+ /**
4
+ * File for testing. `index.ts` is the package entry point.
5
+ */
3
6
  const status = await getPaneStatus();
4
7
  if (!status.available) {
5
8
  console.error(`tmux unavailable: ${status.reason}`);
@@ -1,4 +1,5 @@
1
1
  export type PaneOptions = {
2
2
  direction: "left" | "right" | "up" | "down";
3
3
  focus?: boolean;
4
+ ratio?: number;
4
5
  };
@@ -0,0 +1,5 @@
1
+ export type ShellAction = {
2
+ command: string;
3
+ args?: string[];
4
+ cwd?: string;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,13 +1,20 @@
1
- import { TerminalOptions } from "./domain/terminal-options.js";
1
+ import { ShellAction } from "./domain/shell-action.js";
2
2
  import { PaneOptions } from "./domain/pane-options.js";
3
3
  /**
4
4
  * Splits the pane containing this process and runs a command in the new pane.
5
5
  *
6
- * @param paneOptions - Direction of the split and whether to focus the new pane.
7
- * Focus defaults to false.
8
- * @param terminalOptions - Command, arguments, and working directory for the
9
- * new pane. The working directory defaults to the current process directory.
6
+ * @param options - Split direction, focus behavior, and optional size ratio.
7
+ * Focus defaults to false. The ratio specifies the fraction of the original
8
+ * pane allocated to the new pane and must be finite and strictly between 0
9
+ * and 1. It is rounded to a whole percentage and clamped to 1–99%; tmux
10
+ * allocates space in cells, so the resulting size is approximate. If omitted,
11
+ * tmux uses its default split size.
12
+ * @param action - Command, arguments, and working directory for the new pane.
13
+ * The working directory defaults to the current process directory.
10
14
  * @returns The new pane's tmux ID, such as "%3".
11
- * @throws {SplitError} If the status check or split fails.
15
+ * @throws {SplitError} If the status check or split fails, including when the
16
+ * pane is too small for the requested split.
17
+ * @throws {RangeError} If the ratio is not finite or is outside the exclusive
18
+ * range (0, 1).
12
19
  */
13
- export declare function split(paneOptions: PaneOptions, terminalOptions: TerminalOptions): Promise<string>;
20
+ export declare function split(options: PaneOptions, action: ShellAction): Promise<string>;
package/dist/index.js CHANGED
@@ -2,17 +2,7 @@ import { execFile } from "node:child_process";
2
2
  import { promisify } from "node:util";
3
3
  import { getPaneStatus } from "./infrastructure/get-pane-status.js";
4
4
  import { createSplitError } from "./domain/errors/split-error.js";
5
- /**
6
- * Splits the pane containing this process and runs a command in the new pane.
7
- *
8
- * @param paneOptions - Direction of the split and whether to focus the new pane.
9
- * Focus defaults to false.
10
- * @param terminalOptions - Command, arguments, and working directory for the
11
- * new pane. The working directory defaults to the current process directory.
12
- * @returns The new pane's tmux ID, such as "%3".
13
- * @throws {SplitError} If the status check or split fails.
14
- */
15
- export async function split(paneOptions, terminalOptions) {
5
+ async function getPaneId() {
16
6
  let status;
17
7
  try {
18
8
  status = await getPaneStatus();
@@ -23,24 +13,63 @@ export async function split(paneOptions, terminalOptions) {
23
13
  if (!status.available) {
24
14
  throw createSplitError(status.reason);
25
15
  }
26
- const horizontal = paneOptions.direction === "left" || paneOptions.direction === "right";
27
- const before = paneOptions.direction === "left" || paneOptions.direction === "up";
16
+ return status.paneId;
17
+ }
18
+ /**
19
+ * Splits the pane containing this process and runs a command in the new pane.
20
+ *
21
+ * @param options - Split direction, focus behavior, and optional size ratio.
22
+ * Focus defaults to false. The ratio specifies the fraction of the original
23
+ * pane allocated to the new pane and must be finite and strictly between 0
24
+ * and 1. It is rounded to a whole percentage and clamped to 1–99%; tmux
25
+ * allocates space in cells, so the resulting size is approximate. If omitted,
26
+ * tmux uses its default split size.
27
+ * @param action - Command, arguments, and working directory for the new pane.
28
+ * The working directory defaults to the current process directory.
29
+ * @returns The new pane's tmux ID, such as "%3".
30
+ * @throws {SplitError} If the status check or split fails, including when the
31
+ * pane is too small for the requested split.
32
+ * @throws {RangeError} If the ratio is not finite or is outside the exclusive
33
+ * range (0, 1).
34
+ */
35
+ export async function split(options, action) {
36
+ const paneId = await getPaneId();
37
+ const { ratio } = options;
38
+ if (ratio !== undefined && (!Number.isFinite(ratio) || ratio <= 0 || ratio >= 1)) {
39
+ throw new RangeError("ratio must be a finite number between 0 and 1, exclusive");
40
+ }
41
+ // tmux accepts integer percentages. Clamp after rounding so valid ratios
42
+ // close to either endpoint do not become 0% or 100%.
43
+ const percentage = ratio === undefined
44
+ ? undefined
45
+ : Math.max(1, Math.min(99, Math.round(ratio * 100)));
46
+ // Derive horizontal/vertical and whether to keep the existing session "before" in tmux.
47
+ const horizontal = options.direction === "left" || options.direction === "right";
48
+ const before = options.direction === "left" || options.direction === "up";
28
49
  const execFileAsync = promisify(execFile);
29
50
  let stdout;
30
51
  try {
31
52
  ({ stdout } = await execFileAsync("tmux", [
32
53
  "split-window",
54
+ // Direction:
33
55
  horizontal ? "-h" : "-v",
34
56
  ...(before ? ["-b"] : []),
35
- ...(paneOptions.focus ? [] : ["-d"]),
57
+ ...(options.focus ? [] : ["-d"]),
58
+ ...(percentage === undefined ? [] : ["-l", `${percentage}%`]),
36
59
  "-P",
37
- "-F", "#{pane_id}",
38
- "-t", status.paneId,
39
- "-c", terminalOptions.cwd ?? process.cwd(),
60
+ "-F",
61
+ "#{pane_id}",
62
+ "-t",
63
+ paneId,
64
+ "-c",
65
+ action.cwd ?? process.cwd(),
40
66
  "--",
41
- "/bin/sh", "-c", 'exec "$@"', "tmux-ts",
42
- terminalOptions.command,
43
- ...(terminalOptions.args ?? []),
67
+ "/bin/sh",
68
+ "-c",
69
+ 'exec "$@"',
70
+ "tmux-ts",
71
+ action.command,
72
+ ...(action.args ?? []),
44
73
  ]));
45
74
  }
46
75
  catch (error) {
@@ -19,7 +19,8 @@ export async function getPaneStatus() {
19
19
  const { stdout } = await execFileAsync("tmux", [
20
20
  "display-message",
21
21
  "-p",
22
- "-t", paneId,
22
+ "-t",
23
+ paneId,
23
24
  "#{pane_id}",
24
25
  ]);
25
26
  if (stdout.trim() !== paneId) {
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@mak-98/tmux-ts",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
8
  "start": "tsx src/cli.ts",
9
+ "format": "prettier . --write --log-level warn",
9
10
  "build": "tsc",
10
11
  "login": "npm login",
11
12
  "deploy": "npm run build && npm publish --access public"
@@ -16,10 +17,13 @@
16
17
  "default": "./dist/index.js"
17
18
  }
18
19
  },
19
- "files": ["dist"],
20
+ "files": [
21
+ "dist"
22
+ ],
20
23
  "devDependencies": {
21
24
  "@types/node": "^26.6.6",
22
25
  "tsx": "^4.23.15",
23
- "typescript": "^7.0.2"
26
+ "typescript": "^7.0.2",
27
+ "prettier": "^3.8.4"
24
28
  }
25
29
  }