gt/internal/interactive/sorting/sorting.go

102 lines
1.7 KiB
Go
Raw Normal View History

// Package sorting implements Sorting type for interactive table.
package sorting
import "git.burning.moe/celediel/gt/internal/files"
type Sorting int
const (
Name Sorting = iota + 1
NameReverse
Date
DateReverse
Path
PathReverse
Size
SizeReverse
2024-07-15 19:10:04 -04:00
Extension
ExtensionReverse
2024-07-15 18:08:02 -04:00
Directory
DirectoryReverse
)
func (s Sorting) Next() Sorting {
switch s {
2024-07-15 18:08:02 -04:00
case DirectoryReverse:
return Name
default:
return s + 1
}
}
func (s Sorting) Prev() Sorting {
switch s {
case Name:
2024-07-15 18:08:02 -04:00
return DirectoryReverse
default:
return s - 1
}
}
func (s Sorting) String() string {
switch s {
case Name:
2024-07-17 13:47:16 -04:00
return "name ↑"
case NameReverse:
2024-07-17 13:47:16 -04:00
return "name ↓"
case Date:
2024-07-17 13:47:16 -04:00
return "date ↑"
case DateReverse:
2024-07-17 13:47:16 -04:00
return "date ↓"
case Path:
2024-07-17 13:47:16 -04:00
return "path ↑"
case PathReverse:
2024-07-17 13:47:16 -04:00
return "path ↓"
case Size:
2024-07-17 13:47:16 -04:00
return "size ↑"
case SizeReverse:
2024-07-17 13:47:16 -04:00
return "size ↓"
2024-07-15 19:10:04 -04:00
case Extension:
2024-07-17 13:47:16 -04:00
return "extension ↑"
2024-07-15 19:10:04 -04:00
case ExtensionReverse:
2024-07-17 13:47:16 -04:00
return "extension ↓"
2024-07-15 18:08:02 -04:00
case Directory:
2024-07-17 13:47:16 -04:00
return "directories ↑"
2024-07-15 18:08:02 -04:00
case DirectoryReverse:
2024-07-17 13:47:16 -04:00
return "directories ↓"
default:
return "0"
}
}
func (s Sorting) Sorter() func(a, b files.File) int {
switch s {
case Name:
return files.SortByName
case NameReverse:
return files.SortByNameReverse
case Date:
return files.SortByModified
case DateReverse:
return files.SortByModifiedReverse
case Path:
return files.SortByPath
case PathReverse:
return files.SortByPathReverse
case Size:
return files.SortBySize
case SizeReverse:
return files.SortBySizeReverse
2024-07-15 19:10:04 -04:00
case Extension:
return files.SortByExtension
case ExtensionReverse:
return files.SortByExtensionReverse
2024-07-15 18:08:02 -04:00
case Directory:
return files.SortDirectoriesFirst
case DirectoryReverse:
return files.SortDirectoriesLast
default:
return files.SortByName
}
}