erm/app/darktile/cmd/fonts.go

45 lines
882 B
Go

package cmd
import (
"fmt"
"os"
"sort"
"text/tabwriter"
"tuxpa.in/t/erm/app/fontinfo"
)
type ListFonts struct {
Styles []string `name:"styles" default:"regular"`
}
func (r *ListFonts) Run(ctx *Context) error {
matchers := []fontinfo.Matcher{}
for _, v := range r.Styles {
matchers = append(matchers, fontinfo.MatchStyle(v))
}
fonts, err := fontinfo.Match(matchers...)
if err != nil {
return err
}
sort.SliceStable(fonts, func(i, j int) bool {
if fonts[i].Style == fonts[j].Style {
return fonts[i].Family < fonts[j].Family
}
return fonts[i].Style < fonts[j].Style
})
w := tabwriter.NewWriter(os.Stdout, 0, 0, 0, ' ',
tabwriter.Debug)
fmt.Fprintln(w, "family\tstyle\tpath")
fmt.Fprintln(w, "---\t---\t---")
for _, font := range fonts {
fmt.Fprintf(w, "%s\t%s\t%s\n",
font.Style,
font.Family,
font.Path,
)
w.Flush()
}
return nil
}