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

47 lines
1.3 KiB
Go

package main
import (
"bytes"
"context"
"fmt"
"strings"
"git.dev.alexdunmow.com/block/core/blocks"
)
// ManpageHeaderBlockMeta defines metadata for the man-page header block.
var ManpageHeaderBlockMeta = blocks.BlockMeta{
Key: "manpage_header",
Title: "Man-page Header",
Description: "NAME(section) ... center ... version row, like a man-page top line",
Source: "terminal",
Category: blocks.CategoryLayout,
}
// ManpageHeaderData is the parsed content for the manpage_header block.
type ManpageHeaderData struct {
Name string
Section int
Version string
// Banner is the rendered top-line text: "NAME(1) ... version".
Banner string
}
// ManpageHeaderBlock renders the man-page top row.
// Content shape: {name, section, version}.
func ManpageHeaderBlock(ctx context.Context, content map[string]any) string {
data := ManpageHeaderData{
Name: strings.ToUpper(getStringDefault(content, "name", "PAGE")),
Section: getInt(content, "section", 1),
Version: getStringDefault(content, "version", "terminal v0.1.0"),
}
if data.Section < 1 {
data.Section = 1
}
data.Banner = fmt.Sprintf("%s(%d) %s %s", data.Name, data.Section, "—", data.Version)
var buf bytes.Buffer
_ = manpageHeaderComponent(data).Render(ctx, &buf)
return buf.String()
}