Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/opencode/src/cli/cmd/plug.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EOL } from "os"
import { intro, log, outro, spinner } from "@clack/prompts"
import { Effect } from "effect"

Expand Down Expand Up @@ -44,8 +45,21 @@ export type PlugCtx = {
directory: string
}

export function createPlugSpinner(
options: {
isTTY?: boolean
write?: (msg: string) => void
} = {},
): Spin {
if (options.isTTY ?? process.stdout.isTTY) return spinner()
return {
start: (msg) => (options.write ?? process.stderr.write.bind(process.stderr))(`${msg}${EOL}`),
stop: (msg) => (options.write ?? process.stderr.write.bind(process.stderr))(`${msg}${EOL}`),
}
}

const defaultPlugDeps: PlugDeps = {
spinner: () => spinner(),
spinner: () => createPlugSpinner(),
log: {
error: (msg) => log.error(msg),
info: (msg) => log.info(msg),
Expand Down
18 changes: 17 additions & 1 deletion packages/opencode/test/plugin/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "fs/promises"
import path from "path"
import { parse as parseJsonc } from "jsonc-parser"
import { Filesystem } from "@/util/filesystem"
import { createPlugTask, type PlugCtx, type PlugDeps } from "../../src/cli/cmd/plug"
import { createPlugSpinner, createPlugTask, type PlugCtx, type PlugDeps } from "../../src/cli/cmd/plug"
import { tmpdir } from "../fixture/fixture"

function deps(global: string, target: string | Error): PlugDeps {
Expand Down Expand Up @@ -109,6 +109,22 @@ async function read(file: string) {
}

describe("plugin.install.task", () => {
test("uses static spinner output outside TTY", () => {
const output: string[] = []
const spin = createPlugSpinner({
isTTY: false,
write: (msg) => output.push(msg),
})

spin.start("Installing plugin package...")
spin.stop("Plugin package ready")

const normalized = output.join("").replaceAll("\r\n", "\n")
expect(normalized).toBe("Installing plugin package...\nPlugin package ready\n")
expect(normalized).not.toContain("\r")
expect(normalized).not.toContain("\x1b[")
})

test("writes both server and tui config entries", async () => {
await using tmp = await tmpdir()
const target = await plugin(tmp.path, ["server", "tui"])
Expand Down
Loading