diff --git a/cmd/cheat/cmd_search.go b/cmd/cheat/cmd_search.go index f9da0c2..88a35e4 100644 --- a/cmd/cheat/cmd_search.go +++ b/cmd/cheat/cmd_search.go @@ -59,9 +59,9 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) { os.Exit(1) } - // `Search` will return text entries that match the search terms. We're - // using it here to overwrite the prior cheatsheet Text, filtering it to - // only what is relevant + // `Search` will return text entries that match the search terms. + // We're using it here to overwrite the prior cheatsheet Text, + // filtering it to only what is relevant. sheet.Text = sheet.Search(reg) // if the sheet did not match the search, ignore it and move on @@ -74,14 +74,16 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) { sheet.Colorize(conf) } - // display the cheatsheet title and path - out += fmt.Sprintf("%s %s\n", - display.Underline(sheet.Title), + // display the cheatsheet body + out += fmt.Sprintf( + "%s %s\n%s\n", + // append the cheatsheet title + sheet.Title, + // append the cheatsheet path display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf), + // indent each line of content + display.Indent(sheet.Text), ) - - // indent each line of content - out += display.Indent(sheet.Text) + "\n" } } @@ -89,7 +91,7 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) { out = strings.TrimSpace(out) // display the output - // NB: resist the temptation to call `display.Display` multiple times in - // the loop above. That will not play nicely with the paginator. + // NB: resist the temptation to call `display.Write` multiple times in the + // loop above. That will not play nicely with the paginator. display.Write(out, conf) } diff --git a/cmd/cheat/cmd_view.go b/cmd/cheat/cmd_view.go index b745674..41a47a6 100644 --- a/cmd/cheat/cmd_view.go +++ b/cmd/cheat/cmd_view.go @@ -41,7 +41,7 @@ func cmdView(opts map[string]interface{}, conf config.Config) { // identify the matching cheatsheet out += fmt.Sprintf("%s %s\n", - display.Underline(sheet.Title), + sheet.Title, display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf), ) diff --git a/internal/display/underline.go b/internal/display/underline.go deleted file mode 100644 index e9e5907..0000000 --- a/internal/display/underline.go +++ /dev/null @@ -1,8 +0,0 @@ -package display - -import "fmt" - -// Underline returns an underlined string -func Underline(str string) string { - return fmt.Sprintf("\033[4m%s\033[0m", str) -} diff --git a/internal/display/underline_test.go b/internal/display/underline_test.go deleted file mode 100644 index e9743ee..0000000 --- a/internal/display/underline_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package display - -import ( - "testing" -) - -// TestUnderline asserts that Underline applies underline formatting -func TestUnderline(t *testing.T) { - want := "\033[4mfoo\033[0m" - got := Underline("foo") - if want != got { - t.Errorf("failed to underline: want: %s, got: %s", want, got) - } -} diff --git a/internal/display/write.go b/internal/display/write.go index 3736262..d4dcfc5 100644 --- a/internal/display/write.go +++ b/internal/display/write.go @@ -23,14 +23,13 @@ func Write(out string, conf config.Config) { pager := parts[0] args := parts[1:] - // run the pager + // configure the pager cmd := exec.Command(pager, args...) cmd.Stdin = strings.NewReader(out) cmd.Stdout = os.Stdout - // handle errors - err := cmd.Run() - if err != nil { + // run the pager and handle errors + if err := cmd.Run(); err != nil { fmt.Fprintf(os.Stderr, "failed to write to pager: %v\n", err) os.Exit(1) }