refactor: unwrap UI namespace + self-reexport (#22951)
This commit is contained in:
@@ -3,17 +3,16 @@ import { EOL } from "os"
|
||||
import { NamedError } from "@opencode-ai/shared/util/error"
|
||||
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_BOLD: "\x1b[96m\x1b[1m",
|
||||
TEXT_DIM: "\x1b[90m",
|
||||
@@ -28,26 +27,26 @@ export namespace UI {
|
||||
TEXT_SUCCESS_BOLD: "\x1b[92m\x1b[1m",
|
||||
TEXT_INFO: "\x1b[94m",
|
||||
TEXT_INFO_BOLD: "\x1b[94m\x1b[1m",
|
||||
}
|
||||
}
|
||||
|
||||
export function println(...message: string[]) {
|
||||
export function println(...message: string[]) {
|
||||
print(...message)
|
||||
process.stderr.write(EOL)
|
||||
}
|
||||
}
|
||||
|
||||
export function print(...message: string[]) {
|
||||
export function print(...message: string[]) {
|
||||
blank = false
|
||||
process.stderr.write(message.join(" "))
|
||||
}
|
||||
}
|
||||
|
||||
let blank = false
|
||||
export function empty() {
|
||||
let blank = false
|
||||
export function empty() {
|
||||
if (blank) return
|
||||
println("" + Style.TEXT_NORMAL)
|
||||
blank = true
|
||||
}
|
||||
}
|
||||
|
||||
export function logo(pad?: string) {
|
||||
export function logo(pad?: string) {
|
||||
if (!process.stdout.isTTY && !process.stderr.isTTY) {
|
||||
const result = []
|
||||
for (const row of wordmark) {
|
||||
@@ -103,9 +102,9 @@ export namespace UI {
|
||||
result.push(EOL)
|
||||
})
|
||||
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 rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
@@ -118,16 +117,17 @@ export namespace UI {
|
||||
resolve(answer.trim())
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function error(message: string) {
|
||||
export function error(message: string) {
|
||||
if (message.startsWith("Error: ")) {
|
||||
message = message.slice("Error: ".length)
|
||||
}
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user