Skip to content

Commit

Permalink
sort ips correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jul 28, 2020
1 parent eeaab00 commit 47addbf
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions ui.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"bytes"
"fmt"
"net"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -320,6 +322,8 @@ func (u *ui) gatherData() {
return ret
}()

close(done)

u.infoText = fmt.Sprintf("interface: %s%s entries: %d last update: %s",
u.p.intf.Name,
func() string {
Expand Down Expand Up @@ -349,13 +353,29 @@ func (u *ui) gatherData() {
case "mdns":
n = 6
}
if u.tableRows[i].cells[n] != u.tableRows[j].cells[n] {
if u.tableSortAsc {
return u.tableRows[i].cells[n] < u.tableRows[j].cells[n]
} else {
return u.tableRows[i].cells[n] > u.tableRows[j].cells[n]

if u.tableSortBy == "ip" {
if u.tableRows[i].cells[n] != u.tableRows[j].cells[n] {
ipa := net.ParseIP(u.tableRows[i].cells[n])
ipb := net.ParseIP(u.tableRows[j].cells[n])

if u.tableSortAsc {
return bytes.Compare(ipa, ipb) < 0
} else {
return bytes.Compare(ipa, ipb) >= 0
}
}

} else {
if u.tableRows[i].cells[n] != u.tableRows[j].cells[n] {
if u.tableSortAsc {
return u.tableRows[i].cells[n] < u.tableRows[j].cells[n]
} else {
return u.tableRows[i].cells[n] > u.tableRows[j].cells[n]
}
}
}

return u.tableRows[i].cells[2] < u.tableRows[j].cells[2]
})

Expand All @@ -370,8 +390,6 @@ func (u *ui) gatherData() {
if u.selection == "" {
u.selection = u.selectables[0]
}

close(done)
}

func (u *ui) drawRect(startX int, startY int, width int, height int) {
Expand Down

0 comments on commit 47addbf

Please sign in to comment.