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
15 changes: 14 additions & 1 deletion packages/opencode/src/cli/cmd/plug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ type Spin = {
stop: (msg: string, code?: number) => void
}

type Output = {
readonly isTTY?: boolean
write: (chunk: string) => unknown
}

export function plugSpinner(output: Output = process.stdout): Spin {
if (output.isTTY) return spinner()
return {
start: (msg) => output.write(msg + "\n"),
stop: (msg) => output.write(msg + "\n"),
}
}

export type PlugDeps = {
spinner: () => Spin
log: {
Expand Down Expand Up @@ -45,7 +58,7 @@ export type PlugCtx = {
}

const defaultPlugDeps: PlugDeps = {
spinner: () => spinner(),
spinner: () => plugSpinner(),
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 { createPlugTask, plugSpinner, 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 @@ -108,6 +108,22 @@ async function read(file: string) {
}>(file)
}

test("plugin spinner writes plain lines outside a TTY", () => {
for (const isTTY of [false, undefined] as const) {
const chunks: string[] = []
const spin = plugSpinner({
isTTY,
write: (chunk) => chunks.push(chunk),
})

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

expect(chunks.join("")).toBe("Installing plugin package...\nPlugin package ready\n")
expect(chunks.join("")).not.toContain("\x1b")
}
})

describe("plugin.install.task", () => {
test("writes both server and tui config entries", async () => {
await using tmp = await tmpdir()
Expand Down
Loading