From 95552235594b15d74922e606d2a3c54f7e05224a Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Fri, 12 Jul 2024 10:37:24 -0400 Subject: nil pointer management --- internal/render/instructions.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'internal/render/instructions.go') diff --git a/internal/render/instructions.go b/internal/render/instructions.go index b4823f2..27db5bd 100644 --- a/internal/render/instructions.go +++ b/internal/render/instructions.go @@ -35,6 +35,9 @@ type Instruction interface { } func overlap(over, under Instruction) overlapType { + if over == nil || under == nil { + return CoverNone + } ox, oy := over.Pos() ux, uy := under.Pos() os, us := over.Len(), under.Len() @@ -78,6 +81,9 @@ func overlap(over, under Instruction) overlapType { // No matter what, the over instruction never changes so only variations of // under needs to be returned. func squash(over Instruction, under Instruction, ot overlapType) []Instruction { + if over == nil || under == nil { + return nil + } ox, _ := over.Pos() ux, _ := under.Pos() os, us := over.Len(), under.Len() @@ -174,7 +180,7 @@ type ClearInstruction struct { func (c ClearInstruction) Write(w io.Writer) { // Erase as many characters as the size of the instruction. - msg := reach(c) + "\033[K" + strings.Repeat(" ", c.Size) + msg := reach(c) + "\033[0m" + strings.Repeat(" ", c.Size) // TODO: maybe implement a way to log stuff like writestring errors io.WriteString(w, msg) } -- cgit v1.2.3