Skip to content

Commit 3d74904

Browse files
authored
refactor: unwrap UI namespace + self-reexport (anomalyco#22951)
1 parent 9bec326 commit 3d74904

1 file changed

Lines changed: 110 additions & 110 deletions

File tree

  • packages/opencode/src/cli

packages/opencode/src/cli/ui.ts

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -3,131 +3,131 @@ import { EOL } from "os"
33
import { NamedError } from "@opencode-ai/shared/util/error"
44
import { logo as glyphs } from "./logo"
55

6-
export namespace UI {
7-
const wordmark = [
8-
`⠀ ▄ `,
9-
`█▀▀█ █▀▀█ █▀▀█ █▀▀▄ █▀▀▀ █▀▀█ █▀▀█ █▀▀█`,
10-
`█ █ █ █ █▀▀▀ █ █ █ █ █ █ █ █▀▀▀`,
11-
`▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀`,
12-
]
6+
const wordmark = [
7+
`⠀ ▄ `,
8+
`█▀▀█ █▀▀█ █▀▀█ █▀▀▄ █▀▀▀ █▀▀█ █▀▀█ █▀▀█`,
9+
`█ █ █ █ █▀▀▀ █ █ █ █ █ █ █ █▀▀▀`,
10+
`▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀`,
11+
]
1312

14-
export const CancelledError = NamedError.create("UICancelledError", z.void())
13+
export const CancelledError = NamedError.create("UICancelledError", z.void())
1514

16-
export const Style = {
17-
TEXT_HIGHLIGHT: "\x1b[96m",
18-
TEXT_HIGHLIGHT_BOLD: "\x1b[96m\x1b[1m",
19-
TEXT_DIM: "\x1b[90m",
20-
TEXT_DIM_BOLD: "\x1b[90m\x1b[1m",
21-
TEXT_NORMAL: "\x1b[0m",
22-
TEXT_NORMAL_BOLD: "\x1b[1m",
23-
TEXT_WARNING: "\x1b[93m",
24-
TEXT_WARNING_BOLD: "\x1b[93m\x1b[1m",
25-
TEXT_DANGER: "\x1b[91m",
26-
TEXT_DANGER_BOLD: "\x1b[91m\x1b[1m",
27-
TEXT_SUCCESS: "\x1b[92m",
28-
TEXT_SUCCESS_BOLD: "\x1b[92m\x1b[1m",
29-
TEXT_INFO: "\x1b[94m",
30-
TEXT_INFO_BOLD: "\x1b[94m\x1b[1m",
31-
}
15+
export const Style = {
16+
TEXT_HIGHLIGHT: "\x1b[96m",
17+
TEXT_HIGHLIGHT_BOLD: "\x1b[96m\x1b[1m",
18+
TEXT_DIM: "\x1b[90m",
19+
TEXT_DIM_BOLD: "\x1b[90m\x1b[1m",
20+
TEXT_NORMAL: "\x1b[0m",
21+
TEXT_NORMAL_BOLD: "\x1b[1m",
22+
TEXT_WARNING: "\x1b[93m",
23+
TEXT_WARNING_BOLD: "\x1b[93m\x1b[1m",
24+
TEXT_DANGER: "\x1b[91m",
25+
TEXT_DANGER_BOLD: "\x1b[91m\x1b[1m",
26+
TEXT_SUCCESS: "\x1b[92m",
27+
TEXT_SUCCESS_BOLD: "\x1b[92m\x1b[1m",
28+
TEXT_INFO: "\x1b[94m",
29+
TEXT_INFO_BOLD: "\x1b[94m\x1b[1m",
30+
}
3231

33-
export function println(...message: string[]) {
34-
print(...message)
35-
process.stderr.write(EOL)
36-
}
32+
export function println(...message: string[]) {
33+
print(...message)
34+
process.stderr.write(EOL)
35+
}
3736

38-
export function print(...message: string[]) {
39-
blank = false
40-
process.stderr.write(message.join(" "))
41-
}
37+
export function print(...message: string[]) {
38+
blank = false
39+
process.stderr.write(message.join(" "))
40+
}
4241

43-
let blank = false
44-
export function empty() {
45-
if (blank) return
46-
println("" + Style.TEXT_NORMAL)
47-
blank = true
48-
}
42+
let blank = false
43+
export function empty() {
44+
if (blank) return
45+
println("" + Style.TEXT_NORMAL)
46+
blank = true
47+
}
4948

50-
export function logo(pad?: string) {
51-
if (!process.stdout.isTTY && !process.stderr.isTTY) {
52-
const result = []
53-
for (const row of wordmark) {
54-
if (pad) result.push(pad)
55-
result.push(row)
56-
result.push(EOL)
57-
}
58-
return result.join("").trimEnd()
49+
export function logo(pad?: string) {
50+
if (!process.stdout.isTTY && !process.stderr.isTTY) {
51+
const result = []
52+
for (const row of wordmark) {
53+
if (pad) result.push(pad)
54+
result.push(row)
55+
result.push(EOL)
5956
}
57+
return result.join("").trimEnd()
58+
}
6059

61-
const result: string[] = []
62-
const reset = "\x1b[0m"
63-
const left = {
64-
fg: "\x1b[90m",
65-
shadow: "\x1b[38;5;235m",
66-
bg: "\x1b[48;5;235m",
67-
}
68-
const right = {
69-
fg: reset,
70-
shadow: "\x1b[38;5;238m",
71-
bg: "\x1b[48;5;238m",
72-
}
73-
const gap = " "
74-
const draw = (line: string, fg: string, shadow: string, bg: string) => {
75-
const parts: string[] = []
76-
for (const char of line) {
77-
if (char === "_") {
78-
parts.push(bg, " ", reset)
79-
continue
80-
}
81-
if (char === "^") {
82-
parts.push(fg, bg, "▀", reset)
83-
continue
84-
}
85-
if (char === "~") {
86-
parts.push(shadow, "▀", reset)
87-
continue
88-
}
89-
if (char === " ") {
90-
parts.push(" ")
91-
continue
92-
}
93-
parts.push(fg, char, reset)
60+
const result: string[] = []
61+
const reset = "\x1b[0m"
62+
const left = {
63+
fg: "\x1b[90m",
64+
shadow: "\x1b[38;5;235m",
65+
bg: "\x1b[48;5;235m",
66+
}
67+
const right = {
68+
fg: reset,
69+
shadow: "\x1b[38;5;238m",
70+
bg: "\x1b[48;5;238m",
71+
}
72+
const gap = " "
73+
const draw = (line: string, fg: string, shadow: string, bg: string) => {
74+
const parts: string[] = []
75+
for (const char of line) {
76+
if (char === "_") {
77+
parts.push(bg, " ", reset)
78+
continue
79+
}
80+
if (char === "^") {
81+
parts.push(fg, bg, "▀", reset)
82+
continue
83+
}
84+
if (char === "~") {
85+
parts.push(shadow, "▀", reset)
86+
continue
87+
}
88+
if (char === " ") {
89+
parts.push(" ")
90+
continue
9491
}
95-
return parts.join("")
92+
parts.push(fg, char, reset)
9693
}
97-
glyphs.left.forEach((row, index) => {
98-
if (pad) result.push(pad)
99-
result.push(draw(row, left.fg, left.shadow, left.bg))
100-
result.push(gap)
101-
const other = glyphs.right[index] ?? ""
102-
result.push(draw(other, right.fg, right.shadow, right.bg))
103-
result.push(EOL)
104-
})
105-
return result.join("").trimEnd()
94+
return parts.join("")
10695
}
96+
glyphs.left.forEach((row, index) => {
97+
if (pad) result.push(pad)
98+
result.push(draw(row, left.fg, left.shadow, left.bg))
99+
result.push(gap)
100+
const other = glyphs.right[index] ?? ""
101+
result.push(draw(other, right.fg, right.shadow, right.bg))
102+
result.push(EOL)
103+
})
104+
return result.join("").trimEnd()
105+
}
107106

108-
export async function input(prompt: string): Promise<string> {
109-
const readline = require("readline")
110-
const rl = readline.createInterface({
111-
input: process.stdin,
112-
output: process.stdout,
113-
})
107+
export async function input(prompt: string): Promise<string> {
108+
const readline = require("readline")
109+
const rl = readline.createInterface({
110+
input: process.stdin,
111+
output: process.stdout,
112+
})
114113

115-
return new Promise((resolve) => {
116-
rl.question(prompt, (answer: string) => {
117-
rl.close()
118-
resolve(answer.trim())
119-
})
114+
return new Promise((resolve) => {
115+
rl.question(prompt, (answer: string) => {
116+
rl.close()
117+
resolve(answer.trim())
120118
})
121-
}
119+
})
120+
}
122121

123-
export function error(message: string) {
124-
if (message.startsWith("Error: ")) {
125-
message = message.slice("Error: ".length)
126-
}
127-
println(Style.TEXT_DANGER_BOLD + "Error: " + Style.TEXT_NORMAL + message)
122+
export function error(message: string) {
123+
if (message.startsWith("Error: ")) {
124+
message = message.slice("Error: ".length)
128125
}
126+
println(Style.TEXT_DANGER_BOLD + "Error: " + Style.TEXT_NORMAL + message)
127+
}
129128

130-
export function markdown(text: string): string {
131-
return text
132-
}
129+
export function markdown(text: string): string {
130+
return text
133131
}
132+
133+
export * as UI from "./ui"

0 commit comments

Comments
 (0)