fixed ui when horizontal but color bug

This commit is contained in:
2024-10-01 19:53:19 +02:00
parent f77c04c908
commit 8165e80b05
+12 -13
View File
@@ -14,7 +14,7 @@ import (
"golang.org/x/term" "golang.org/x/term"
) )
func RenderLine(frameLine, line_ string, x int, fm *map[int]string, lm *map[int]string) string { func RenderLine(frameLine, line_ string, x int, fm *map[int]string, lm map[int]string) string {
frame := []rune(frameLine) frame := []rune(frameLine)
line := []rune(line_) line := []rune(line_)
@@ -22,11 +22,8 @@ func RenderLine(frameLine, line_ string, x int, fm *map[int]string, lm *map[int]
if i >= x && i-x < len(line) { if i >= x && i-x < len(line) {
frame[i] = line[i-x] frame[i] = line[i-x]
delete(*fm, i) delete(*fm, i)
} if v, ok := lm[i-x]; ok {
if v, ok := (*lm)[i-x]; ok { (*fm)[i] = v
if i-x > 0 {
delete(*lm, i-x)
(*lm)[i] = v
} }
} }
} }
@@ -40,8 +37,13 @@ func RenderOnFrame(c Component, frame *[]string) {
if int(componentData.Y)+i < len(*frame) { if int(componentData.Y)+i < len(*frame) {
fo, fm := CompressString((*frame)[int(componentData.Y)+i], "") fo, fm := CompressString((*frame)[int(componentData.Y)+i], "")
lo, lm := CompressString(line, "") lo, lm := CompressString(line, "")
r := RenderLine(fo, lo, int(componentData.X), &fm, &lm) r := RenderLine(fo, lo, int(componentData.X), &fm, lm)
(*frame)[int(componentData.Y)+i] = DecompressString(r, fm, lm) // if strings.Contains(line, "info") {
// fmt.Printf("%#v\n", lm)
// for {
// }
// }
(*frame)[int(componentData.Y)+i] = DecompressString(r, fm)
} }
} }
} }
@@ -61,16 +63,13 @@ func CompressString(input, repl string) (string, map[int]string) {
return re.ReplaceAllString(input, repl), matchesMap return re.ReplaceAllString(input, repl), matchesMap
} }
func DecompressString(modified string, fm map[int]string, lm map[int]string) string { func DecompressString(modified string, fm map[int]string) string {
res := "" res := ""
for i, c := range modified { for i, c := range modified {
res += string(c)
if v, ok := fm[i]; ok { if v, ok := fm[i]; ok {
res += v res += v
} }
if v, ok := lm[i]; ok {
res += v
}
res += string(c)
} }
return res return res
} }