feat: add ora spinner (v9.3.0) while running shell

This commit is contained in:
2026-03-23 14:27:23 +05:30
parent 6b07a7ac2a
commit e4d3e0e263
12 changed files with 201 additions and 72 deletions
+40 -10
View File
@@ -1,6 +1,12 @@
import * as os from "node:os";
import * as path from "node:path";
import type { CommandResult, WindowLaunchPlan, WorktreeInfo } from "../types";
import ora, { type Ora } from "ora";
import type {
CommandResult,
RunCommandOptions,
WindowLaunchPlan,
WorktreeInfo,
} from "../types";
const MAX_SUGGESTIONS = 3;
const WINDOW_NAME_LIMIT = 24;
@@ -9,6 +15,7 @@ const WINDOW_NAME_LIMIT = 24;
* Runs a command and captures its output without throwing on non-zero exit codes.
*
* @param parts Command segments to pass to the shell.
* @param options Additional options for running the command (e.g., mode, spinnerMsg).
* @returns The exit status plus captured stdout and stderr.
*
* @example
@@ -19,9 +26,28 @@ const WINDOW_NAME_LIMIT = 24;
* }
* ```
*/
export async function runCommand(parts: string[]): Promise<CommandResult> {
export async function runCommand(
parts: string[],
options?: RunCommandOptions,
): Promise<CommandResult> {
let spinner: Ora | undefined;
const isTest =
process.env.NODE_ENV === "test" || process.env.BUN_ENV === "test";
if (options?.mode === "cli" && !isTest) {
const msg = options.spinnerMsg || `Running ${parts[0]}...`;
spinner = ora(msg).start();
}
const result = await Bun.$`${parts}`.quiet().nothrow();
if (spinner) {
if (result.exitCode === 0) {
spinner.succeed();
} else {
spinner.fail();
}
}
return {
ok: result.exitCode === 0,
stdout: result.stdout.toString().trim(),
@@ -274,17 +300,21 @@ export async function launchModelInWindow(
sessionName: string,
plan: WindowLaunchPlan,
binaryName: string = "opencode",
mode?: "cli" | "tool",
): Promise<CommandResult> {
const launchCommand = `${binaryName} --model ${shellQuote(plan.model)}`;
return runCommand([
"tmux",
"send-keys",
"-t",
`${sessionName}:${plan.windowName}`,
launchCommand,
"C-m",
]);
return runCommand(
[
"tmux",
"send-keys",
"-t",
`${sessionName}:${plan.windowName}`,
launchCommand,
"C-m",
],
{ mode, spinnerMsg: `Launching model ${plan.model}...` },
);
}
/**