commit a4fd300

Hubert Hirtz  ·  2020-06-13 09:34:50 +0000 UTC
parent bff8eb4
Make renderedHeight correct
2 files changed,  +24, -5
+23, -4
 1@@ -63,12 +63,13 @@ func (line *Line) RenderedHeight(screenWidth int) (height int) {
 2 	return
 3 }
 4 
 5+// TODO clean and understand the fucking function
 6 func (line *Line) computeRenderedHeight(screenWidth int) {
 7 	var lastSP Point
 8 	line.renderedHeight = 1
 9 	x := 0
10 
11-	fmt.Printf("\n%d %q\n", screenWidth, line.Content)
12+	//fmt.Printf("\n%d %q\n", screenWidth, line.Content)
13 	for _, sp := range line.SplitPoints {
14 		l := sp.X - lastSP.X
15 
16@@ -77,16 +78,34 @@ func (line *Line) computeRenderedHeight(screenWidth int) {
17 		} else if screenWidth < l {
18 			line.renderedHeight += (x + l) / screenWidth
19 			x = (x + l) % screenWidth
20+		} else if screenWidth == l {
21+			if x == 0 {
22+				line.renderedHeight++
23+			} else {
24+				line.renderedHeight += 2
25+				x = 0
26+			}
27 		} else if screenWidth < x+l {
28 			line.renderedHeight++
29-			x = l % screenWidth
30+			if sp.Split {
31+				x = l % screenWidth
32+			} else {
33+				x = 0
34+			}
35+		} else if screenWidth == x+l {
36+			line.renderedHeight++
37+			x = 0
38 		} else {
39-			x = (x + l) % screenWidth
40+			x = x + l
41 		}
42 
43-		fmt.Printf("%d %d %t occupied by %q\n", line.renderedHeight, x, sp.Split, line.Content[:sp.I])
44+		//fmt.Printf("%d %d %t occupied by %q\n", line.renderedHeight, x, sp.Split, line.Content[:sp.I])
45 		lastSP = sp
46 	}
47+
48+	if x == 0 && 1 < line.renderedHeight {
49+		line.renderedHeight--
50+	}
51 }
52 
53 func (line *Line) computeSplitPoints() {
+1, -1
1@@ -104,7 +104,7 @@ func TestRenderedHeight(t *testing.T) {
2 	assertRenderedHeight(t, "have a good day!", 2, 7)  // |ha|ve|a |go|od|da|y!|
3 	assertRenderedHeight(t, "have a good day!", 3, 5)  // |hav|e a|goo|d d|ay!|
4 	assertRenderedHeight(t, "have a good day!", 4, 4)  // |have|a   |good|day!|
5-	assertRenderedHeight(t, "have a good day!", 5, 3)  // |have |a good|day! |
6+	assertRenderedHeight(t, "have a good day!", 5, 4)  // |have |a    |good |day! |
7 	assertRenderedHeight(t, "have a good day!", 6, 3)  // |have a|good  |day!  |
8 	assertRenderedHeight(t, "have a good day!", 7, 3)  // |have a |good   |day!   |
9 	assertRenderedHeight(t, "have a good day!", 8, 3)  // |have a  |good    |day!    |