-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom themes and language support to Monaco editor.
- Loading branch information
1 parent
cfa9274
commit 3b9295e
Showing
6 changed files
with
123 additions
and
3 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
36 changes: 36 additions & 0 deletions
36
new-log-viewer/src/components/Editor/MonacoInstance/language.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js"; | ||
|
||
import {TOKEN_NAMES} from "./typings"; | ||
|
||
|
||
const LOG_LANGUAGE_NAME = "logLanguage"; | ||
|
||
|
||
/** | ||
* Registers a custom log language in the Monaco editor. | ||
*/ | ||
const setupCustomLogLanguage = () => { | ||
monaco.languages.register({ | ||
id: LOG_LANGUAGE_NAME, | ||
}); | ||
monaco.languages.setMonarchTokensProvider(LOG_LANGUAGE_NAME, { | ||
tokenizer: { | ||
root: [ | ||
/* eslint-disable @stylistic/js/array-element-newline */ | ||
["INFO", TOKEN_NAMES.CUSTOM_INFO], | ||
["WARN", TOKEN_NAMES.CUSTOM_WARN], | ||
["ERROR", TOKEN_NAMES.CUSTOM_ERROR], | ||
["FATAL", TOKEN_NAMES.CUSTOM_FATAL], | ||
[/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})Z/, TOKEN_NAMES.CUSTOM_DATE], | ||
[/^[\t ]*at.*$/, TOKEN_NAMES.CUSTOM_EXCEPTION], | ||
[/(\d+(?:\.\d+)?([eE])([+-])[0-9](\.[0-9])?|\d+(?:\.\d+)?)/, TOKEN_NAMES.CUSTOM_NUMBER], | ||
/* eslint-enable @stylistic/js/array-element-newline */ | ||
], | ||
}, | ||
}); | ||
}; | ||
|
||
export { | ||
LOG_LANGUAGE_NAME, | ||
setupCustomLogLanguage, | ||
}; |
45 changes: 45 additions & 0 deletions
45
new-log-viewer/src/components/Editor/MonacoInstance/theme.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js"; | ||
|
||
import {THEME_NAME} from "../../../typings/config"; | ||
import {TOKEN_NAMES} from "./typings"; | ||
|
||
|
||
/** | ||
* Sets up custom themes for the Monaco editor. | ||
*/ | ||
const setupThemes = () => { | ||
monaco.editor.defineTheme(THEME_NAME.DARK, { | ||
base: "vs-dark", | ||
inherit: true, | ||
rules: [ | ||
{token: TOKEN_NAMES.CUSTOM_INFO, foreground: "#098658"}, | ||
{token: TOKEN_NAMES.CUSTOM_WARN, foreground: "#ce9178"}, | ||
{token: TOKEN_NAMES.CUSTOM_ERROR, foreground: "#ce9178", fontStyle: "bold"}, | ||
{token: TOKEN_NAMES.CUSTOM_FATAL, foreground: "#ce9178", fontStyle: "bold"}, | ||
{token: TOKEN_NAMES.CUSTOM_DATE, foreground: "#529955"}, | ||
{token: TOKEN_NAMES.CUSTOM_EXCEPTION, foreground: "#ce723b", fontStyle: "italic"}, | ||
{token: TOKEN_NAMES.CUSTOM_NUMBER, foreground: "#3f9ccb"}, | ||
{token: TOKEN_NAMES.COMMENT, foreground: "#008000"}, | ||
], | ||
colors: { | ||
"editor.lineHighlightBackground": "#3c3c3c", | ||
}, | ||
}); | ||
monaco.editor.defineTheme(THEME_NAME.LIGHT, { | ||
base: "vs", | ||
inherit: true, | ||
rules: [ | ||
{token: TOKEN_NAMES.CUSTOM_INFO, foreground: "#098658"}, | ||
{token: TOKEN_NAMES.CUSTOM_WARN, foreground: "#b81560"}, | ||
{token: TOKEN_NAMES.CUSTOM_ERROR, foreground: "#ac1515", fontStyle: "bold"}, | ||
{token: TOKEN_NAMES.CUSTOM_FATAL, foreground: "#ac1515", fontStyle: "bold"}, | ||
{token: TOKEN_NAMES.CUSTOM_DATE, foreground: "#008000"}, | ||
{token: TOKEN_NAMES.CUSTOM_EXCEPTION, foreground: "#ce723b", fontStyle: "italic"}, | ||
{token: TOKEN_NAMES.CUSTOM_NUMBER, foreground: "#3f9ccb"}, | ||
], | ||
colors: {}, | ||
}); | ||
}; | ||
|
||
|
||
export {setupThemes}; |
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