forked from emprcl/runal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
34 lines (28 loc) · 678 Bytes
/
debug.go
File metadata and controls
34 lines (28 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package runal
import (
"fmt"
)
const maxDebugBufferSize = 100
var debugStyle = style{
background: color("9"),
foreground: color("15"),
}
func (c *Canvas) Debug(messages ...any) {
msg := fmt.Sprint(messages...)
c.debugBuffer = append(c.debugBuffer, msg)
if len(c.debugBuffer) > min(maxDebugBufferSize, c.termHeight) {
c.debugBuffer = c.debugBuffer[len(c.debugBuffer)-min(maxDebugBufferSize, c.termHeight):]
}
}
func (c *Canvas) renderDebug() {
if len(c.debugBuffer) == 0 {
return
}
resetCursorPosition()
for y, msg := range c.debugBuffer {
if y >= c.termHeight-1 {
continue
}
fmt.Fprint(c.output, debugStyle.render(fmt.Sprintf("%s\r\n", msg)))
}
}