From 573058d86164fe67cb0826e147c235e7f27e5016 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 21 Jul 2024 18:41:04 +0530 Subject: [PATCH] Fix panic on empty style --- tools/tui/loop/api.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/tui/loop/api.go b/tools/tui/loop/api.go index 51396f911..1ac92c8fd 100644 --- a/tools/tui/loop/api.go +++ b/tools/tui/loop/api.go @@ -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