104 lines
2.6 KiB
Go

package main
import (
`embed`
"strings"
`text/template`
"github.com/go-playground/validator/v10"
)
var (
args = new(Args)
validate = validator.New(validator.WithRequiredStructEnabled())
)
const (
/*
fixedPad is a fixed "surrounding" pad always present (as minimum), even for values max len on columns.
*Must* be positive even, as <fixed left pad> and <fixed right pad> == fixedPad/2.
*/
fixedPad int = 2
/*
padChars is what fills the pads in table cells.
At the *LEAST*, a cell will be "<fixedPad/2 * padChars><str><fixedPad/2 * padChars>"
*/
padChars string = " "
)
var (
//go:embed "_tpl"
tplDir embed.FS
tblTpl *template.Template = template.Must(template.New("").Funcs(
template.FuncMap{
"legacy4": tplClass4Iter,
"addrs": tplAddrIter,
"mask4": tplMaskIter4,
},
).ParseFS(tplDir, "_tpl/*.tpl"))
)
var (
// Primarily output formatting stuff in this block.
sectSepCnt = 48
sectSep1 = strings.Repeat("=", sectSepCnt)
sectSep2 = strings.Repeat("-", sectSepCnt)
sectSep3 = strings.Repeat(".", sectSepCnt)
// tblFmts contains a lookup of map[<is plain>]*tableFormatter.
tblFmts map[bool]*tableFormatter = map[bool]*tableFormatter{
// Plaintext/ASCII-only
true: &tableFormatter{
TopLeftHdr: "*", // Or _
TopFillHdr: "*", // ""
TopColSepHdr: "*", // ""
TopRightHdr: "*", // ""
ColSepHdr: "|",
BottomLeftHdr: "*", // Or +
BottomFillHdr: "*", // Or -
BottomColSepHdr: "*", // Or +
BottomRightHdr: "*", // ""
Left: "|",
Fill: "-",
LineColSep: "|",
LineLeft: "|",
LineRight: "|",
ColSep: "|",
Right: "|",
LastLeft: "+",
LastFill: "-",
LastSep: "-",
LastRight: "+",
SuppressLineSep: true,
NoUpperTitle: false,
NoBoldTitle: true,
},
// Unicode/UTF-8
// https://en.wikipedia.org/wiki/Box-drawing_characters
false: &tableFormatter{
TopLeftHdr: "┏",
TopFillHdr: "━",
TopColSepHdr: "┳",
TopRightHdr: "┓",
ColSepHdr: "┃",
BottomLeftHdr: "┣",
BottomFillHdr: "━",
BottomColSepHdr: "╇",
BottomRightHdr: "┫",
Left: "┃",
Fill: "─",
LineColSep: "┼",
LineLeft: "┠",
LineRight: "┨",
ColSep: "│",
Right: "┃",
LastLeft: "┗",
LastFill: "━",
LastSep: "┷",
LastRight: "┛",
SuppressLineSep: false,
NoUpperTitle: true,
NoBoldTitle: false,
},
}
)