mirror of
https://github.com/cheat/cheat.git
synced 2025-09-02 01:58:29 +02:00
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:
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user