ansiSkip skips the first skipWidth visual columns of an ANSI-styled string and returns the remainder.
(s string, skipWidth int)
| 502 | // ansiSkip skips the first skipWidth visual columns of an ANSI-styled string |
| 503 | // and returns the remainder. |
| 504 | func ansiSkip(s string, skipWidth int) string { |
| 505 | width := 0 |
| 506 | inEscape := false |
| 507 | for i, r := range s { |
| 508 | if r == '\033' { |
| 509 | inEscape = true |
| 510 | continue |
| 511 | } |
| 512 | if inEscape { |
| 513 | if (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') { |
| 514 | inEscape = false |
| 515 | } |
| 516 | continue |
| 517 | } |
| 518 | if width >= skipWidth { |
| 519 | return s[i:] |
| 520 | } |
| 521 | width++ |
| 522 | } |
| 523 | return "" |
| 524 | } |
| 525 | |
| 526 | // overlayModal composites a modal on top of a background, centering the modal. |
| 527 | func overlayModal(background, modal string, screenWidth, screenHeight int) string { |