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

fix: ensure project names are readable in dark terminals #7371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/renderers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export function formatProjectName(name: string | undefined, suffix = ' ') {
.split('')
.reduce((acc, v, idx) => acc + v.charCodeAt(0) + idx, 0)

const colors = [c.black, c.yellow, c.cyan, c.green, c.magenta]
const colors = [c.blue, c.yellow, c.cyan, c.green, c.magenta]
Copy link
Member

@AriPerkkio AriPerkkio Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the bug here that c.black doesn't use proper background color? It should have some light background color, so that it would be visible in both light and dark backgrounds. c.inverse below should do that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the feedback.

My understanding is that c.inverse() causes background colors to become foreground colors and vice versa, but since we're not setting separate background and foreground colors here, the result of c.inverse(c.black('text')) is a black background with text that's the color of the terminal's default background color.

In a terminal with a light background, this is likely to be readable because it will result in light text on black. In a terminal with a dark background, this is unlikely to be readable because it will result in dark text on black.

I've fixed this by using blue instead of black, because blue as a background color is more likely to be readable with both light and dark text (though it's still not guaranteed, since it depends on the specific color scheme in use in the terminal).

An alternative approach would be to define explicit colors for both the background and the foreground, in which case we would no longer need to use c.inverse(). Is this what you're suggesting, or would you like to see something else?


return c.inverse(colors[index % colors.length](` ${name} `)) + suffix
}
Expand Down
Loading