First version

This commit is contained in:
2024-09-29 13:40:46 +02:00
parent 8592b1cc50
commit 716d1d4a08
7 changed files with 113 additions and 102 deletions
+5 -35
View File
@@ -13,48 +13,18 @@ import (
"golang.org/x/term"
)
// NOTE: for now keep this code in case of needing it later
// func renderLine(frameLine, line string, x int) string {
// result := []rune(frameLine)
// lineRunes := []rune(line)
// x += strings.Count(string(result[:(x+1)]), "\t") + strings.Count(string(result[:(x+1)]), "\b")
// for range strings.Count(line, "\t") + strings.Count(line, "\b") {
// result = append(result, ' ')
// }
// frameLen := len(result)
// for i := 0; i < len(lineRunes) && x+i < frameLen; i++ {
// result[x+i] = lineRunes[i]
// }
// return string(result)
// }
// lineRunes := []rune(line)
// x += strings.Count(string(frameLine[:(x+1)]), "\b")
// result = append(result, []rune(strings.Repeat(" ", strings.Count(line, "\t")))...)
// frameLen := len(result)
// d := strings.Count(frameLine, "\b") - strings.Count(string(result), "\b")
// for i := 0; i < len(lineRunes) && x+i < frameLen; i++ {
// result[x+i] = lineRunes[i]
// }
// NOTE: for now keep this code in case of needing it later
func renderLine(frameLine, line_ string, x int) string {
result := []rune(frameLine)
frame := []rune(frameLine)
line := []rune(line_)
i := 0
v := 0
for j, c := range result {
for j, c := range frame {
if i+j >= x && v < len(line) {
if c != '\b' && line[v] == '\t' {
result = append(result, ' ')
frame = append(frame[:i+j], append([]rune{' '}, frame[i+j:]...)...)
}
result[i+j] = line[v]
frame[i+j] = line[v]
v++
}
if c == '\b' {
@@ -62,7 +32,7 @@ func renderLine(frameLine, line_ string, x int) string {
}
}
return string(result)
return string(frame)
}
func RenderOnFrame(c Component, frame *[]string) {