Park remaining local WIP on main. TUI archived, CLI/kernel edits, glass. Sort later. Broken is fine.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@neuron/glass",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "bun test",
|
||||
"typecheck": "tsgo --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/bun": "catalog:",
|
||||
"@types/bun": "catalog:",
|
||||
"@typescript/native-preview": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export type Row = { text: string; fg: readonly [number, number, number]; bg: readonly [number, number, number] }[]
|
||||
|
||||
export function presentRows(write: (chunk: string) => void, rows: Row[]): void {
|
||||
const out: string[] = ["\x1b[?25l"]
|
||||
for (let y = 0; y < rows.length; y++) {
|
||||
out.push(`\x1b[${y + 1};1H`)
|
||||
for (const span of rows[y] ?? []) {
|
||||
const [fr, fg, fb] = span.fg
|
||||
const [br, bg, bb] = span.bg
|
||||
out.push(`\x1b[38;2;${fr};${fg};${fb}m\x1b[48;2;${br};${bg};${bb}m${span.text}`)
|
||||
}
|
||||
}
|
||||
out.push("\x1b[0m")
|
||||
write(out.join(""))
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { presentRows } from "../src/index.ts"
|
||||
|
||||
describe("presentRows", () => {
|
||||
test("writes the spans", () => {
|
||||
const chunks: string[] = []
|
||||
presentRows((chunk) => chunks.push(chunk), [[{ text: "neuron", fg: [255, 225, 74], bg: [10, 10, 10] }]])
|
||||
const out = chunks.join("")
|
||||
expect(out.includes("neuron")).toBe(true)
|
||||
expect(out.includes("\x1b[38;2;255;225;74m")).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "@tsconfig/bun/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"noUncheckedIndexedAccess": false
|
||||
},
|
||||
"include": ["src", "test"]
|
||||
}
|
||||
Reference in New Issue
Block a user