mirror of
https://github.com/cheat/cheat.git
synced 2024-11-01 05:31:01 +01:00
f4e6c76e58
Fix an issue whereby ANSI escape characters could appear in search output when a pager was not configured. The root cause of the problem was code that was overzealously applying an underlying effect to search terms. This commit simply rips out underlying entirely, both as means of resolving this problem, and also simply for removing needless visual noise from search output.
37 lines
780 B
Go
37 lines
780 B
Go
package display
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/cheat/cheat/internal/config"
|
|
)
|
|
|
|
// Write writes output either directly to stdout, or through a pager,
|
|
// depending upon configuration.
|
|
func Write(out string, conf config.Config) {
|
|
// if no pager was configured, print the output to stdout and exit
|
|
if conf.Pager == "" {
|
|
fmt.Print(out)
|
|
os.Exit(0)
|
|
}
|
|
|
|
// otherwise, pipe output through the pager
|
|
parts := strings.Split(conf.Pager, " ")
|
|
pager := parts[0]
|
|
args := parts[1:]
|
|
|
|
// configure the pager
|
|
cmd := exec.Command(pager, args...)
|
|
cmd.Stdin = strings.NewReader(out)
|
|
cmd.Stdout = os.Stdout
|
|
|
|
// 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)
|
|
}
|
|
}
|