Repository navigation
Expand file tree
/
Copy pathbanner.ts
More file actions
71 lines (65 loc) · 1.92 KB
/
Copy pathbanner.ts
File metadata and controls
71 lines (65 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { sleep } from '@sim/utils/helpers'
import chalk from 'chalk'
import { restoreTerminal } from './terminal.ts'
import { isRich, theme } from './theme.ts'
const WORDMARK = [' ▀ ', '▄▀▀▀ █ █▀█▀█', '▀▀▀▄ █ █ █ █', '▄▄▄▀ █ █ █ █'] as const
const TAGLINE = 'the AI workspace'
const WIDTH = Math.max(...WORDMARK.map((row) => row.length))
const EDGE = chalk.hex('#ffffff')
const SHELL = chalk.hex('#3d3d3d')
const FRAME_DELAY_MS = 35
function renderRow(row: string, edge: number): string {
let out = ''
for (let col = 0; col < row.length; col++) {
const ch = row[col]
if (ch === ' ') {
out += ch
} else if (col < edge - 1) {
out += theme.accent(ch)
} else if (col <= edge) {
out += EDGE(ch)
} else {
out += SHELL(ch)
}
}
return out
}
function paintFrame(edge: number, redraw: boolean): void {
if (redraw) process.stdout.write(`\x1b[${WORDMARK.length + 1}F`)
for (const row of WORDMARK) {
process.stdout.write(`\x1b[K${renderRow(row, edge)}\n`)
}
process.stdout.write(`\x1b[K${theme.muted(TAGLINE)}\n`)
}
/** Animated half-block sim wordmark; degrades to a plain line off-TTY/CI. */
export async function showBanner(): Promise<void> {
const animated =
process.stdout.isTTY &&
isRich() &&
!process.env.CI &&
!process.env.VITEST &&
(process.stdout.columns ?? 80) >= WIDTH + 2
console.log()
if (!animated) {
console.log(`◆ Sim — ${TAGLINE}`)
console.log()
return
}
const onSigint = () => {
restoreTerminal()
process.exit(130)
}
process.once('SIGINT', onSigint)
process.stdout.write('\x1b[?25l')
try {
paintFrame(-2, false)
for (let edge = 0; edge <= WIDTH + 2; edge++) {
await sleep(FRAME_DELAY_MS)
paintFrame(edge, true)
}
} finally {
process.stdout.write('\x1b[?25h')
process.removeListener('SIGINT', onSigint)
}
console.log()
}