(text string, width int)
| 1159 | } |
| 1160 | |
| 1161 | func wrapVisibleLine(text string, width int) []string { |
| 1162 | if width <= 0 { |
| 1163 | return []string{text} |
| 1164 | } |
| 1165 | var lines []string |
| 1166 | var current strings.Builder |
| 1167 | currentWidth := 0 |
| 1168 | inEscape := false |
| 1169 | inCSI := false |
| 1170 | for _, r := range text { |
| 1171 | if inEscape { |
| 1172 | current.WriteRune(r) |
| 1173 | if r == '[' && !inCSI { |
| 1174 | inCSI = true |
| 1175 | continue |
| 1176 | } |
| 1177 | if !inCSI || (r >= '@' && r <= '~') { |
| 1178 | inEscape = false |
| 1179 | inCSI = false |
| 1180 | } |
| 1181 | continue |
| 1182 | } |
| 1183 | if r == '\x1b' { |
| 1184 | inEscape = true |
| 1185 | current.WriteRune(r) |
| 1186 | continue |
| 1187 | } |
| 1188 | runeWidth := runewidth.RuneWidth(r) |
| 1189 | if currentWidth > 0 && currentWidth+runeWidth > width { |
| 1190 | lines = append(lines, current.String()) |
| 1191 | current.Reset() |
| 1192 | currentWidth = 0 |
| 1193 | } |
| 1194 | current.WriteRune(r) |
| 1195 | currentWidth += runeWidth |
| 1196 | } |
| 1197 | lines = append(lines, current.String()) |
| 1198 | return lines |
| 1199 | } |
| 1200 | |
| 1201 | func splitNonEmptyViewportLines(text string) []string { |
| 1202 | if text == "" { |
no test coverage detected