diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 13:26:51 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 13:26:51 +0200 |
| commit | 07c24054cab965800983ef40f53a05c2db131ede (patch) | |
| tree | 741db561d614b35f8f94fee04fb5ce663a629a0b /cmd/krino/colour.go | |
| parent | 70dccf8d573028aaed64185acb8e134e5339afa3 (diff) | |
| download | krino-4667e3dcd416fa3be6aae17326c57a5e065a4d5b.tar.gz krino-4667e3dcd416fa3be6aae17326c57a5e065a4d5b.zip | |
krino: 0.0.3 — the plan as one block per file, wrapped, and -Pv0.0.3
Each file shows its steps, then the rule and the reason it matched, one
field per line; on a terminal every line wraps to its width with
continuation lines under their own column, and piped output is never
wrapped. Choosing per file shows the same block. -P / --no-pager prints
the plan without the pager. A duplicate's original is shown with ~.
Diffstat (limited to 'cmd/krino/colour.go')
| -rw-r--r-- | cmd/krino/colour.go | 53 |
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 { |
