-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mainly an attempt to clear up what is configurable via git and what gets loaded separately.
- Loading branch information
Showing
8 changed files
with
203 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { GitConfig } from './getGitConfig'; | ||
import { Theme, loadTheme } from './themes'; | ||
import * as shikiji from 'shikiji'; | ||
|
||
export type Config = Theme & { | ||
MIN_LINE_WIDTH: number; | ||
WRAP_LINES: boolean; | ||
HIGHLIGHT_LINE_CHANGES: boolean; | ||
}; | ||
|
||
export const DEFAULT_THEME_NAME = 'dark'; | ||
|
||
export const CONFIG_DEFAULTS: Omit<Config, keyof Theme> = { | ||
MIN_LINE_WIDTH: 80, | ||
WRAP_LINES: true, | ||
HIGHLIGHT_LINE_CHANGES: true, | ||
}; | ||
|
||
export function getConfig(gitConfig: GitConfig): Config { | ||
const theme = loadTheme(gitConfig.THEME_NAME ?? DEFAULT_THEME_NAME); | ||
|
||
return { | ||
...CONFIG_DEFAULTS, | ||
...theme, | ||
...gitConfig, | ||
SYNTAX_HIGHLIGHTING_THEME: (theme.SYNTAX_HIGHLIGHTING_THEME ?? | ||
gitConfig.SYNTAX_HIGHLIGHTING_THEME) as shikiji.BundledTheme, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { DEFAULT_THEME_NAME } from './getConfig'; | ||
import { | ||
DEFAULT_MIN_LINE_WIDTH, | ||
GitConfig, | ||
getGitConfig, | ||
} from './getGitConfig'; | ||
|
||
const DEFAULT_CONFIG: GitConfig = { | ||
WRAP_LINES: true, | ||
HIGHLIGHT_LINE_CHANGES: true, | ||
MIN_LINE_WIDTH: DEFAULT_MIN_LINE_WIDTH, | ||
THEME_NAME: DEFAULT_THEME_NAME, | ||
}; | ||
|
||
describe('getGitConfig', () => { | ||
test('empty', () => { | ||
expect(getGitConfig('')).toEqual(DEFAULT_CONFIG); | ||
}); | ||
|
||
test('full', () => { | ||
expect( | ||
getGitConfig(` | ||
split-diffs.wrap-lines=false | ||
split-diffs.highlight-line-changes=false | ||
split-diffs.min-line-width=40 | ||
split-diffs.theme-name=arctic | ||
split-diffs.syntax-highlighting-theme=dark-plus | ||
`) | ||
).toEqual({ | ||
WRAP_LINES: false, | ||
HIGHLIGHT_LINE_CHANGES: false, | ||
MIN_LINE_WIDTH: 40, | ||
THEME_NAME: 'arctic', | ||
SYNTAX_HIGHLIGHTING_THEME: 'dark-plus', | ||
}); | ||
}); | ||
|
||
test('partial', () => { | ||
expect( | ||
getGitConfig(` | ||
split-diffs.wrap-lines=true | ||
split-diffs.syntax-highlighting-theme=nord | ||
`) | ||
).toEqual({ | ||
...DEFAULT_CONFIG, | ||
WRAP_LINES: true, | ||
SYNTAX_HIGHLIGHTING_THEME: 'nord', | ||
}); | ||
}); | ||
|
||
test('invalid values', () => { | ||
expect( | ||
getGitConfig(` | ||
split-diffs.wrap-lines=1 | ||
split-diffs.highlight-line-changes=1 | ||
split-diffs.min-line-width=bar | ||
split-diffs.syntax-highlighting-theme=foo | ||
split-diffs.theme-name=baz | ||
`) | ||
).toEqual({ | ||
...DEFAULT_CONFIG, | ||
SYNTAX_HIGHLIGHTING_THEME: 'foo', | ||
THEME_NAME: 'baz', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.