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

[Console Monaco] Add theme for yaml and text mode in output #180080

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
4 changes: 3 additions & 1 deletion packages/kbn-monaco/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ export {
CONSOLE_LANG_ID,
CONSOLE_OUTPUT_LANG_ID,
CONSOLE_THEME_ID,
CONSOLE_OUTPUT_THEME_ID,
CONSOLE_OUTPUT_JSON_THEME_ID,
CONSOLE_OUTPUT_YAML_THEME_ID,
CONSOLE_OUTPUT_TEXT_THEME_ID,
} from './src/console';
4 changes: 3 additions & 1 deletion packages/kbn-monaco/src/console/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
export const CONSOLE_LANG_ID = 'console';
export const CONSOLE_THEME_ID = 'consoleTheme';
export const CONSOLE_OUTPUT_LANG_ID = 'consoleOutput';
export const CONSOLE_OUTPUT_THEME_ID = 'consoleOutputTheme';
export const CONSOLE_OUTPUT_JSON_THEME_ID = 'consoleOutputJsonTheme';
export const CONSOLE_OUTPUT_YAML_THEME_ID = 'consoleOutputYamlTheme';
export const CONSOLE_OUTPUT_TEXT_THEME_ID = 'consoleOutputTextTheme';
export const CONSOLE_POSTFIX = '.console';
11 changes: 9 additions & 2 deletions packages/kbn-monaco/src/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ export {
CONSOLE_LANG_ID,
CONSOLE_OUTPUT_LANG_ID,
CONSOLE_THEME_ID,
CONSOLE_OUTPUT_THEME_ID,
CONSOLE_OUTPUT_JSON_THEME_ID,
CONSOLE_OUTPUT_YAML_THEME_ID,
CONSOLE_OUTPUT_TEXT_THEME_ID,
} from './constants';

export { buildConsoleTheme, buildConsoleOutputTheme } from './theme';
export {
buildConsoleTheme,
buildConsoleOutputJsonTheme,
buildConsoleOutputYamlTheme,
buildConsoleOutputTextTheme,
} from './theme';

export const ConsoleLang: LangModuleType = {
ID: CONSOLE_LANG_ID,
Expand Down
33 changes: 33 additions & 0 deletions packages/kbn-monaco/src/console/theme/basic_theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { darkMode, euiThemeVars } from '@kbn/ui-theme';
import { monaco } from '../../monaco_imports';

const background = euiThemeVars.euiColorLightestShade;

/**
* A utility function that returns a theme with the basic theme features that are used
* in both the Console editor and the Console output panel in all modes.
*/
export const buildConsoleBasicTheme = (): monaco.editor.IStandaloneThemeData => {
return {
base: darkMode ? 'vs-dark' : 'vs',
inherit: true,
rules: [],
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,
},
};
};
10 changes: 6 additions & 4 deletions packages/kbn-monaco/src/console/theme/editor_theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import { euiThemeVars } from '@kbn/ui-theme';

import { themeRuleGroupBuilderFactory } from '../../common/theme';
import { monaco } from '../../monaco_imports';
import { buildConsoleSharedTheme } from './shared';
import { buildConsoleBasicTheme } from './basic_theme';
import { buildConsoleSharedJsonRules } from './shared_json_rules';

const buildRuleGroup = themeRuleGroupBuilderFactory();

const background = euiThemeVars.euiColorLightestShade;
const methodTextColor = '#DD0A73';
const urlTextColor = '#00A69B';
export const buildConsoleTheme = (): monaco.editor.IStandaloneThemeData => {
const sharedTheme = buildConsoleSharedTheme();
const basicTheme = buildConsoleBasicTheme();
const sharedJsonRules = buildConsoleSharedJsonRules();
return {
...sharedTheme,
...basicTheme,
rules: [
...sharedTheme.rules,
...sharedJsonRules,
...buildRuleGroup(['method'], makeHighContrastColor(methodTextColor)(background)),
...buildRuleGroup(['url'], makeHighContrastColor(urlTextColor)(background)),
],
Expand Down
6 changes: 5 additions & 1 deletion packages/kbn-monaco/src/console/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
*/

export { buildConsoleTheme } from './editor_theme';
export { buildConsoleOutputTheme } from './output_theme';
export {
buildConsoleOutputJsonTheme,
buildConsoleOutputYamlTheme,
buildConsoleOutputTextTheme,
} from './output_theme';
24 changes: 20 additions & 4 deletions packages/kbn-monaco/src/console/theme/output_theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@
*/

import { monaco } from '../../monaco_imports';
import { buildConsoleSharedTheme } from './shared';
import { buildConsoleBasicTheme } from './basic_theme';
import { buildConsoleSharedJsonRules } from './shared_json_rules';

export const buildConsoleOutputTheme = (): monaco.editor.IStandaloneThemeData => {
const sharedTheme = buildConsoleSharedTheme();
const basicTheme = buildConsoleBasicTheme();

export const buildConsoleOutputJsonTheme = (): monaco.editor.IStandaloneThemeData => {
const sharedJsonRules = buildConsoleSharedJsonRules();
return {
...basicTheme,
rules: sharedJsonRules,
};
};

export const buildConsoleOutputYamlTheme = (): monaco.editor.IStandaloneThemeData => {
return {
...basicTheme,
};
};

export const buildConsoleOutputTextTheme = (): monaco.editor.IStandaloneThemeData => {
return {
...sharedTheme,
...basicTheme,
};
};
50 changes: 0 additions & 50 deletions packages/kbn-monaco/src/console/theme/shared.ts

This file was deleted.

41 changes: 41 additions & 0 deletions packages/kbn-monaco/src/console/theme/shared_json_rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 { euiThemeVars } from '@kbn/ui-theme';

import { themeRuleGroupBuilderFactory } from '../../common/theme';

const buildRuleGroup = themeRuleGroupBuilderFactory();

const background = euiThemeVars.euiColorLightestShade;
const stringTextColor = '#009926';
const commentTextColor = '#4C886B';
const variableTextColor = '#0079A5';
const booleanTextColor = '#585CF6';
const numericTextColor = variableTextColor;

/**
* A utility function that returns theme rules that are shared between Console editor and
* the Console output panel when it is in JSON mode.
*/
export const buildConsoleSharedJsonRules = () => {
return [
...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)),
];
};
12 changes: 9 additions & 3 deletions packages/kbn-monaco/src/register_globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import {
ConsoleLang,
ConsoleOutputLang,
CONSOLE_THEME_ID,
CONSOLE_OUTPUT_THEME_ID,
CONSOLE_OUTPUT_JSON_THEME_ID,
CONSOLE_OUTPUT_YAML_THEME_ID,
CONSOLE_OUTPUT_TEXT_THEME_ID,
buildConsoleTheme,
buildConsoleOutputTheme,
buildConsoleOutputJsonTheme,
buildConsoleOutputYamlTheme,
buildConsoleOutputTextTheme,
} from './console';

export const DEFAULT_WORKER_ID = 'default';
Expand Down Expand Up @@ -48,7 +52,9 @@ registerLanguage(ConsoleOutputLang);
*/
registerTheme(ESQL_THEME_ID, buildESQlTheme());
registerTheme(CONSOLE_THEME_ID, buildConsoleTheme());
registerTheme(CONSOLE_OUTPUT_THEME_ID, buildConsoleOutputTheme());
registerTheme(CONSOLE_OUTPUT_JSON_THEME_ID, buildConsoleOutputJsonTheme());
registerTheme(CONSOLE_OUTPUT_YAML_THEME_ID, buildConsoleOutputYamlTheme());
registerTheme(CONSOLE_OUTPUT_TEXT_THEME_ID, buildConsoleOutputTextTheme());

const monacoBundleDir = (window as any).__kbnPublicPath__?.['kbn-monaco'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import { VectorTile } from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import { i18n } from '@kbn/i18n';
import { EuiScreenReaderOnly } from '@elastic/eui';
import { CONSOLE_OUTPUT_THEME_ID, CONSOLE_OUTPUT_LANG_ID } from '@kbn/monaco';
import { CONSOLE_OUTPUT_LANG_ID } from '@kbn/monaco';
import { useEditorReadContext, useRequestReadContext } from '../../../contexts';
import { convertMapboxVectorTileToJson } from '../legacy/console_editor/mapbox_vector_tile';
import {
isJSONContentType,
isMapboxVectorTile,
safeExpandLiteralStrings,
languageForContentType,
getThemeForLanguage,
} from '../utilities';

export const MonacoEditorOutput: FunctionComponent = () => {
Expand Down Expand Up @@ -84,7 +85,7 @@ export const MonacoEditorOutput: FunctionComponent = () => {
options={{
fontSize: readOnlySettings.fontSize,
wordWrap: readOnlySettings.wrapMode === true ? 'on' : 'off',
theme: mode === CONSOLE_OUTPUT_LANG_ID ? CONSOLE_OUTPUT_THEME_ID : undefined,
theme: getThemeForLanguage(mode),
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
* Side Public License, v 1.
*/

import { YAML_LANG_ID, CONSOLE_OUTPUT_LANG_ID } from '@kbn/monaco';
import {
YAML_LANG_ID,
CONSOLE_OUTPUT_LANG_ID,
CONSOLE_OUTPUT_JSON_THEME_ID,
CONSOLE_OUTPUT_YAML_THEME_ID,
CONSOLE_OUTPUT_TEXT_THEME_ID,
} from '@kbn/monaco';
import { expandLiteralStrings } from '../../../../shared_imports';

export const isJSONContentType = (contentType?: string) =>
Expand Down Expand Up @@ -40,3 +46,20 @@ export const languageForContentType = (contentType?: string) => {
}
return TEXT_LANGUAGE_ID;
};

export const getThemeForLanguage = (language: string) => {
switch (language) {
case CONSOLE_OUTPUT_LANG_ID: {
return CONSOLE_OUTPUT_JSON_THEME_ID;
}
case YAML_LANG_ID: {
return CONSOLE_OUTPUT_YAML_THEME_ID;
}
case TEXT_LANGUAGE_ID: {
return CONSOLE_OUTPUT_TEXT_THEME_ID;
}
default: {
return undefined;
}
}
};