-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4065424
commit 7e29bf8
Showing
27 changed files
with
1,472 additions
and
1,394 deletions.
There are no files selected for viewing
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
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
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
38 changes: 19 additions & 19 deletions
38
src/papyrus-lang-vscode/src/common/colorizer/colorizer.ts
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import * as chalk_d from 'chalk' | ||
import * as chalk_d from 'chalk'; | ||
import get from 'lodash.get'; | ||
import { ColorizerOptions, Token } from './types'; | ||
|
||
interface ColorMap { | ||
[key: string]: string; | ||
[key: string]: string; | ||
} | ||
|
||
const defaultColors: ColorMap = { | ||
BRACE: 'gray', | ||
BRACKET: 'gray', | ||
COLON: 'gray', | ||
COMMA: 'gray', | ||
STRING_KEY: 'magenta', | ||
STRING_LITERAL: 'yellow', | ||
NUMBER_LITERAL: 'green', | ||
BOOLEAN_LITERAL: 'cyan', | ||
NULL_LITERAL: 'white' | ||
BRACE: 'gray', | ||
BRACKET: 'gray', | ||
COLON: 'gray', | ||
COMMA: 'gray', | ||
STRING_KEY: 'magenta', | ||
STRING_LITERAL: 'yellow', | ||
NUMBER_LITERAL: 'green', | ||
BOOLEAN_LITERAL: 'cyan', | ||
NULL_LITERAL: 'white', | ||
}; | ||
|
||
const nonForcedChalk = new chalk_d.default.constructor(); | ||
const forcedChalk = new chalk_d.default.constructor({ enabled: true, level: 2 }); | ||
export function colorize(tokens: Token[], options?: ColorizerOptions): string { | ||
const colors = options?.colors || {}; | ||
const colors = options?.colors || {}; | ||
|
||
return tokens.reduce((acc, token) => { | ||
const chalk : chalk_d.Chalk = options?.forceColor ? forcedChalk : nonForcedChalk; | ||
const colorKey = colors[token.type] || defaultColors[token.type]; | ||
const colorFn = colorKey && colorKey[0] === '#' ? chalk.hex(colorKey) : get(chalk, colorKey); | ||
return tokens.reduce((acc, token) => { | ||
const chalk: chalk_d.Chalk = options?.forceColor ? forcedChalk : nonForcedChalk; | ||
const colorKey = colors[token.type] || defaultColors[token.type]; | ||
const colorFn = colorKey && colorKey[0] === '#' ? chalk.hex(colorKey) : get(chalk, colorKey); | ||
|
||
return acc + (colorFn ? colorFn(token.value) : token.value); | ||
}, ''); | ||
} | ||
return acc + (colorFn ? colorFn(token.value) : token.value); | ||
}, ''); | ||
} |
Oops, something went wrong.