themes-terminal/code_console.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

45 lines
1.2 KiB
Go

package main
import (
"bytes"
"context"
"git.dev.alexdunmow.com/block/core/blocks"
)
// CodeConsoleBlockMeta defines metadata for the console code block.
var CodeConsoleBlockMeta = blocks.BlockMeta{
Key: "code_console",
Title: "Console Block",
Description: "Shell prompt + command + output, with language hint",
Source: "terminal",
Category: blocks.CategoryContent,
}
// CodeConsoleData is the parsed content for the code_console block.
type CodeConsoleData struct {
Prompt string
Command string
Output string
Language string
}
// CodeConsoleBlock renders an interactive-looking shell block.
// Content shape: {prompt, command, output, language}.
func CodeConsoleBlock(ctx context.Context, content map[string]any) string {
data := CodeConsoleData{
Prompt: getStringDefault(content, "prompt", "$"),
Command: getString(content, "command"),
Output: getString(content, "output"),
Language: getStringDefault(content, "language", "shell"),
}
// Empty state: render nothing if both command and output are blank.
if data.Command == "" && data.Output == "" {
return ""
}
var buf bytes.Buffer
_ = codeConsoleComponent(data).Render(ctx, &buf)
return buf.String()
}