commit dffaae8

Hubert Hirtz  ·  2020-11-07 14:13:09 +0000 UTC
parent c5e30f9
Support for mouse clicks on channel names
3 files changed,  +44, -1
M app.go
M app.go
+10, -1
 1@@ -229,7 +229,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
 2 }
 3 
 4 func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
 5-	x, _ := ev.Position()
 6+	x, y := ev.Position()
 7 	if ev.Buttons()&tcell.WheelUp != 0 {
 8 		if x < app.cfg.ChanColWidth {
 9 			// TODO scroll chan list
10@@ -255,6 +255,15 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
11 			app.win.ScrollDownBy(4)
12 		}
13 	}
14+	if ev.Buttons()&tcell.ButtonPrimary != 0 && x < app.cfg.ChanColWidth {
15+		app.win.ClickBuffer(y)
16+	}
17+	if ev.Buttons() == 0 {
18+		if y == app.win.ClickedBuffer() && x < app.cfg.ChanColWidth {
19+			app.win.GoToBufferNo(y)
20+		}
21+		app.win.ClickBuffer(-1)
22+	}
23 }
24 
25 func (app *App) handleKeyEvent(ev *tcell.EventKey) {
+20, -0
 1@@ -170,6 +170,7 @@ type buffer struct {
 2 type BufferList struct {
 3 	list    []buffer
 4 	current int
 5+	clicked int
 6 
 7 	tlWidth      int
 8 	tlHeight     int
 9@@ -179,6 +180,7 @@ type BufferList struct {
10 func NewBufferList(tlWidth, tlHeight, nickColWidth int) BufferList {
11 	return BufferList{
12 		list:         []buffer{},
13+		clicked:      -1,
14 		tlWidth:      tlWidth,
15 		tlHeight:     tlHeight,
16 		nickColWidth: nickColWidth,
17@@ -194,6 +196,14 @@ func (bs *BufferList) tlInnerWidth() int {
18 	return bs.tlWidth - bs.nickColWidth - 9
19 }
20 
21+func (bs *BufferList) To(i int) {
22+	if 0 <= i && i < len(bs.list) {
23+		bs.current = i
24+		bs.list[bs.current].highlights = 0
25+		bs.list[bs.current].unread = false
26+	}
27+}
28+
29 func (bs *BufferList) Next() {
30 	bs.current = (bs.current + 1) % len(bs.list)
31 	bs.list[bs.current].highlights = 0
32@@ -359,6 +369,9 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
33 		} else if y == bs.current {
34 			st = st.Underline(true)
35 		}
36+		if i == bs.clicked {
37+			st = st.Reverse(true).Dim(true)
38+		}
39 		title := truncate(b.title, width, "\u2026")
40 		printString(screen, &x, y, st, title)
41 		if 0 < b.highlights {
42@@ -369,6 +382,13 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
43 			screen.SetContent(x, y, ' ', nil, st)
44 			x++
45 		}
46+		if i == bs.clicked {
47+			st = st.Bold(false).Underline(false)
48+			for ; x < x0+width; x++ {
49+				screen.SetContent(x, y, ' ', nil, st)
50+			}
51+			screen.SetContent(x0+width, y, 0x2590, nil, st)
52+		}
53 		y++
54 	}
55 }
+14, -0
 1@@ -90,6 +90,20 @@ func (ui *UI) PreviousBuffer() {
 2 	ui.bs.Previous()
 3 }
 4 
 5+func (ui *UI) ClickedBuffer() int {
 6+	return ui.bs.clicked
 7+}
 8+
 9+func (ui *UI) ClickBuffer(i int) {
10+	if i < len(ui.bs.list) {
11+		ui.bs.clicked = i
12+	}
13+}
14+
15+func (ui *UI) GoToBufferNo(i int) {
16+	ui.bs.To(i)
17+}
18+
19 func (ui *UI) ScrollUp() {
20 	ui.bs.ScrollUp(ui.bs.tlHeight / 2)
21 }