1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Dark edit recourse area in light color theme #2224

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2022-01-07 16:20:42 +02:00
parent fa3708c879
commit 2c67e041ca
8 changed files with 76 additions and 44 deletions

View File

@ -233,6 +233,19 @@ const terminalCopyOnSelect: PreferenceDescription<boolean> = {
}, },
}; };
const terminalUseDarkTheme: PreferenceDescription<boolean> = {
fromStore(val) {
return val ?? false;
},
toStore(val) {
if (!val) {
return undefined;
}
return val;
},
};
const hiddenTableColumns: PreferenceDescription<[string, string[]][], Map<string, ObservableToggleSet<string>>> = { const hiddenTableColumns: PreferenceDescription<[string, string[]][], Map<string, ObservableToggleSet<string>>> = {
fromStore(val) { fromStore(val) {
return new Map( return new Map(
@ -364,6 +377,7 @@ export const DESCRIPTORS = {
syncKubeconfigEntries, syncKubeconfigEntries,
editorConfiguration, editorConfiguration,
terminalCopyOnSelect, terminalCopyOnSelect,
terminalUseDarkTheme,
updateChannel, updateChannel,
extensionRegistryUrl, extensionRegistryUrl,
}; };

View File

@ -74,6 +74,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
@observable downloadBinariesPath?: string; @observable downloadBinariesPath?: string;
@observable kubectlBinariesPath?: string; @observable kubectlBinariesPath?: string;
@observable terminalCopyOnSelect: boolean; @observable terminalCopyOnSelect: boolean;
@observable terminalUseDarkTheme: boolean;
@observable updateChannel?: string; @observable updateChannel?: string;
@observable extensionRegistryUrl: ExtensionRegistry; @observable extensionRegistryUrl: ExtensionRegistry;
@ -201,6 +202,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
this.syncKubeconfigEntries.replace(DESCRIPTORS.syncKubeconfigEntries.fromStore(preferences?.syncKubeconfigEntries)); this.syncKubeconfigEntries.replace(DESCRIPTORS.syncKubeconfigEntries.fromStore(preferences?.syncKubeconfigEntries));
this.editorConfiguration = DESCRIPTORS.editorConfiguration.fromStore(preferences?.editorConfiguration); this.editorConfiguration = DESCRIPTORS.editorConfiguration.fromStore(preferences?.editorConfiguration);
this.terminalCopyOnSelect = DESCRIPTORS.terminalCopyOnSelect.fromStore(preferences?.terminalCopyOnSelect); this.terminalCopyOnSelect = DESCRIPTORS.terminalCopyOnSelect.fromStore(preferences?.terminalCopyOnSelect);
this.terminalUseDarkTheme = DESCRIPTORS.terminalUseDarkTheme.fromStore(preferences?.terminalUseDarkTheme);
this.updateChannel = DESCRIPTORS.updateChannel.fromStore(preferences?.updateChannel); this.updateChannel = DESCRIPTORS.updateChannel.fromStore(preferences?.updateChannel);
this.extensionRegistryUrl = DESCRIPTORS.extensionRegistryUrl.fromStore(preferences?.extensionRegistryUrl); this.extensionRegistryUrl = DESCRIPTORS.extensionRegistryUrl.fromStore(preferences?.extensionRegistryUrl);
} }
@ -225,6 +227,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
syncKubeconfigEntries: DESCRIPTORS.syncKubeconfigEntries.toStore(this.syncKubeconfigEntries), syncKubeconfigEntries: DESCRIPTORS.syncKubeconfigEntries.toStore(this.syncKubeconfigEntries),
editorConfiguration: DESCRIPTORS.editorConfiguration.toStore(this.editorConfiguration), editorConfiguration: DESCRIPTORS.editorConfiguration.toStore(this.editorConfiguration),
terminalCopyOnSelect: DESCRIPTORS.terminalCopyOnSelect.toStore(this.terminalCopyOnSelect), terminalCopyOnSelect: DESCRIPTORS.terminalCopyOnSelect.toStore(this.terminalCopyOnSelect),
terminalUseDarkTheme: DESCRIPTORS.terminalUseDarkTheme.toStore(this.terminalUseDarkTheme),
updateChannel: DESCRIPTORS.updateChannel.toStore(this.updateChannel), updateChannel: DESCRIPTORS.updateChannel.toStore(this.updateChannel),
extensionRegistryUrl: DESCRIPTORS.extensionRegistryUrl.toStore(this.extensionRegistryUrl), extensionRegistryUrl: DESCRIPTORS.extensionRegistryUrl.toStore(this.extensionRegistryUrl),
}, },

View File

@ -94,6 +94,16 @@ export const Application = observer(() => {
</Switch> </Switch>
</section> </section>
<section id="terminalColors">
<SubTitle title="Terminal color scheme" />
<Switch
checked={userStore.terminalUseDarkTheme}
onChange={() => userStore.terminalUseDarkTheme = !userStore.terminalUseDarkTheme}
>
Always use dark terminal theme colors
</Switch>
</section>
<hr/> <hr/>
<section id="extensionRegistryUrl"> <section id="extensionRegistryUrl">

View File

@ -76,7 +76,6 @@
.tab-content { .tab-content {
position: relative; position: relative;
background: var(--terminalBackground);
flex: 1; flex: 1;
overflow: hidden; overflow: hidden;
transition: flex-basis 25ms ease-in; transition: flex-basis 25ms ease-in;

View File

@ -26,7 +26,8 @@
flex: 1; flex: 1;
overflow: hidden; overflow: hidden;
left: var(--spacing) !important;
top: var(--spacing) !important; > .xterm {
bottom: var(--spacing) !important; padding: var(--spacing);
}
} }

View File

@ -26,9 +26,9 @@ import { FitAddon } from "xterm-addon-fit";
import { dockStore, TabId } from "./dock.store"; import { dockStore, TabId } from "./dock.store";
import { TerminalApi, TerminalChannels } from "../../api/terminal-api"; import { TerminalApi, TerminalChannels } from "../../api/terminal-api";
import { ThemeStore } from "../../theme.store"; import { ThemeStore } from "../../theme.store";
import { boundMethod, disposer } from "../../utils"; import { disposer } from "../../utils";
import { isMac } from "../../../common/vars"; import { isMac } from "../../../common/vars";
import { camelCase, once } from "lodash"; import { once } from "lodash";
import { UserStore } from "../../../common/user-store"; import { UserStore } from "../../../common/user-store";
import { clipboard } from "electron"; import { clipboard } from "electron";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
@ -56,23 +56,6 @@ export class Terminal {
private scrollPos = 0; private scrollPos = 0;
private disposer = disposer(); private disposer = disposer();
@boundMethod
protected setTheme(colors: Record<string, string>) {
if (!this.xterm) {
return;
}
// Replacing keys stored in styles to format accepted by terminal
// E.g. terminalBrightBlack -> brightBlack
const colorPrefix = "terminal";
const terminalColorEntries = Object.entries(colors)
.filter(([name]) => name.startsWith(colorPrefix))
.map(([name, color]) => [camelCase(name.slice(colorPrefix.length)), color]);
const terminalColors = Object.fromEntries(terminalColorEntries);
this.xterm.setOption("theme", terminalColors);
}
get elem() { get elem() {
return this.xterm?.element; return this.xterm?.element;
} }
@ -121,7 +104,9 @@ export class Terminal {
window.addEventListener("resize", this.onResize); window.addEventListener("resize", this.onResize);
this.disposer.push( this.disposer.push(
reaction(() => ThemeStore.getInstance().activeTheme.colors, this.setTheme, { reaction(() => ThemeStore.getInstance().terminalColors, themeColors => {
this.xterm?.setOption("theme", themeColors);
}, {
fireImmediately: true, fireImmediately: true,
}), }),
dockStore.onResize(this.onResize), dockStore.onResize(this.onResize),

View File

@ -28,6 +28,7 @@ import lensLightThemeJson from "./themes/lens-light.json";
import type { SelectOption } from "./components/select"; import type { SelectOption } from "./components/select";
import type { MonacoEditorProps } from "./components/monaco-editor"; import type { MonacoEditorProps } from "./components/monaco-editor";
import { defaultTheme } from "../common/vars"; import { defaultTheme } from "../common/vars";
import { camelCase } from "lodash";
export type ThemeId = string; export type ThemeId = string;
@ -41,7 +42,8 @@ export interface Theme {
} }
export class ThemeStore extends Singleton { export class ThemeStore extends Singleton {
protected styles: HTMLStyleElement; private styles: HTMLStyleElement;
private terminalColorPrefix = "terminal";
// bundled themes from `themes/${themeId}.json` // bundled themes from `themes/${themeId}.json`
private themes = observable.map<ThemeId, Theme>({ private themes = observable.map<ThemeId, Theme>({
@ -57,6 +59,24 @@ export class ThemeStore extends Singleton {
return this.themes.get(this.activeThemeId) ?? this.themes.get(defaultTheme); return this.themes.get(this.activeThemeId) ?? this.themes.get(defaultTheme);
} }
@computed get terminalColors(): Record<string, string> {
const useDarkThemeColors = UserStore.getInstance().terminalUseDarkTheme;
const theme = useDarkThemeColors ? this.themes.get("lens-dark") : this.activeTheme;
const xtermColors: Record<string, string> = {}; // see also "terminal.ts"
// Replacing keys stored in styles to format accepted by terminal
// E.g. terminalBrightBlack -> brightBlack
for (const [name, color] of Object.entries(theme.colors)) {
if (!name.startsWith(this.terminalColorPrefix)) continue; // skip
const xtermColorName = camelCase(name.replace(this.terminalColorPrefix, ""));
xtermColors[xtermColorName] = color;
}
return xtermColors;
}
@computed get themeOptions(): SelectOption<string>[] { @computed get themeOptions(): SelectOption<string>[] {
return Array.from(this.themes).map(([themeId, theme]) => ({ return Array.from(this.themes).map(([themeId, theme]) => ({
label: theme.name, label: theme.name,

View File

@ -76,26 +76,26 @@
"logsBackground": "#24292e", "logsBackground": "#24292e",
"logsForeground": "#ffffff", "logsForeground": "#ffffff",
"logRowHoverBackground": "#35373a", "logRowHoverBackground": "#35373a",
"terminalBackground": "#24292e", "terminalBackground": "#ffffff",
"terminalForeground": "#ffffff", "terminalForeground": "#2d2d2d",
"terminalCursor": "#ffffff", "terminalCursor": "#2d2d2d",
"terminalCursorAccent": "#000000", "terminalCursorAccent": "#ffffff",
"terminalSelection": "#ffffff77", "terminalSelection": "#bfbfbf",
"terminalBlack": "#2e3436", "terminalBlack": "#2d2d2d",
"terminalRed": "#cc0000", "terminalRed": "#cd3734 ",
"terminalGreen": "#4e9a06", "terminalGreen": "#18cf12",
"terminalYellow": "#c4a000", "terminalYellow": "#acb300",
"terminalBlue": "#3465a4", "terminalBlue": "#3d90ce",
"terminalMagenta": "#75507b", "terminalMagenta": "#c100cd",
"terminalCyan": "#06989a", "terminalCyan": "#07c4b9",
"terminalWhite": "#d3d7cf", "terminalWhite": "#d3d7cf",
"terminalBrightBlack": "#555753", "terminalBrightBlack": "#a8a8a8",
"terminalBrightRed": "#ef2929", "terminalBrightRed": "#ff6259",
"terminalBrightGreen": "#8ae234", "terminalBrightGreen": "#5cdb59",
"terminalBrightYellow": "#fce94f", "terminalBrightYellow": "#f8c000",
"terminalBrightBlue": "#729fcf", "terminalBrightBlue": "#008db6",
"terminalBrightMagenta": "#ad7fa8", "terminalBrightMagenta": "#ee55f8",
"terminalBrightCyan": "#34e2e2", "terminalBrightCyan": "#50e8df",
"terminalBrightWhite": "#eeeeec", "terminalBrightWhite": "#eeeeec",
"dialogTextColor": "#87909c", "dialogTextColor": "#87909c",
"dialogBackground": "#ffffff", "dialogBackground": "#ffffff",