sort images in a 'natural sort' way
This commit is contained in:
1
go.mod
1
go.mod
@@ -18,6 +18,7 @@ require (
|
||||
github.com/evilsocket/islazy v1.11.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/maruel/natural v1.1.1 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||
|
2
go.sum
2
go.sum
@@ -22,6 +22,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
|
||||
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
|
||||
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
|
||||
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
|
18
main.go
18
main.go
@@ -7,12 +7,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.yetaga.in/alazyreader/why/filetypes"
|
||||
"github.com/dblezek/tga"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/maruel/natural"
|
||||
"golang.org/x/image/webp"
|
||||
tk "modernc.org/tk9.0"
|
||||
)
|
||||
@@ -92,14 +94,20 @@ func newBrowse(file string) {
|
||||
return
|
||||
}
|
||||
directoryState.images = []string{}
|
||||
i := 0
|
||||
for _, v := range dirfiles {
|
||||
if filetypes.IsImage(v) {
|
||||
directoryState.images = append(directoryState.images, v.Name())
|
||||
if filepath.Join(directoryState.dir, v.Name()) == file {
|
||||
directoryState.i = i
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
slices.SortFunc(directoryState.images, func(a, b string) int {
|
||||
if natural.Less(a, b) {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
})
|
||||
for i, v := range directoryState.images {
|
||||
if v == file {
|
||||
directoryState.i = i
|
||||
}
|
||||
}
|
||||
updateImage(file)
|
||||
|
Reference in New Issue
Block a user