Adds ability to sort by author

This commit is contained in:
sloum 2024-03-21 22:25:37 -07:00
parent c610502f47
commit b069d0b232
2 changed files with 15 additions and 2 deletions

View File

@ -9,6 +9,8 @@ import (
"strings"
)
var authorSort bool
func editConfig(p string) error {
editor := os.Getenv("EDITOR")
var err error
@ -38,6 +40,9 @@ func main() {
filterTitle := flag.String("title", "", "Filter by title")
filterFormat := flag.String("format", "", "Filter by format; ex. \"epub\"")
installResults := flag.Bool("install", false, "Installs the results of the query")
// TODO figure out sorting by author, likely have the strings start with the author name
flag.BoolVar(&authorSort, "a", false, "Sort by author instead of title")
configure := flag.Bool("configure", false, "Open the configuration file in your $EDITOR")
flag.Parse()
var err error

View File

@ -100,11 +100,19 @@ func (d doc) FilesString() string {
}
func (d doc) String(s string) string {
return fmt.Sprintf("\033[3m%-35s\033[0m \033[2mby\033[0m %-20s \033[2m(\033[0m%s\033[2m) %s\033[0m", d.Title, d.Author, d.FileTypes(), s)
if authorSort {
return fmt.Sprintf("\033[3m%-20s\033[0m \033[2m-\033[0m %-35s \033[2m(%s) %s\033[0m", d.Author, d.Title, d.FileTypes(), s)
} else {
return fmt.Sprintf("\033[3m%-35s\033[0m \033[2mby\033[0m %-20s \033[2m(%s) %s\033[0m", d.Title, d.Author, d.FileTypes(), s)
}
}
func (d doc) StringLong(s string) string {
return fmt.Sprintf("\033[7;1m%s\033[0m \033[2mby\033[0m %s\nSource: %s\nSubjects: %s\nFiles:\n%sDescription:\n %s\n\n", d.Title, d.Author, s, strings.Join(d.Subjects, ", "), d.FilesString(), strings.TrimSpace(strings.ReplaceAll(d.Description, "\\n", "\n")))
if authorSort {
return fmt.Sprintf("%s \033[2m-\033[0m \033[7;1m%s\033[0m\nSource: %s\nSubjects: %s\nFiles:\n%sDescription:\n %s\n\n", d.Author, d.Title, s, strings.Join(d.Subjects, ", "), d.FilesString(), strings.TrimSpace(strings.ReplaceAll(d.Description, "\\n", "\n")))
} else {
return fmt.Sprintf("\033[7;1m%s\033[0m \033[2mby\033[0m %s\nSource: %s\nSubjects: %s\nFiles:\n%sDescription:\n %s\n\n", d.Title, d.Author, s, strings.Join(d.Subjects, ", "), d.FilesString(), strings.TrimSpace(strings.ReplaceAll(d.Description, "\\n", "\n")))
}
}
type sourceData struct {