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>
31 lines
787 B
Go
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()
|
|
}
|