Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brief: highlight evidence #566

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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