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

31 lines
787 B
Go

package main
import (
"bytes"
"context"
"sync/atomic"
)
// imgCounter assigns sequential [fig.N] numbers in render order so each
// rendered terminal image gets a unique caption number.
var imgCounter uint64
// TerminalImageBlock wraps the built-in image in a +----+ ASCII frame with
// a [fig.N caption] line beneath it.
//
// Content shape (same as built-in image): {src, alt, caption, width, height}.
func TerminalImageBlock(ctx context.Context, content map[string]any) string {
src := getString(content, "src")
alt := getString(content, "alt")
caption := getString(content, "caption")
if alt == "" {
alt = caption
}
n := atomic.AddUint64(&imgCounter, 1)
var buf bytes.Buffer
_ = terminalImageComponent(src, alt, caption, n).Render(ctx, &buf)
return buf.String()
}