sortMethod simplification. (#1535)

* made sortMethod a string enum to reduce comparisons and repetition

* main uses sortmethod directly instead of converting it into a string

* updated sortmethod validity check to no longer require slices package

* Update opts.go

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>

---------

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>
This commit is contained in:
Michael GalloandJoe Lim authored and GitHub committed 2023-12-26 15:55:42 +01:00
1 parent f13325f78d
commit e1ab72516d
3 files changed
+31 -65

No files matched your search

+3 -23
View File
@@ -13,9 +13,9 @@ import (
"runtime/pprof"
"strconv"
"strings"
)
import _ "embed"
_ "embed"
)
//go:embed doc.txt
var genDocString string
@@ -137,28 +137,8 @@ func getOptsMap() map[string]string {
continue
}
// Get string representation of the value
if name == "lf_sortType" {
var sortby string
switch gOpts.sortType.method {
case naturalSort:
sortby = "natural"
case nameSort:
sortby = "name"
case sizeSort:
sortby = "size"
case timeSort:
sortby = "time"
case ctimeSort:
sortby = "ctime"
case atimeSort:
sortby = "atime"
case extSort:
sortby = "ext"
}
opts["lf_sortby"] = sortby
opts["lf_sortby"] = string(gOpts.sortType.method)
opts["lf_reverse"] = strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
opts["lf_hidden"] = strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
opts["lf_dirfirst"] = strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)