-
Notifications
You must be signed in to change notification settings - Fork 0
/
row.go
60 lines (47 loc) · 1.12 KB
/
row.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
52
53
54
55
56
57
58
59
60
package main
import (
"io"
"math"
"slices"
)
func NewRow() *Row {
return &Row{}
}
func (r *Row) Print(w io.Writer) {
cursorPositionVertical := 0
numBoxes := len(r.Boxes)
endOfBoxReachedCounter := 0
fullyPrintedBoxes := []*Box{}
maxHeight := 0
for _, box := range r.Boxes {
maxHeight = int(math.Max(float64(maxHeight), float64(box.GetRealHeight())))
}
for {
for _, box := range r.Boxes {
if box.GetRealHeight() < maxHeight && cursorPositionVertical >= box.GetRealHeight() {
fillUpRowText := fillUpRow(*box)
PrintRaw(fillUpRowText, w)
}
err := box.PrintLine(cursorPositionVertical, w)
if err != nil && err.Error() == END_OF_BOX_REACHED_ERROR && !slices.Contains(fullyPrintedBoxes, box) {
endOfBoxReachedCounter++
fullyPrintedBoxes = append(fullyPrintedBoxes, box)
}
}
if numBoxes <= endOfBoxReachedCounter {
break
}
PrintRaw("\n", w)
cursorPositionVertical++
}
}
func (r *Row) Add(box *Box) {
r.Boxes = append(r.Boxes, box)
}
func fillUpRow(box Box) string {
var emptyContent string
for i := 0; i < box.GetRealWidth(); i++ {
emptyContent += " "
}
return emptyContent
}