fix(view): whitespace corrections

- Fix bug whereby `--all` flag would conflict with pager

- Fix whitespace inconsistencies among view and search outputs
This commit is contained in:
Chris Lane
2020-11-28 11:18:16 -05:00
parent ecc96c64f9
commit 4f2a57fce8
4 changed files with 16 additions and 9 deletions

View File

@ -75,7 +75,7 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) {
}
// display the cheatsheet title and path
out += fmt.Sprintf("\n%s %s\n",
out += fmt.Sprintf("%s %s\n",
display.Underline(sheet.Title),
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf),
)
@ -85,8 +85,8 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) {
}
}
// trim the leading newline
out = strings.TrimPrefix(out, "\n")
// trim superfluous newlines
out = strings.TrimSpace(out)
// display the output
// NB: resist the temptation to call `display.Display` multiple times in

View File

@ -33,16 +33,17 @@ func cmdView(opts map[string]interface{}, conf config.Config) {
// if --all was passed, display cheatsheets from all cheatpaths
if opts["--all"].(bool) {
// iterate over the cheatpaths
out := ""
for _, cheatpath := range cheatsheets {
// if the cheatpath contains the specified cheatsheet, display it
if sheet, ok := cheatpath[cheatsheet]; ok {
// identify the matching cheatsheet
fmt.Println(fmt.Sprintf("%s %s",
out += fmt.Sprintf("%s %s\n",
display.Underline(sheet.Title),
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf),
))
)
// apply colorization if requested
if conf.Color(opts) {
@ -50,11 +51,12 @@ func cmdView(opts map[string]interface{}, conf config.Config) {
}
// display the cheatsheet
display.Write(display.Indent(sheet.Text), conf)
out += display.Indent(sheet.Text) + "\n"
}
}
// exit early
// display and exit
display.Write(strings.TrimSuffix(out, "\n"), conf)
os.Exit(0)
}