okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
f7fcae1
main
1// Package display holds small rendering helpers, not an application framework. 2package display 3 4import ( 5"strings" 6"unicode" 7) 8 9// BodyRows receives already-measured chrome heights, not guessed constants. 10func BodyRows (total ,header ,footer int )int { 11return max (0 ,max (0 ,total )- max (0 ,header )- max (0 ,footer )) 12} 13 14// Window keeps the current row visible and returns a half-open item range. 15// It only applies to fixed-height, one-line rows. 16func Window (total ,cursor ,top ,height int ) (int ,int ) { 17if total <= 0 || height <= 0 { 18return 0 ,0 19 } 20cursor = min (max (0 ,cursor ),total - 1 ) 21top = min (max (0 ,top ),max (0 ,total - height )) 22if cursor < top { 23top = cursor 24 } 25if cursor >= top + height { 26top = cursor - height + 1 27 } 28return top ,min (total ,top + height ) 29} 30 31// SingleLine accepts plain data, not trusted ANSI. It neutralizes terminal 32// controls by replacing every C0/C1 control with a space. Escape parameters 33// remain visible text. This is deliberately not an ANSI-preserving sanitizer 34// or a Unicode spoofing defense. Application styling is added AFTER this call. 35func SingleLine (s string )string { 36return strings .Map (func (r rune )rune { 37if unicode .IsControl (r )|| r == '\u2028' || r == '\u2029' { 38return ' ' 39 } 40return r 41 },strings .ToValidUTF8 (s ,"\uFFFD" )) 42}