2026-02-08 15:01:42 +09:00
|
|
|
import { spawn } from "bun"
|
|
|
|
|
import type { TmuxLayout } from "../../../config/schema"
|
|
|
|
|
import { getTmuxPath } from "../../../tools/interactive-bash/tmux-path-resolver"
|
|
|
|
|
|
|
|
|
|
export async function applyLayout(
|
|
|
|
|
layout: TmuxLayout,
|
|
|
|
|
mainPaneSize: number,
|
|
|
|
|
): Promise<void> {
|
2026-02-17 01:36:01 +09:00
|
|
|
const tmux = await getTmuxPath()
|
|
|
|
|
if (!tmux) return
|
|
|
|
|
|
2026-02-08 15:01:42 +09:00
|
|
|
const layoutProc = spawn([tmux, "select-layout", layout], {
|
|
|
|
|
stdout: "ignore",
|
|
|
|
|
stderr: "ignore",
|
|
|
|
|
})
|
|
|
|
|
await layoutProc.exited
|
|
|
|
|
|
|
|
|
|
if (layout.startsWith("main-")) {
|
|
|
|
|
const dimension =
|
|
|
|
|
layout === "main-horizontal" ? "main-pane-height" : "main-pane-width"
|
|
|
|
|
const sizeProc = spawn(
|
|
|
|
|
[tmux, "set-window-option", dimension, `${mainPaneSize}%`],
|
|
|
|
|
{ stdout: "ignore", stderr: "ignore" },
|
|
|
|
|
)
|
|
|
|
|
await sizeProc.exited
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function enforceMainPaneWidth(
|
|
|
|
|
mainPaneId: string,
|
|
|
|
|
windowWidth: number,
|
2026-02-17 03:40:46 +09:00
|
|
|
mainPaneSize: number,
|
2026-02-08 15:01:42 +09:00
|
|
|
): Promise<void> {
|
|
|
|
|
const { log } = await import("../../logger")
|
|
|
|
|
const tmux = await getTmuxPath()
|
|
|
|
|
if (!tmux) return
|
|
|
|
|
|
|
|
|
|
const dividerWidth = 1
|
2026-02-17 03:40:46 +09:00
|
|
|
const boundedMainPaneSize = Math.max(20, Math.min(80, mainPaneSize))
|
|
|
|
|
const mainWidth = Math.floor(((windowWidth - dividerWidth) * boundedMainPaneSize) / 100)
|
2026-02-08 15:01:42 +09:00
|
|
|
|
|
|
|
|
const proc = spawn([tmux, "resize-pane", "-t", mainPaneId, "-x", String(mainWidth)], {
|
|
|
|
|
stdout: "ignore",
|
|
|
|
|
stderr: "ignore",
|
|
|
|
|
})
|
|
|
|
|
await proc.exited
|
|
|
|
|
|
|
|
|
|
log("[enforceMainPaneWidth] main pane resized", {
|
|
|
|
|
mainPaneId,
|
|
|
|
|
mainWidth,
|
|
|
|
|
windowWidth,
|
2026-02-17 03:40:46 +09:00
|
|
|
mainPaneSize: boundedMainPaneSize,
|
2026-02-08 15:01:42 +09:00
|
|
|
})
|
|
|
|
|
}
|