opencode/packages/cli-rs/script/gen/keybinds.ts
Simon Klee 6b1df0cceb
feat(cli-rs): add the native CLI and TUI (#63477)
Add packages/cli-rs, an OpenCode client written in Rust on OpenTUI's Rust crates. It is a client only.
2026-11-22 00:07:01 +01:00

29 lines
1.2 KiB
TypeScript

// Writes crates/ui/src/keymap/generated.rs from the TUI's keybind definitions: every name in definition order,
// its default as JSON text, and its description.
import { TuiKeybind } from "../../../tui/src/config/keybind"
const entries = Object.entries(TuiKeybind.Definitions)
const lines = [
"// Generated by script/gen/keybinds.ts from packages/tui/src/config/keybind.ts. Do not edit.",
"",
"/// A configurable keybind name: its default value as JSON text and its description.",
"pub struct Definition {",
" pub name: &'static str,",
" pub default: &'static str,",
" pub description: &'static str,",
"}",
"",
`pub const LEADER_DEFAULT: &str = ${JSON.stringify(TuiKeybind.LeaderDefault)};`,
"",
"pub const DEFINITIONS: &[Definition] = &[",
...entries.map(
([name, item]) =>
` Definition { name: ${JSON.stringify(name)}, default: ${JSON.stringify(JSON.stringify(item.default))}, description: ${JSON.stringify(item.description)} },`,
),
"];",
"",
]
const file = new URL("../../crates/ui/src/keymap/generated.rs", import.meta.url).pathname
await Bun.write(file, lines.join("\n"))
console.log(`keybinds: ${entries.length} definitions`)