package receipt import ( "strings" "unicode/utf8" "uberbringer/internal/pkg/escpos" ) // textStyle is how a run of block text prints. Borders, fills, padding and // margins are always plain. type textStyle struct { bold bool underline escpos.Underline invert bool } // run is text printed in one style. Each rune is one character cell. type run struct { text string style textStyle } // blockLine is one printed line of a block. type blockLine []run func plain(s string) run { return run{text: s} } func spaces(n int) string { return strings.Repeat(" ", max(n, 0)) } // fill repeats pattern to exactly n runes. func fill(pattern string, n int) string { p := []rune(pattern) if n <= 0 || len(p) == 0 { return "" } out := make([]rune, n) for i := range out { out[i] = p[i%len(p)] } return string(out) } // fillTowards is fill for the n runes before (towards the right end) or // after something, laid out so that the pattern starts next to it. A // dashed fill then always ends in a dash, never a space, at a label. func fillTowards(pattern string, n int, before bool) string { p := []rune(pattern) if n <= 0 || len(p) == 0 { return "" } out := make([]rune, n) for i := range out { d := i if before { d = n - 1 - i } out[i] = p[d%len(p)] } return string(out) } // truncate shortens s to at most n runes, marking the cut with "...". func truncate(s string, n int) string { r := []rune(s) switch { case n <= 0: return "" case len(r) <= n: return s case n <= 3: return string(r[:n]) } return string(r[:n-3]) + "..." } func runeLen(s string) int { return utf8.RuneCountInString(s) }