commit d448905

Hubert Hirtz  ·  2020-06-05 08:13:07 +0000 UTC
parent 09c94ce
Split lines between words
2 files changed,  +36, -17
+17, -9
 1@@ -33,6 +33,22 @@ type Line struct {
 2 	renderedHeight int
 3 }
 4 
 5+func NewLine(t time.Time, isStatus bool, content string) (line Line) {
 6+	line.Time = t
 7+	line.IsStatus = isStatus
 8+	line.Content = content
 9+
10+	line.Invalidate()
11+	line.computeSplitPoints()
12+
13+	return
14+}
15+
16+func NewLineNow(content string) (line Line) {
17+	line = NewLine(time.Now(), false, content)
18+	return
19+}
20+
21 func (line *Line) Invalidate() {
22 	line.renderedHeight = -1
23 }
24@@ -194,15 +210,7 @@ func (bs *BufferList) AddLine(idx int, line string, t time.Time, isStatus bool)
25 			line = fmt.Sprintf("\x02%02d:%02d\x00 %s", hour, minute, line)
26 		}
27 
28-		l := Line{
29-			Time:     t,
30-			IsStatus: isStatus,
31-			Content:  line,
32-		}
33-
34-		l.computeSplitPoints()
35-		l.Invalidate()
36-
37+		l := NewLine(t, isStatus, line)
38 		b.Content = append(b.Content, l)
39 	}
40 }
+19, -8
 1@@ -48,10 +48,7 @@ func New() (ui *UI, err error) {
 2 			{
 3 				Title:      "home",
 4 				Highlights: 0,
 5-				Content: []Line{{
 6-					Time:    time.Now(),
 7-					Content: homeMessages[0],
 8-				}},
 9+				Content:    []Line{NewLineNow(homeMessages[0])},
10 			},
11 		},
12 	}
13@@ -256,15 +253,29 @@ func (ui *UI) drawBuffer() {
14 
15 		rs := []rune(line.Content)
16 		x := 0
17+		spIdx := 0
18+		hasLineHadSplit := false
19 
20-		for _, r := range rs {
21-			if w <= x {
22+		for i, r := range rs {
23+			if hasLineHadSplit && (y-y0+1)*w <= line.SplitPoints[spIdx].X {
24 				y++
25 				x = 0
26+				hasLineHadSplit = false
27+			} else if w <= x {
28+				y++
29+				x = 0
30+				hasLineHadSplit = false
31 			}
32 
33-			if x == 0 && IsSplitRune(r) {
34-				continue
35+			if IsSplitRune(r) {
36+				if i == line.SplitPoints[spIdx].I {
37+					spIdx++
38+				}
39+				if x == 0 {
40+					continue
41+				}
42+
43+				hasLineHadSplit = true
44 			}
45 
46 			if colorState == 1 {