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 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() }