Allow to customize terminal theme (#4666)

Allow to customize terminal theme, fix #2224
This commit is contained in:
Roman authored and GitHub committed 2022-01-12 17:42:51 +02:00
1 parent 2ee47a442a
commit a5e89b79d6
9 files changed
+106 -65

No files matched your search

@@ -57,24 +57,38 @@ export const Application = observer(() => {
const [customUrl, setCustomUrl] = React.useState(userStore.extensionRegistryUrl.customUrl || "");
const [shell, setShell] = React.useState(userStore.shell || "");
const extensionSettings = AppPreferenceRegistry.getInstance().getItems().filter((preference) => preference.showInPreferencesTab === "application");
const themeStore = ThemeStore.getInstance();
return (
<section id="application">
<h2 data-testid="application-header">Application</h2>
<section id="appearance">
<SubTitle title="Theme"/>
<SubTitle title="Theme" />
<Select
options={ThemeStore.getInstance().themeOptions}
options={themeStore.themeOptions}
value={userStore.colorTheme}
onChange={({ value }) => userStore.colorTheme = value}
themeName="lens"
/>
</section>
<hr/>
<hr />
<section id="terminalTheme">
<SubTitle title="Terminal theme" />
<Select
themeName="lens"
options={[
{ label: "Match theme", value: "" },
...themeStore.themeOptions,
]}
value={userStore.terminalTheme}
onChange={({ value }) => userStore.terminalTheme = value}
/>
</section>
<section id="shell">
<SubTitle title="Terminal Shell Path"/>
<SubTitle title="Terminal Shell Path" />
<Input
theme="round-black"
placeholder={defaultShell}
@@ -94,7 +108,7 @@ export const Application = observer(() => {
</Switch>
</section>
<hr/>
<hr />
<section id="extensionRegistryUrl">
<SubTitle title="Extension Install Registry" />
+4 -1
View File
@@ -76,11 +76,14 @@
.tab-content {
position: relative;
background: var(--terminalBackground);
flex: 1;
overflow: hidden;
transition: flex-basis 25ms ease-in;
&.terminal {
background: var(--terminalBackground);
}
> *:not(.Spinner) {
position: absolute;
left: 0;
+1 -1
View File
@@ -105,7 +105,7 @@ export class Dock extends React.Component<Props> {
if (!isOpen || !selectedTab) return null;
return (
<div className="tab-content" style={{ flexBasis: height }}>
<div className={`tab-content ${selectedTab.kind}`} style={{ flexBasis: height }}>
{this.renderTab(selectedTab)}
</div>
);
+5 -20
View File
@@ -26,9 +26,9 @@ import { FitAddon } from "xterm-addon-fit";
import { dockStore, TabId } from "./dock.store";
import { TerminalApi, TerminalChannels } from "../../api/terminal-api";
import { ThemeStore } from "../../theme.store";
import { boundMethod, disposer } from "../../utils";
import { disposer } from "../../utils";
import { isMac } from "../../../common/vars";
import { camelCase, once } from "lodash";
import { once } from "lodash";
import { UserStore } from "../../../common/user-store";
import { clipboard } from "electron";
import logger from "../../../common/logger";
@@ -56,23 +56,6 @@ export class Terminal {
private scrollPos = 0;
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() {
return this.xterm?.element;
}
@@ -121,7 +104,9 @@ export class Terminal {
window.addEventListener("resize", this.onResize);
this.disposer.push(
reaction(() => ThemeStore.getInstance().activeTheme.colors, this.setTheme, {
reaction(() => ThemeStore.getInstance().xtermColors, colors => {
this.xterm?.setOption("theme", colors);
}, {
fireImmediately: true,
}),
dockStore.onResize(this.onResize),