From 07c24054cab965800983ef40f53a05c2db131ede Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 13:26:51 +0200 Subject: krino: 0.0.3 — the plan as one block per file, wrapped, and -P MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ~. --- cmd/krino/colour.go | 53 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'cmd/krino/colour.go') 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 { -- cgit v1.3