~taiite/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH senpai] Alphabetically sort buffer list

Details
Message ID
<20210319215607.8556-1-galen@galenabell.com>
DKIM signature
pass
Download raw message
Patch: +36 -6
---
 ui/buffers.go | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/ui/buffers.go b/ui/buffers.go
index 40aa83f..e8d6291 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -220,18 +220,48 @@ func (bs *BufferList) Previous() {
}

func (bs *BufferList) Add(title string) (ok bool) {
	lTitle := strings.ToLower(title)
	for _, b := range bs.list {
		if strings.ToLower(b.title) == lTitle {
			return
		}
	idx := bs.insertIdx(title)
	if idx == -1 {
		return
	}

	ok = true
	bs.list = append(bs.list, buffer{title: title})
	buf := buffer{title: title}

	if len(bs.list) == idx {
		bs.list = append(bs.list, buf)
	} else {
		bs.list = append(bs.list[:idx+1], bs.list[idx:]...)
		bs.list[idx] = buf
	}

	return
}

func (bs *BufferList) insertIdx(title string) int {
	lTitle := strings.ToLower(title)
	if lTitle == "home" {
		// always put the home buffer at the top
		return 0
	}

	// don't include home in calculation
	for i := 1; i < len(bs.list); i++ {
		b := bs.list[i]
		switch strings.Compare(strings.ToLower(b.title), lTitle) {
		case -1:
			continue
		case 0:
			// title already exists
			return -1
		case 1:
			return i
		}
	}

	return len(bs.list)
}

func (bs *BufferList) Remove(title string) (ok bool) {
	lTitle := strings.ToLower(title)
	for i, b := range bs.list {
--
2.31.0
Details
Message ID
<20210329151751.1e0696c0@vroom.localdomain>
In-Reply-To
<20210319215607.8556-1-galen@galenabell.com> (view parent)
DKIM signature
pass
Download raw message
Thank you for the patch!

May I ask why you want to sort the channels?

I am using senpai with soju [0], which sends JOIN grouped by upstream
network, for example:

    #soju/fn
    #senpai/fn
    #sr.ht/fn
    #arch-fr/rz
    #somechannel/rz

("fn" and "rz" being two IRC networks), sorting channels alphabetically
would break this.

I'm planning for a complete rewrite of the UI code anyway, for
something less brittle.  It'll be easily configurable.

However if other people are OK with channels being sorted
alphabetically, I'll gladly merge this.

[0] https://git.sr.ht/~emersion/soju
Details
Message ID
<CAAZ41CXH552.30TKY55IIX1JR@asgard>
In-Reply-To
<20210329151751.1e0696c0@vroom.localdomain> (view parent)
DKIM signature
pass
Download raw message
Hey, thanks for taking a look!

For me it's less confusing for channels to be sorted, but I admit this
is more a personal preference sort of thing :)

Good point about multiple networks, I didn't consider that when I wrote
the patch. It would definitely require some additional logic to handle.

I think ultimately it would be nice to have some additional
configuration (maybe like the autosort plugin in weechat). If there are
already plans to refactor the UI then I think it would be better to not
merge this patch for now, and others who are interested in it can apply
it manually; otherwise let me know and I can send some follow up
patches to try and handle multiple networks and also add a configuration
toggle in case people don't want channels to be sorted.
Reply to thread Export thread (mbox)