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

Add option to hide background colors #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export type Config = Theme & {
WRAP_LINES: boolean;
HIGHLIGHT_LINE_CHANGES: boolean;
SYNTAX_HIGHLIGHTING_THEME?: string;
HIDE_BACKGROUND: boolean;
};
4 changes: 3 additions & 1 deletion src/getGitConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export async function getGitConfig(

// Defaults to "dark"
const themeName = rawConfig['theme-name'] ?? 'dark';
const theme = loadTheme(themeName);
const hideBackground = rawConfig['hide-background'] === 'true';
const theme = loadTheme(themeName, hideBackground);

// Defaults to the theme's setting
const syntaxHighlightingTheme =
Expand Down Expand Up @@ -65,5 +66,6 @@ export async function getGitConfig(
WRAP_LINES: wrapLines,
HIGHLIGHT_LINE_CHANGES: highlightLineChanges,
SYNTAX_HIGHLIGHTING_THEME: syntaxHighlightingTheme,
HIDE_BACKGROUND: hideBackground,
};
}
22 changes: 21 additions & 1 deletion src/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export enum ThemeColorName {
MISSING_LINE_COLOR = 'MISSING_LINE_COLOR',
}

export const NO_BACKGROUND_THEME_COLORS: ThemeColorName[] = [
ThemeColorName.COMMIT_HEADER_COLOR,
ThemeColorName.COMMIT_MESSAGE_COLOR,
ThemeColorName.BORDER_COLOR,
ThemeColorName.FILE_NAME_COLOR,
ThemeColorName.UNMODIFIED_LINE_NO_COLOR,
ThemeColorName.UNMODIFIED_LINE_COLOR,
ThemeColorName.MISSING_LINE_COLOR,
];

export type ThemeDefinition = {
SYNTAX_HIGHLIGHTING_THEME?: string;
} & {
Expand Down Expand Up @@ -162,7 +172,10 @@ function loadThemeDefinition(themeName: string): ThemeDefinition {
) as ThemeDefinition;
}

export function loadTheme(themeName: string): Theme {
export function loadTheme(
themeName: string,
hideBackground: boolean = false
): Theme {
const themeDefinition = loadThemeDefinition(themeName);

const theme: Partial<Theme> = {
Expand All @@ -176,6 +189,13 @@ export function loadTheme(themeName: string): Theme {
assert.fail(`${variableName} is missing in theme`);
}
theme[variableName] = parseColorDefinition(value);

if (
hideBackground &&
NO_BACKGROUND_THEME_COLORS.includes(variableName)
) {
(theme[variableName] as ThemeColor).backgroundColor = undefined;
}
}

return theme as Theme;
Expand Down