-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Console] Add theme and more lexer rules #178757
Merged
yuliacech
merged 14 commits into
elastic:main
from
yuliacech:console/add_more_lexer_rules
Mar 27, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2d20369
[Console] Add more lexer rules
yuliacech a838e11
[Console] Add Console theme for Monaco editor
yuliacech 9cf7402
[Console] Fix end of line rules
yuliacech 12e4ff7
[Console] More fixes for lexer rules and theme
yuliacech 32a4290
[Console] Add xjson rules
yuliacech f09318a
[Console] Finish up
yuliacech f58da35
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine c2f4393
[Console] Fix the build error
yuliacech 1e4d2b4
Merge branch 'main' into console/add_more_lexer_rules
yuliacech 946f0c9
Merge branch 'main' into console/add_more_lexer_rules
yuliacech 7f008a1
Fix eui mocks
yuliacech 1b567e0
Merge branch 'main' into console/add_more_lexer_rules
yuliacech 009d5d2
Merge branch 'main' into console/add_more_lexer_rules
yuliacech c241b76
Revert bazel build change
yuliacech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
File renamed without changes.
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,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const themeRuleGroupBuilderFactory = | ||
(postfix: string = '') => | ||
(tokens: string[], color: string, isBold: boolean = false) => | ||
tokens.map((i) => ({ | ||
token: i + postfix, | ||
foreground: color, | ||
fontStyle: isBold ? 'bold' : '', | ||
})); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { makeHighContrastColor } from '@elastic/eui'; | ||
import { darkMode, euiThemeVars } from '@kbn/ui-theme'; | ||
|
||
import { themeRuleGroupBuilderFactory } from '../common/theme'; | ||
import { monaco } from '../monaco_imports'; | ||
|
||
const buildRuleGroup = themeRuleGroupBuilderFactory(); | ||
|
||
const background = euiThemeVars.euiColorLightestShade; | ||
const methodTextColor = '#DD0A73'; | ||
const urlTextColor = '#00A69B'; | ||
const stringTextColor = '#009926'; | ||
const commentTextColor = '#4C886B'; | ||
const variableTextColor = '#0079A5'; | ||
const booleanTextColor = '#585CF6'; | ||
const numericTextColor = variableTextColor; | ||
export const buildConsoleTheme = (): monaco.editor.IStandaloneThemeData => { | ||
return { | ||
base: darkMode ? 'vs-dark' : 'vs', | ||
inherit: true, | ||
rules: [ | ||
...buildRuleGroup(['method'], makeHighContrastColor(methodTextColor)(background)), | ||
...buildRuleGroup(['url'], makeHighContrastColor(urlTextColor)(background)), | ||
...buildRuleGroup( | ||
['string', 'string-literal', 'multi-string', 'punctuation.end-triple-quote'], | ||
makeHighContrastColor(stringTextColor)(background) | ||
), | ||
...buildRuleGroup(['comment'], makeHighContrastColor(commentTextColor)(background)), | ||
...buildRuleGroup(['variable'], makeHighContrastColor(variableTextColor)(background)), | ||
...buildRuleGroup( | ||
['constant.language.boolean'], | ||
makeHighContrastColor(booleanTextColor)(background) | ||
), | ||
...buildRuleGroup(['constant.numeric'], makeHighContrastColor(numericTextColor)(background)), | ||
], | ||
colors: { | ||
'editor.background': background, | ||
// color of the line numbers | ||
'editorLineNumber.foreground': euiThemeVars.euiColorDarkShade, | ||
// color of the active line number | ||
'editorLineNumber.activeForeground': euiThemeVars.euiColorDarkShade, | ||
// background of the line numbers side panel | ||
'editorGutter.background': euiThemeVars.euiColorEmptyShade, | ||
}, | ||
}; | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering whether we could use the already defined
euiTheme
colors for consistency, like it is done for the code editor theme (which I think is used in Painless lab). For example, the method color could beeuiTheme.euiColorAccentText
. But this decision depends on whether we want to keep the theme as close to the ace editor theme as possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the hard coded values are not great, but we can't currently map them one-to-one without changing the colors. I think there are 2 ways to improve this code: either re-use the already existing json code editor theme, but that changes the look of console. Or alternatively, we try to keep the original look but re-use the built-in colors from EUI as much as possible.
I added a section to #176926 with follow up work once the initial language definition is implemented.