aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/render.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 11:05:13 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 11:05:13 +0200
commitadc3410395771609d2db5ee5ae2b9da71115c5ca (patch)
tree453def41e18f607332be1088920f9d0c563603a3 /cmd/krino/render.go
parent0468ce38470aa3ae8092b92d4f77e72d25dfa108 (diff)
downloadkrino-adc3410395771609d2db5ee5ae2b9da71115c5ca.tar.gz
krino-adc3410395771609d2db5ee5ae2b9da71115c5ca.zip
krino: coloured output, and --no-color
One palette type styles the plan table, warnings, headers, outcome counts, prompt keys, undo's refused steps and krino log's (undone), from the 16-colour ANSI palette plus bold and faint only. Widths are measured on the plain text, so columns line up; with colour off the output is unchanged. --no-color works before or after any subcommand, as NO_COLOR does. The two search-and-replace colourings are gone.
Diffstat (limited to 'cmd/krino/render.go')
-rw-r--r--cmd/krino/render.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/cmd/krino/render.go b/cmd/krino/render.go
index de5489a..d8e6e47 100644
--- a/cmd/krino/render.go
+++ b/cmd/krino/render.go
@@ -25,10 +25,10 @@ const actionKindWidth = len("rename")
// spec §8.2, below the header line cmdSort has already written: a counts
// line, the numbered action table, the warnings section and the "not
// acted on" line, each present only when it has something to show. No
-// colour, pager or prompt: those arrive with the review UI in plan 4,
-// which wraps this same function, hence its plain (io.Writer, *DirPlan,
-// bool) signature.
-func printPlan(w io.Writer, dp *engine.DirPlan, verbose bool) {
+// pager or prompt: those arrive with the review UI in plan 4, which wraps
+// this same function. p styles the table and the warnings (spec §8.2); the
+// zero palette prints plain text.
+func printPlan(w io.Writer, dp *engine.DirPlan, verbose bool, p palette) {
r := dp.Result
// C1 (plan 2): scanned counts matched, unmatched and skipped alike, not
// just matched plus unmatched - spec §8.2's worked example is "266
@@ -47,13 +47,13 @@ func printPlan(w io.Writer, dp *engine.DirPlan, verbose bool) {
if rows := planRows(dp.Chains, dp.Dir.Root); len(rows) > 0 {
fmt.Fprintln(w)
- printPlanTable(w, rows)
+ printPlanTable(w, rows, p)
}
if len(lines) > 0 {
fmt.Fprintln(w)
- fmt.Fprintln(w, "warnings")
- printWarnings(w, lines)
+ fmt.Fprintln(w, p.warn("warnings"))
+ printWarnings(w, lines, p)
}
if line := skipSummaryLine(r, dp.Chains, verbose); line != "" {
@@ -119,6 +119,7 @@ func countActing(chains []plan.Chain) int {
type planRow struct {
num, file, actions, rule, reason string
chainIdx int
+ step plan.Step // the step this row shows, for styling its cells
}
// planRows turns the chains that have at least one step into table rows,
@@ -137,7 +138,7 @@ func planRows(chains []plan.Chain, root string) []planRow {
}
n++
for i, s := range c.Steps {
- row := planRow{actions: actionCell(s, root), rule: s.Rule, reason: s.Reason, chainIdx: ci}
+ row := planRow{actions: actionCell(s, root), rule: s.Rule, reason: s.Reason, chainIdx: ci, step: s}
if i == 0 {
row.num = strconv.Itoa(n)
row.file = c.File.Rel
@@ -219,8 +220,10 @@ func relToRoot(root, dir string) (rel string, ok bool) {
// column is capped at 40 and the actions column at 46. The reason is the
// last column and is never padded. The row number is right-aligned
// (padLeft, not padCell) so the "#" column stays flush as it widens past
-// a single digit - the layout plan 4's review UI inherits unchanged.
-func printPlanTable(w io.Writer, rows []planRow) {
+// a single digit - the layout plan 4's review UI inherits unchanged. p
+// styles the action, rule and reason cells; widths are measured on the
+// plain text, so the columns line up with colour on.
+func printPlanTable(w io.Writer, rows []planRow, p palette) {
nums := make([]string, len(rows))
files := make([]string, len(rows))
actions := make([]string, len(rows))
@@ -241,7 +244,7 @@ func printPlanTable(w io.Writer, rows []planRow) {
fmt.Fprintf(w, " %s %s %s rule\n", padLeft("#", numW), padCell("file", fileW), padCell("actions", actionsW))
for _, r := range rows {
- fmt.Fprintf(w, " %s %s %s %s %s\n", padLeft(r.num, numW), padCell(r.file, fileW), padCell(r.actions, actionsW), padCell(r.rule, ruleW), r.reason)
+ fmt.Fprintf(w, " %s %s %s %s %s\n", padLeft(r.num, numW), padCell(r.file, fileW), styleAction(p, r.step, padCell(r.actions, actionsW)), padStyled(r.rule, ruleW, p.rule), p.faint(r.reason))
}
}