aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/colour.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/krino/colour.go')
-rw-r--r--cmd/krino/colour.go53
1 files changed, 18 insertions, 35 deletions
diff --git a/cmd/krino/colour.go b/cmd/krino/colour.go
index ee9055c..1b58171 100644
--- a/cmd/krino/colour.go
+++ b/cmd/krino/colour.go
@@ -6,9 +6,7 @@ import (
"fmt"
"io"
"strings"
- "unicode/utf8"
- "krino/internal/plan"
"krino/internal/tui"
)
@@ -52,39 +50,6 @@ func (p palette) keys(menu string) string {
return b.String()
}
-// padStyled styles s and pads it to w runes measured on s itself, so the
-// escape bytes never count toward the column's width.
-func padStyled(s string, w int, style func(string) string) string {
- pad := w - utf8.RuneCountInString(s)
- if pad < 0 {
- pad = 0
- }
- return style(s) + strings.Repeat(" ", pad)
-}
-
-// styleAction styles an action cell actionCell rendered for s: a skipped
-// step faint throughout; otherwise only its leading kind word, green for
-// copy, move and rename, yellow for trash, bold red for DELETE permanently.
-func styleAction(p palette, s plan.Step, cell string) string {
- if s.Skip != "" {
- return p.faint(cell)
- }
- word := s.Kind.String()
- if !strings.HasPrefix(cell, word) {
- return cell
- }
- var styled string
- switch s.Kind {
- case plan.Trash:
- styled = p.warn(word)
- case plan.DeletePermanent:
- styled = p.alarm(word)
- default:
- styled = p.good(word)
- }
- return styled + cell[len(word):]
-}
-
// outcome renders the "N applied · N failed · N declined" line: the applied
// count green and the failed count red, each only when above 0.
func outcome(p palette, applied, failed, declined int) string {
@@ -102,6 +67,24 @@ func outcome(p palette, applied, failed, declined int) string {
// it, since no test runs on a terminal.
var colourPolicy = tui.Colour
+// widthPolicy is tui.Width, the terminal's columns (0: never wrap); pager
+// is tui.Page. Tests replace both, for the same reason.
+var (
+ widthPolicy = tui.Width
+ pager = tui.Page
+)
+
+// show writes text to w: straight out with -P (--no-pager), otherwise
+// through the pager, which only engages when text is taller than the
+// terminal.
+func show(g *globals, w io.Writer, text string) error {
+ if g.noPager {
+ _, err := io.WriteString(w, text)
+ return err
+ }
+ return pager(w, text)
+}
+
// colourOn reports whether output to w is coloured: never with --no-color,
// otherwise as colourPolicy decides.
func colourOn(g *globals, w io.Writer) bool {