themes-terminal/keybind_table.go
Alex Dunmow 0a9b177f7c initial: theme plugin terminal
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/terminal.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:44 +08:00

57 lines
1.4 KiB
Go

package main
import (
"bytes"
"context"
"strings"
"git.dev.alexdunmow.com/block/core/blocks"
)
// KeybindTableBlockMeta defines metadata for the keybind table block.
var KeybindTableBlockMeta = blocks.BlockMeta{
Key: "keybind_table",
Title: "Keybinding Table",
Description: "Two-column key + action reference table",
Source: "terminal",
Category: blocks.CategoryContent,
}
// KeybindRow is a single keybind table row.
type KeybindRow struct {
Keys []string
Action string
}
// KeybindTableData is the parsed content for the keybind_table block.
type KeybindTableData struct {
Rows []KeybindRow
}
// KeybindTableBlock renders a key/action reference table.
// Content shape: {rows[{keys, action}]}.
func KeybindTableBlock(ctx context.Context, content map[string]any) string {
rows := getSlice(content, "rows")
tableRows := make([]KeybindRow, 0, len(rows))
for _, r := range rows {
keys := getString(r, "keys")
// Split combos on whitespace so we can render individual <kbd> elements.
parts := strings.Fields(keys)
if len(parts) == 0 && keys != "" {
parts = []string{keys}
}
tableRows = append(tableRows, KeybindRow{
Keys: parts,
Action: getString(r, "action"),
})
}
if len(tableRows) == 0 {
return ""
}
data := KeybindTableData{Rows: tableRows}
var buf bytes.Buffer
_ = keybindTableComponent(data).Render(ctx, &buf)
return buf.String()
}