Fix panic on empty style

This commit is contained in:
Kovid Goyal 2024-07-21 18:41:04 +05:30
parent be772caeaf
commit 573058d861
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -223,9 +223,12 @@ func (self *Loop) Println(args ...any) {
}
func (self *Loop) style_region(style string, start_x, start_y, end_x, end_y int) string {
sgr := self.SprintStyled(style, "|")[2:]
sgr = sgr[:strings.IndexByte(sgr, 'm')]
return fmt.Sprintf("\x1b[%d;%d;%d;%d;%s$r", start_y+1, start_x+1, end_y+1, end_x+1, sgr)
sgr := self.SprintStyled(style, "|")
if len(sgr) > 2 {
sgr = sgr[2:strings.IndexByte(sgr, 'm')]
return fmt.Sprintf("\x1b[%d;%d;%d;%d;%s$r", start_y+1, start_x+1, end_y+1, end_x+1, sgr)
}
return ""
}
// Apply the specified style to the specified region of the screen (0-based