fixed color bug

This commit is contained in:
2024-10-03 13:19:43 +02:00
parent 3ceaa13b3f
commit 7e714abddf
2 changed files with 3 additions and 23 deletions
+1 -1
View File
@@ -34,7 +34,6 @@ func NewScreen(c Component) *Screen {
} }
func (s *Screen) Render() { func (s *Screen) Render() {
Clear()
width, height := GetTerminalSize() width, height := GetTerminalSize()
frame := NewFrame(width, height) frame := NewFrame(width, height)
data := s.component.GetComponentData() data := s.component.GetComponentData()
@@ -48,6 +47,7 @@ func (s *Screen) Render() {
data.IsActive = true data.IsActive = true
data.DefaultColor = colors.Reset data.DefaultColor = colors.Reset
RenderOnFrame(s.component, &frame) RenderOnFrame(s.component, &frame)
Clear()
fmt.Print(strings.Join(frame, "\n")) fmt.Print(strings.Join(frame, "\n"))
} }
+2 -22
View File
@@ -14,11 +14,6 @@ import (
"golang.org/x/term" "golang.org/x/term"
) )
func LogToFile(s string, a ...any) {
existingData, _ := os.ReadFile("log.log")
os.WriteFile("log.log", []byte(string(existingData)+"\n"+fmt.Sprintf(s, a...)), 0644)
}
func RenderLine(frame_, line_ string, x int, fm map[int]string, lm map[int]string) string { func RenderLine(frame_, line_ string, x int, fm map[int]string, lm map[int]string) string {
var res strings.Builder var res strings.Builder
frame := []rune(frame_) frame := []rune(frame_)
@@ -26,29 +21,17 @@ func RenderLine(frame_, line_ string, x int, fm map[int]string, lm map[int]strin
for i := range frame { for i := range frame {
if i >= x && i-x < len(line) { if i >= x && i-x < len(line) {
// Render character from 'line'
res.WriteRune(line[i-x])
// Add escape sequence from line's map (lm), if any
if v, ok := lm[i-x]; ok { if v, ok := lm[i-x]; ok {
res.WriteString(v) res.WriteString(v)
} }
res.WriteRune(line[i-x])
} else { } else {
// Render character from 'frame'
res.WriteRune(frame[i])
// Add escape sequence from frame's map (fm), if any
if v, ok := fm[i]; ok { if v, ok := fm[i]; ok {
res.WriteString(v) res.WriteString(v)
} }
res.WriteRune(frame[i])
} }
} }
// Log the result string for debugging
// LogToFile("line_: %#v", line_)
// LogToFile("lm: %#v", lm)
// LogToFile("result: %#v\n", res.String())
return res.String() return res.String()
} }
@@ -81,9 +64,6 @@ 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)
LogToFile("line: %#v", line)
LogToFile("Line Map (lm): %#v", lm)
LogToFile("Compressed Line: %#v\n", lo)
(*frame)[int(componentData.Y)+i] = RenderLine(fo, lo, componentData.X, fm, lm) (*frame)[int(componentData.Y)+i] = RenderLine(fo, lo, componentData.X, fm, lm)
} }
} }