commit 2abe469

delthas  ·  2023-11-09 10:24:48 +0000 UTC
parent ae42619
Close buffer on mouse middle click

Will be much clearer to users than /part.

Fixes: https://todo.sr.ht/~taiite/senpai/123
4 files changed,  +31, -1
M app.go
M app.go
+17, -0
 1@@ -511,6 +511,23 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
 2 			app.win.ClickMember(y - 2 + app.win.MemberOffset())
 3 		}
 4 	}
 5+	if ev.Buttons()&tcell.ButtonMiddle != 0 {
 6+		i := -1
 7+		if x < app.win.ChannelWidth() {
 8+			i = y + app.win.ChannelOffset()
 9+		} else if app.win.ChannelWidth() == 0 && y == h-1 {
10+			i = app.win.HorizontalBufferOffset(x)
11+		}
12+		netID, channel, ok := app.win.Buffer(i)
13+		if ok && channel != "" {
14+			s := app.sessions[netID]
15+			if s != nil && s.IsChannel(channel) {
16+				s.Part(channel, "")
17+			} else {
18+				app.win.RemoveBuffer(netID, channel)
19+			}
20+		}
21+	}
22 	if ev.Buttons() == 0 {
23 		if x < app.win.ChannelWidth() {
24 			if i := y + app.win.ChannelOffset(); i == app.win.ClickedBuffer() {
+2, -1
 1@@ -47,7 +47,8 @@ The user interface of senpai consists of 4 parts.  Starting from the bottom:
 2 
 3 The *buffer list*, shows joined channels.  The special buffer *home* is where
 4 server notices are shown.  This list can be put on the left of the screen with
 5-the _chan-column-width_ configuration option.
 6+the _chan-column-width_ configuration option. Buffers can be closed with the
 7+mouse middle click, or the _part_ command.
 8 
 9 On the row above, the *input field* is where you type in messages or commands
10 (see *COMMANDS*).  By default, when you type a message, senpai will inform
+8, -0
 1@@ -573,6 +573,14 @@ func (bs *BufferList) UpdateRead() (netID, title string, timestamp time.Time) {
 2 	return "", "", time.Time{}
 3 }
 4 
 5+func (bs *BufferList) Buffer(i int) (netID, title string, ok bool) {
 6+	if i < 0 || i >= len(bs.list) {
 7+		return
 8+	}
 9+	b := &bs.list[i]
10+	return b.netID, b.title, true
11+}
12+
13 func (bs *BufferList) Current() (netID, title string) {
14 	b := &bs.list[bs.current]
15 	return b.netID, b.title
+4, -0
 1@@ -119,6 +119,10 @@ func (ui *UI) Close() {
 2 	ui.screen.Fini()
 3 }
 4 
 5+func (ui *UI) Buffer(i int) (netID, title string, ok bool) {
 6+	return ui.bs.Buffer(i)
 7+}
 8+
 9 func (ui *UI) CurrentBuffer() (netID, title string) {
10 	return ui.bs.Current()
11 }