-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewframe.go
51 lines (43 loc) · 1.06 KB
/
viewframe.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package voidterm
import (
"github.com/1f349/voidterm/termutil"
"strings"
)
type ViewFrame struct {
// Cells stores individual cells in [row][col] format
Cells [][]*termutil.Cell
}
func (v *ViewFrame) RenderRawString() string {
var sb strings.Builder
for _, row := range v.Cells {
for _, cell := range row {
if cell == nil {
sb.WriteRune(' ')
} else {
sb.WriteRune(cell.Rune().Rune)
}
}
sb.WriteByte('\n')
}
return sb.String()
}
func ViewFrameFromBuffer(buffer *termutil.Buffer) *ViewFrame {
frame := &ViewFrame{}
frame.Cells = make([][]*termutil.Cell, buffer.ViewHeight())
for i := range frame.Cells {
frame.Cells[i] = make([]*termutil.Cell, buffer.ViewWidth())
}
// draw base content for each row
for viewY := uint16(0); viewY < buffer.ViewHeight(); viewY++ {
for viewX := uint16(0); viewX < buffer.ViewWidth(); viewX++ {
cell := buffer.GetCell(viewX, viewY)
// we don't need to draw empty cells
if cell == nil || cell.Rune().Rune == 0 {
continue
}
a := *cell
frame.Cells[viewY][viewX] = &a
}
}
return frame
}