Skip to content

Commit

Permalink
terminal: improve color matching, diff readability (chainguard-dev#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg authored Nov 7, 2024
1 parent 0e449cf commit db63e0d
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions pkg/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func New(kind string, w io.Writer) (malcontent.Renderer, error) {
}

func riskEmoji(score int) string {
symbol := "🟢"
symbol := "🔵"
switch score {
case 2:
symbol = "🟡"
case 3:
symbol = "🟠"
case 4:
symbol = "🛑"
case 4:
symbol = "😈"
}

return symbol
Expand Down
16 changes: 8 additions & 8 deletions pkg/render/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func riskInColor(level string) string {
func riskColor(level string, text string) string {
switch level {
case "LOW":
return color.HiGreenString(text)
return color.HiCyanString(text)
case "MEDIUM", "MED":
return color.HiYellowString(text)
case "HIGH":
Expand Down Expand Up @@ -299,24 +299,24 @@ func renderFileSummary(_ context.Context, fr *malcontent.FileReport, w io.Writer
}
}

prefix := "│ "
prefix := "│ "
bullet := riskEmoji(b.RiskScore)
content := fmt.Sprintf("%s%s %s %s", prefix, indent, riskColor(b.RiskLevel, bullet+" "+rest), desc)
content := fmt.Sprintf("%s%s%s %s", prefix, indent, riskColor(b.RiskLevel, bullet+" "+rest), desc)
pc := color.New()

if diffMode {
content = fmt.Sprintf("%s%s %s %s %s", prefix, indent, bullet, rest, desc)
content = fmt.Sprintf("%s%s%s %s %s", prefix, indent, bullet, rest, desc)

if b.DiffAdded {
pc = color.New(color.FgHiGreen)
prefix = "++"
content = fmt.Sprintf("%s%s %s %s %s", prefix, indent, bullet, rest, desc)
prefix = "+++"
content = fmt.Sprintf("%s%s%s %s %s", prefix, indent, bullet, rest, desc)
}

if b.DiffRemoved {
prefix = "--"
prefix = "---"
pc = color.New(color.FgHiRed)
content = fmt.Sprintf("%s%s %s %s %s", prefix, indent, bullet, rest, desc)
content = fmt.Sprintf("%s%s%s %s %s", prefix, indent, bullet, rest, desc)
e = ""
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Changed: javascript/2024.lottie-player/lottie-player.min.js [🟡 MEDIUM → 🛑 CRITICAL]
## Changed: javascript/2024.lottie-player/lottie-player.min.js [🟡 MEDIUM → 😈 CRITICAL]

### 43 new behaviors

Expand Down
2 changes: 1 addition & 1 deletion tests/linux/2022.bpfdoor/2023.ConnectBack/tiny.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## linux/2022.bpfdoor/2023.ConnectBack/tiny [🛑 CRITICAL]
## linux/2022.bpfdoor/2023.ConnectBack/tiny [😈 CRITICAL]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|----------|
Expand Down
2 changes: 1 addition & 1 deletion tests/linux/2023.ConnectBack/tiny.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## linux/2023.ConnectBack/tiny [🛑 CRITICAL]
## linux/2023.ConnectBack/tiny [😈 CRITICAL]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|----------|
Expand Down
2 changes: 1 addition & 1 deletion tests/linux/2024.Darkcracks/darkcracks.sh.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## linux/2024.Darkcracks/darkcracks.sh [🛑 CRITICAL]
## linux/2024.Darkcracks/darkcracks.sh [😈 CRITICAL]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion tests/linux/UPX/06ed158.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## linux/UPX/06ed158 [🛑 CRITICAL]
## linux/UPX/06ed158 [😈 CRITICAL]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------|------------------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion tests/linux/clean/lslogins.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## linux/clean/lslogins [🟠 HIGH]
## linux/clean/lslogins [🛑 HIGH]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion tests/linux/clean/pandoc.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/linux/clean/qemu-system-xtensa.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/linux/clean/tree-sitter.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/linux/clean/trufflehog.md

Large diffs are not rendered by default.

Binary file modified tests/macOS/2023.3CX/libffmpeg.change_decrease.mdiff
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/macOS/2023.3CX/libffmpeg.change_increase.mdiff
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| -LOW | [net/url/parse](https://github.com/chainguard-dev/malcontent/blob/main/rules/net/url/parse.yara#url_handle) | Handles URL strings | [URLContext](https://github.com/search?q=URLContext&type=code) |
| -LOW | [process/multithreaded](https://github.com/chainguard-dev/malcontent/blob/main/rules/process/multithreaded.yara#pthread_create) | [creates pthreads](https://man7.org/linux/man-pages/man3/pthread_create.3.html) | [pthread_create](https://github.com/search?q=pthread_create&type=code) |

## Added: libffmpeg.dirty.dylib [🛑 CRITICAL]
## Added: libffmpeg.dirty.dylib [😈 CRITICAL]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion tests/macOS/2023.3CX/libffmpeg.change_unrelated.mdiff
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| -LOW | [net/url/parse](https://github.com/chainguard-dev/malcontent/blob/main/rules/net/url/parse.yara#url_handle) | Handles URL strings | [URLContext](https://github.com/search?q=URLContext&type=code) |
| -LOW | [process/multithreaded](https://github.com/chainguard-dev/malcontent/blob/main/rules/process/multithreaded.yara#pthread_create) | [creates pthreads](https://man7.org/linux/man-pages/man3/pthread_create.3.html) | [pthread_create](https://github.com/search?q=pthread_create&type=code) |

## Added: ls [🟢 LOW]
## Added: ls [🔵 LOW]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|------|------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
Binary file modified tests/macOS/2023.3CX/libffmpeg.decrease.mdiff
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/macOS/2023.3CX/libffmpeg.dirty.mdiff
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| -LOW | [net/url/parse](https://github.com/chainguard-dev/malcontent/blob/main/rules/net/url/parse.yara#url_handle) | Handles URL strings | [URLContext](https://github.com/search?q=URLContext&type=code) |
| -LOW | [process/multithreaded](https://github.com/chainguard-dev/malcontent/blob/main/rules/process/multithreaded.yara#pthread_create) | [creates pthreads](https://man7.org/linux/man-pages/man3/pthread_create.3.html) | [pthread_create](https://github.com/search?q=pthread_create&type=code) |

## Added: libffmpeg.dirty.dylib [🛑 CRITICAL]
## Added: libffmpeg.dirty.dylib [😈 CRITICAL]

| RISK | KEY | DESCRIPTION | EVIDENCE |
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
Loading

0 comments on commit db63e0d

Please sign in to comment.