pagerCommand returns the pager command and arguments to use for viewing colored diff output.
()
| 610 | |
| 611 | // pagerCommand returns the pager command and arguments to use for viewing colored diff output. |
| 612 | func pagerCommand() []string { |
| 613 | pager := strings.TrimSpace(os.Getenv("PAGER")) |
| 614 | if pager == "" { |
| 615 | return []string{"less", "-R"} |
| 616 | } |
| 617 | args := strings.Fields(pager) |
| 618 | if filepath.Base(args[0]) != "less" { |
| 619 | return args |
| 620 | } |
| 621 | if lessHasRawColorFlag(args[1:]) { |
| 622 | return args |
| 623 | } |
| 624 | if lessHasRawColorFlag(strings.Fields(os.Getenv("LESS"))) { |
| 625 | return args |
| 626 | } |
| 627 | return append(args, "-R") |
| 628 | } |
| 629 | |
| 630 | func lessHasRawColorFlag(flags []string) bool { |
| 631 | for _, f := range flags { |
no test coverage detected