Skip to content

Commit

Permalink
brief: highlight evidence (chainguard-dev#566)
Browse files Browse the repository at this point in the history
* brief: highlight evidence

* remove whitespace
  • Loading branch information
tstromberg authored Nov 3, 2024
1 parent 4d6d3b4 commit 9cedac6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/render/terminal_brief.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"io"

"github.com/chainguard-dev/malcontent/pkg/malcontent"
"github.com/fatih/color"
)

type TerminalBrief struct {
Expand All @@ -36,11 +37,29 @@ func (r TerminalBrief) File(_ context.Context, fr *malcontent.FileReport) error
return nil
}

width := suggestedWidth()
fmt.Fprintf(r.w, "├─ %s %s\n", riskEmoji(fr.RiskScore), fr.Path)

for _, b := range fr.Behaviors {
content := fmt.Sprintf("│ %s %s — %s", riskColor(fr.RiskLevel, "•"), riskColor(fr.RiskLevel, b.ID), b.Description)
e := evidenceString(b.MatchStrings, b.Description)
fmt.Fprintf(r.w, "│ %s %s — %s%s\n", riskColor(fr.RiskLevel, "•"), riskColor(fr.RiskLevel, b.ID), b.Description, e)

// no evidence to give
if e == "" {
continue
}

fmt.Fprint(r.w, content)
color.New(color.FgHiBlack).Fprint(r.w, ":")
e = color.RGB(255, 255, 255).Sprint(e)

// Two-line output for long evidence strings
if ansiLineLength(content+e)+1 > width && len(e) > 4 {
fmt.Fprintln(r.w, "\n"+truncate(fmt.Sprintf("│ %s", e), width))
continue
}
// Single-line output for short evidence
fmt.Fprintln(r.w, " "+e)
}

return nil
Expand Down

0 comments on commit 9cedac6

Please sign in to comment.