refactor: unwrap UI namespace + self-reexport (#22951)

This commit is contained in:
Kit Langton
2026-04-17 00:01:41 +00:00
committed by GitHub
parent f6dbb2f3e0
commit 79732ab175
+23 -23
View File
@@ -3,17 +3,16 @@ import { EOL } from "os"
import { NamedError } from "@opencode-ai/shared/util/error" import { NamedError } from "@opencode-ai/shared/util/error"
import { logo as glyphs } from "./logo" import { logo as glyphs } from "./logo"
export namespace UI { const wordmark = [
const wordmark = [
``, ``,
`█▀▀█ █▀▀█ █▀▀█ █▀▀▄ █▀▀▀ █▀▀█ █▀▀█ █▀▀█`, `█▀▀█ █▀▀█ █▀▀█ █▀▀▄ █▀▀▀ █▀▀█ █▀▀█ █▀▀█`,
`█ █ █ █ █▀▀▀ █ █ █ █ █ █ █ █▀▀▀`, `█ █ █ █ █▀▀▀ █ █ █ █ █ █ █ █▀▀▀`,
`▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀`, `▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀`,
] ]
export const CancelledError = NamedError.create("UICancelledError", z.void()) export const CancelledError = NamedError.create("UICancelledError", z.void())
export const Style = { export const Style = {
TEXT_HIGHLIGHT: "\x1b[96m", TEXT_HIGHLIGHT: "\x1b[96m",
TEXT_HIGHLIGHT_BOLD: "\x1b[96m\x1b[1m", TEXT_HIGHLIGHT_BOLD: "\x1b[96m\x1b[1m",
TEXT_DIM: "\x1b[90m", TEXT_DIM: "\x1b[90m",
@@ -28,26 +27,26 @@ export namespace UI {
TEXT_SUCCESS_BOLD: "\x1b[92m\x1b[1m", TEXT_SUCCESS_BOLD: "\x1b[92m\x1b[1m",
TEXT_INFO: "\x1b[94m", TEXT_INFO: "\x1b[94m",
TEXT_INFO_BOLD: "\x1b[94m\x1b[1m", TEXT_INFO_BOLD: "\x1b[94m\x1b[1m",
} }
export function println(...message: string[]) { export function println(...message: string[]) {
print(...message) print(...message)
process.stderr.write(EOL) process.stderr.write(EOL)
} }
export function print(...message: string[]) { export function print(...message: string[]) {
blank = false blank = false
process.stderr.write(message.join(" ")) process.stderr.write(message.join(" "))
} }
let blank = false let blank = false
export function empty() { export function empty() {
if (blank) return if (blank) return
println("" + Style.TEXT_NORMAL) println("" + Style.TEXT_NORMAL)
blank = true blank = true
} }
export function logo(pad?: string) { export function logo(pad?: string) {
if (!process.stdout.isTTY && !process.stderr.isTTY) { if (!process.stdout.isTTY && !process.stderr.isTTY) {
const result = [] const result = []
for (const row of wordmark) { for (const row of wordmark) {
@@ -103,9 +102,9 @@ export namespace UI {
result.push(EOL) result.push(EOL)
}) })
return result.join("").trimEnd() return result.join("").trimEnd()
} }
export async function input(prompt: string): Promise<string> { export async function input(prompt: string): Promise<string> {
const readline = require("readline") const readline = require("readline")
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
@@ -118,16 +117,17 @@ export namespace UI {
resolve(answer.trim()) resolve(answer.trim())
}) })
}) })
} }
export function error(message: string) { export function error(message: string) {
if (message.startsWith("Error: ")) { if (message.startsWith("Error: ")) {
message = message.slice("Error: ".length) message = message.slice("Error: ".length)
} }
println(Style.TEXT_DANGER_BOLD + "Error: " + Style.TEXT_NORMAL + message) println(Style.TEXT_DANGER_BOLD + "Error: " + Style.TEXT_NORMAL + message)
}
export function markdown(text: string): string {
return text
}
} }
export function markdown(text: string): string {
return text
}
export * as UI from "./ui"