mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
sidepanel: sort user nicks alphabetically and ascendingly
This commit is contained in:
@@ -19,7 +19,10 @@ package mainscreen
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
@@ -40,11 +43,38 @@ func (s *SidePanelState) getHeader() string {
|
|||||||
usersCount = len(s.Client.Channels[s.Client.ActiveChannelIndex].Users)
|
usersCount = len(s.Client.Channels[s.Client.ActiveChannelIndex].Users)
|
||||||
}
|
}
|
||||||
separator := strings.Repeat("—", s.Viewport.Width-s.Viewport.Style.GetHorizontalFrameSize()) + "\n"
|
separator := strings.Repeat("—", s.Viewport.Width-s.Viewport.Style.GetHorizontalFrameSize()) + "\n"
|
||||||
header := fmt.Sprintf("Users in this channel (%d)\n", usersCount) + separator
|
header := fmt.Sprintf("%d Users\n", usersCount) + separator
|
||||||
|
|
||||||
return header
|
return header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lessCaseInsensitive compares s, t without allocating
|
||||||
|
func lessCaseInsensitive(s, t string) bool {
|
||||||
|
for {
|
||||||
|
if len(t) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if len(s) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
c, sizec := utf8.DecodeRuneInString(s)
|
||||||
|
d, sized := utf8.DecodeRuneInString(t)
|
||||||
|
|
||||||
|
lowerc := unicode.ToLower(c)
|
||||||
|
lowerd := unicode.ToLower(d)
|
||||||
|
|
||||||
|
if lowerc < lowerd {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if lowerc > lowerd {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
s = s[sizec:]
|
||||||
|
t = t[sized:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SidePanelState) getLatestNicks() []string {
|
func (s *SidePanelState) getLatestNicks() []string {
|
||||||
nicks := make([]string, 0)
|
nicks := make([]string, 0)
|
||||||
|
|
||||||
@@ -55,6 +85,7 @@ func (s *SidePanelState) getLatestNicks() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(nicks, func(i, j int) bool { return lessCaseInsensitive(nicks[i], nicks[j]) })
|
||||||
return nicks
|
return nicks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user