commit 526eb96

Hubert Hirtz  ·  2021-09-01 11:01:54 +0000 UTC
parent 058532e
Channel list is horizontal by default
4 files changed,  +65, -10
+2, -2
 1@@ -91,8 +91,8 @@ func ParseConfig(buf []byte) (cfg Config, err error) {
 2 	if cfg.NickColWidth <= 0 {
 3 		cfg.NickColWidth = 16
 4 	}
 5-	if cfg.ChanColWidth <= 0 {
 6-		cfg.ChanColWidth = 16
 7+	if cfg.ChanColWidth < 0 {
 8+		cfg.ChanColWidth = 0
 9 	}
10 	if cfg.MemberColWidth <= 0 {
11 		cfg.MemberColWidth = 16
+2, -1
 1@@ -76,7 +76,8 @@ on-highlight: |
 2 	By default, 16.
 3 
 4 *chan-column-width*
 5-	The number of cells that the column for channels occupies.  By default, 16.
 6+	Make the channel list vertical, with a width equals to the given amount of
 7+	cells.  By default, the channel list is horizontal.
 8 
 9 *member-column-width*
10 	The number of cells that the column for members occupies.  By default, 16.
+31, -0
 1@@ -413,6 +413,37 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
 2 	}
 3 }
 4 
 5+func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int) {
 6+	x := x0
 7+
 8+	for i, b := range bs.list {
 9+		if width <= x-x0 {
10+			break
11+		}
12+		st := tcell.StyleDefault
13+		if b.unread {
14+			st = st.Bold(true)
15+		} else if i == bs.current {
16+			st = st.Underline(true)
17+		}
18+		if i == bs.clicked {
19+			st = st.Reverse(true)
20+		}
21+		title := truncate(b.title, width-x, "\u2026")
22+		printString(screen, &x, y0, Styled(title, st))
23+		if 0 < b.highlights {
24+			st = st.Foreground(tcell.ColorRed).Reverse(true)
25+			screen.SetContent(x, y0, ' ', nil, st)
26+			x++
27+			printNumber(screen, &x, y0, st, b.highlights)
28+			screen.SetContent(x, y0, ' ', nil, st)
29+			x++
30+		}
31+		screen.SetContent(x, y0, ' ', nil, tcell.StyleDefault)
32+		x++
33+	}
34+}
35+
36 func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, members []irc.Member, offset *int) {
37 	st := tcell.StyleDefault
38 
+30, -7
 1@@ -273,7 +273,11 @@ func (ui *UI) Resize() {
 2 	w, h := ui.screen.Size()
 3 	innerWidth := w - 9 - ui.config.ChanColWidth - ui.config.NickColWidth - ui.config.MemberColWidth
 4 	ui.e.Resize(innerWidth)
 5-	ui.bs.ResizeTimeline(innerWidth, h-2)
 6+	if ui.config.ChanColWidth == 0 {
 7+		ui.bs.ResizeTimeline(innerWidth, h-3)
 8+	} else {
 9+		ui.bs.ResizeTimeline(innerWidth, h-2)
10+	}
11 }
12 
13 func (ui *UI) Size() (int, int) {
14@@ -283,17 +287,36 @@ func (ui *UI) Size() (int, int) {
15 func (ui *UI) Draw(members []irc.Member) {
16 	w, h := ui.screen.Size()
17 
18-	ui.e.Draw(ui.screen, 9+ui.config.ChanColWidth+ui.config.NickColWidth, h-1)
19+	if ui.config.ChanColWidth == 0 {
20+		ui.e.Draw(ui.screen, 9+ui.config.NickColWidth, h-2)
21+	} else {
22+		ui.e.Draw(ui.screen, 9+ui.config.ChanColWidth+ui.config.NickColWidth, h-1)
23+	}
24 
25 	ui.bs.DrawTimeline(ui.screen, ui.config.ChanColWidth, 0, ui.config.NickColWidth)
26-	ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h)
27+	if ui.config.ChanColWidth == 0 {
28+		ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.config.MemberColWidth)
29+	} else {
30+		ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h)
31+	}
32 	ui.bs.DrawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members, &ui.memberOffset)
33-	ui.drawStatusBar(ui.config.ChanColWidth, h-2, w-ui.config.ChanColWidth-ui.config.MemberColWidth)
34+	if ui.config.ChanColWidth == 0 {
35+		ui.drawStatusBar(ui.config.ChanColWidth, h-3, w-ui.config.MemberColWidth)
36+	} else {
37+		ui.drawStatusBar(ui.config.ChanColWidth, h-2, w-ui.config.ChanColWidth-ui.config.MemberColWidth)
38+	}
39 
40-	for x := ui.config.ChanColWidth; x < 9+ui.config.ChanColWidth+ui.config.NickColWidth; x++ {
41-		ui.screen.SetContent(x, h-1, ' ', nil, tcell.StyleDefault)
42+	if ui.config.ChanColWidth == 0 {
43+		for x := 0; x < 9+ui.config.NickColWidth; x++ {
44+			ui.screen.SetContent(x, h-2, ' ', nil, tcell.StyleDefault)
45+		}
46+		printIdent(ui.screen, 7, h-2, ui.config.NickColWidth, ui.prompt)
47+	} else {
48+		for x := ui.config.ChanColWidth; x < 9+ui.config.ChanColWidth+ui.config.NickColWidth; x++ {
49+			ui.screen.SetContent(x, h-1, ' ', nil, tcell.StyleDefault)
50+		}
51+		printIdent(ui.screen, ui.config.ChanColWidth+7, h-1, ui.config.NickColWidth, ui.prompt)
52 	}
53-	printIdent(ui.screen, ui.config.ChanColWidth+7, h-1, ui.config.NickColWidth, ui.prompt)
54 
55 	ui.screen.Show()
56 }