mirror of
https://github.com/bendtherules/opencode-multi-model.git
synced 2026-08-18 13:42:21 +00:00
feat: add ora spinner (v9.3.0) while running shell
This commit is contained in:
+40
-10
@@ -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}...` },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user