simplify options display

This commit is contained in:
Celogeek 2023-04-30 14:01:12 +02:00
parent 5ec963a11e
commit 5b0051720f
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc

View File

@ -82,27 +82,27 @@ func New() *Options {
} }
func (o *Options) Header() string { func (o *Options) Header() string {
return `Go Comic Converter return "Go Comic Converter\n\nOptions:"
Options:`
} }
func (o *Options) String() string { func (o *Options) String() string {
return fmt.Sprintf(`%s var b strings.Builder
Input : %s b.WriteString(o.Header())
Output : %s for _, v := range []struct {
Author : %s K string
Title : %s V any
Workers : %d%s }{
`, {"Input", o.Input},
o.Header(), {"Output", o.Output},
o.Input, {"Author", o.Author},
o.Output, {"Title", o.Title},
o.Author, {"Workers", o.Workers},
o.Title, } {
o.Workers, b.WriteString(fmt.Sprintf("\n %-26s: %v", v.K, v.V))
o.ShowConfig(), }
) b.WriteString(o.ShowConfig())
b.WriteRune('\n')
return b.String()
} }
// Config file: ~/.go-comic-converter.yaml // Config file: ~/.go-comic-converter.yaml
@ -161,40 +161,31 @@ func (o *Options) ShowConfig() string {
sortpathmode = "path=alphanum, file=alphanum" sortpathmode = "path=alphanum, file=alphanum"
} }
return fmt.Sprintf(` var b strings.Builder
Profile : %s for _, v := range []struct {
ViewRatio : 1:%s K string
View : %s V any
Quality : %d }{
Crop : %v {"Profile", profileDesc},
CropRatio : %d Left - %d Up - %d Right - %d Bottom {"ViewRatio", fmt.Sprintf("1:%s", strings.TrimRight(fmt.Sprintf("%f", profiles.PerfectRatio), "0"))},
Brightness : %d {"View", viewDesc},
Contrast : %d {"Quality", o.Quality},
AutoRotate : %v {"Crop", o.Crop},
AutoSplitDoublePage : %v {"CropRatio", fmt.Sprintf("%d Left - %d Up - %d Right - %d Bottom", o.CropRatioLeft, o.CropRatioUp, o.CropRatioRight, o.CropRatioBottom)},
NoBlankImage : %v {"Brightness", o.Brightness},
Manga : %v {"Contrast", o.Contrast},
HasCover : %v {"AutoRotate", o.AutoRotate},
LimitMb : %s {"AutoSplitDoublePage", o.AutoSplitDoublePage},
StripFirstDirectoryFromToc: %v {"NoBlankImage", o.NoBlankImage},
SortPathMode : %s`, {"Manga", o.Manga},
profileDesc, {"HasCover", o.HasCover},
strings.TrimRight(fmt.Sprintf("%f", profiles.PerfectRatio), "0"), {"LimitMb", limitmb},
viewDesc, {"StripFirstDirectoryFromToc", o.StripFirstDirectoryFromToc},
o.Quality, {"SortPathMode", sortpathmode},
o.Crop, } {
o.CropRatioLeft, o.CropRatioUp, o.CropRatioRight, o.CropRatioBottom, b.WriteString(fmt.Sprintf("\n %-26s: %v", v.K, v.V))
o.Brightness, }
o.Contrast, return b.String()
o.AutoRotate,
o.AutoSplitDoublePage,
o.NoBlankImage,
o.Manga,
o.HasCover,
limitmb,
o.StripFirstDirectoryFromToc,
sortpathmode,
)
} }
// reset all settings to default value // reset all settings to default value