commit a88a370

Hubert Hirtz  ·  2021-10-20 13:22:29 +0000 UTC
parent 8846bcc
Rework vertical lists
3 files changed,  +43, -37
+18, -24
 1@@ -368,51 +368,45 @@ func (bs *BufferList) idx(title string) int {
 2 
 3 func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, height int) {
 4 	width--
 5-	st := tcell.StyleDefault
 6-
 7-	for y := y0; y < y0+height; y++ {
 8-		for x := x0; x < x0+width; x++ {
 9-			screen.SetContent(x, y, ' ', nil, st)
10-		}
11-		screen.SetContent(x0+width, y, 0x2502, nil, st)
12-	}
13+	drawVerticalLine(screen, x0+width, y0, height)
14+	clearArea(screen, x0, y0, width, height)
15 
16 	indexPadding := 1 + int(math.Ceil(math.Log10(float64(len(bs.list)))))
17 	for i, b := range bs.list {
18-		st = tcell.StyleDefault
19 		x := x0
20 		y := y0 + i
21+		st := tcell.StyleDefault
22 		if b.unread {
23 			st = st.Bold(true)
24-		} else if y == bs.current {
25+		} else if i == bs.current {
26 			st = st.Underline(true)
27 		}
28 		if i == bs.clicked {
29 			st = st.Reverse(true)
30 		}
31 		if bs.showBufferNumbers {
32+			indexSt := st.Foreground(tcell.ColorGray)
33 			indexText := fmt.Sprintf("%d:", i)
34-			for ; x < x0+indexPadding-len(indexText); x++ {
35-				screen.SetContent(x, y, ' ', nil, tcell.StyleDefault)
36-			}
37-			printString(screen, &x, y, Styled(indexText, st.Foreground(tcell.ColorGrey)))
38+			printString(screen, &x, y, Styled(indexText, indexSt))
39+			x = x0 + indexPadding
40 		}
41+
42 		title := truncate(b.title, width-(x-x0), "\u2026")
43 		printString(screen, &x, y, Styled(title, st))
44-		if 0 < b.highlights {
45-			st = st.Foreground(tcell.ColorRed).Reverse(true)
46-			screen.SetContent(x, y, ' ', nil, st)
47-			x++
48-			printNumber(screen, &x, y, st, b.highlights)
49-			screen.SetContent(x, y, ' ', nil, st)
50-			x++
51-		}
52+
53 		if i == bs.clicked {
54-			st = tcell.StyleDefault.Reverse(true)
55+			st := tcell.StyleDefault.Reverse(true)
56 			for ; x < x0+width; x++ {
57 				screen.SetContent(x, y, ' ', nil, st)
58 			}
59-			screen.SetContent(x0+width, y, 0x2590, nil, st)
60+			screen.SetContent(x, y, 0x2590, nil, st)
61+		}
62+
63+		if b.highlights != 0 {
64+			highlightSt := st.Foreground(tcell.ColorRed).Reverse(true)
65+			highlightText := fmt.Sprintf(" %d ", b.highlights)
66+			x = x0 + width - len(highlightText)
67+			printString(screen, &x, y, Styled(highlightText, highlightSt))
68 		}
69 	}
70 }
+14, -0
 1@@ -53,3 +53,17 @@ func printTime(screen tcell.Screen, x int, y int, st tcell.Style, t time.Time) {
 2 	screen.SetContent(x+3, y, mn0, nil, st)
 3 	screen.SetContent(x+4, y, mn1, nil, st)
 4 }
 5+
 6+func clearArea(screen tcell.Screen, x0, y0, width, height int) {
 7+	for x := x0; x < x0+width; x++ {
 8+		for y := y0; y < y0+height; y++ {
 9+			screen.SetContent(x, y, ' ', nil, tcell.StyleDefault)
10+		}
11+	}
12+}
13+
14+func drawVerticalLine(screen tcell.Screen, x, y0, height int) {
15+	for y := y0; y < y0+height; y++ {
16+		screen.SetContent(x, y, 0x2502, nil, tcell.StyleDefault)
17+	}
18+}
+11, -13
 1@@ -355,24 +355,22 @@ func drawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, memb
 2 		}
 3 	}
 4 
 5-	for y := y0; y < y0+height; y++ {
 6-		screen.SetContent(x0, y, 0x2502, nil, tcell.StyleDefault)
 7-		for x := x0 + 1; x < x0+width; x++ {
 8-			screen.SetContent(x, y, ' ', nil, tcell.StyleDefault)
 9-		}
10-	}
11+	drawVerticalLine(screen, x0, y0, height)
12+	x0++
13+	width--
14+	clearArea(screen, x0, y0, width, height)
15 
16 	for i, m := range members[*offset:] {
17-		x := x0 + 1
18+		x := x0
19 		y := y0 + i
20-
21 		if m.PowerLevel != "" {
22-			powerLevel := Styled(string([]rune(m.PowerLevel)[0]), tcell.StyleDefault.Foreground(tcell.ColorGreen))
23-			printString(screen, &x, y, powerLevel)
24+			powerLevelText := m.PowerLevel[:1]
25+			powerLevelSt := tcell.StyleDefault.Foreground(tcell.ColorGreen)
26+			printString(screen, &x, y, Styled(powerLevelText, powerLevelSt))
27 		} else {
28-			x += 1
29+			x++
30 		}
31-		name := truncate(m.Name.Name, width-(x-x0), "\u2026")
32-		printString(screen, &x, y, Styled(name, tcell.StyleDefault))
33+		name := truncate(m.Name.Name, width-1, "\u2026")
34+		printString(screen, &x, y, PlainString(name))
35 	}
36 }