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

- fix: reverting handling padding as previous since buggy xterm.fit() plugin

- fix: override/use own terminal css-vars

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2022-01-11 18:11:41 +02:00
parent 1092b876c2
commit c98d4173ed
6 changed files with 54 additions and 48 deletions

View File

@ -79,8 +79,13 @@ export const Application = observer(() => {
<Select <Select
themeName="lens" themeName="lens"
options={[ options={[
{ label: "Use global theme settings", value: "" }, { label: "Match current theme", value: "" },
...themeStore.themeOptions, ...themeStore.themeOptions.map((option) => {
return {
...option,
label: <span>Match theme <em>{option.label}</em></span>,
};
}),
]} ]}
value={userStore.terminalTheme} value={userStore.terminalTheme}
onChange={({ value }) => userStore.terminalTheme = value} onChange={({ value }) => userStore.terminalTheme = value}

View File

@ -80,6 +80,10 @@
overflow: hidden; overflow: hidden;
transition: flex-basis 25ms ease-in; transition: flex-basis 25ms ease-in;
&.terminal {
background: var(--terminalBackground);
}
> *:not(.Spinner) { > *:not(.Spinner) {
position: absolute; position: absolute;
left: 0; left: 0;

View File

@ -105,7 +105,7 @@ export class Dock extends React.Component<Props> {
if (!isOpen || !selectedTab) return null; if (!isOpen || !selectedTab) return null;
return ( return (
<div className="tab-content" style={{ flexBasis: height }}> <div className={`tab-content ${selectedTab.kind}`} style={{ flexBasis: height }}>
{this.renderTab(selectedTab)} {this.renderTab(selectedTab)}
</div> </div>
); );

View File

@ -26,16 +26,7 @@
flex: 1; flex: 1;
overflow: hidden; overflow: hidden;
left: var(--spacing) !important;
.xterm { top: var(--spacing) !important;
padding: var(--spacing); bottom: var(--spacing) !important;
&, &-viewport {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
}
} }

View File

@ -104,8 +104,8 @@ export class Terminal {
window.addEventListener("resize", this.onResize); window.addEventListener("resize", this.onResize);
this.disposer.push( this.disposer.push(
reaction(() => ThemeStore.getInstance().terminalColors, themeColors => { reaction(() => ThemeStore.getInstance().xtermColors, colors => {
this.xterm?.setOption("theme", themeColors); this.xterm?.setOption("theme", colors);
}, { }, {
fireImmediately: true, fireImmediately: true,
}), }),

View File

@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import { computed, makeObservable, observable, reaction } from "mobx"; import { comparer, computed, makeObservable, observable, reaction } from "mobx";
import { autoBind, Singleton } from "./utils"; import { autoBind, Singleton } from "./utils";
import { UserStore } from "../common/user-store"; import { UserStore } from "../common/user-store";
import logger from "../main/logger"; import logger from "../main/logger";
@ -42,7 +42,6 @@ export interface Theme {
} }
export class ThemeStore extends Singleton { export class ThemeStore extends Singleton {
private styles: HTMLStyleElement;
private terminalColorPrefix = "terminal"; private terminalColorPrefix = "terminal";
// bundled themes from `themes/${themeId}.json` // bundled themes from `themes/${themeId}.json`
@ -51,30 +50,35 @@ export class ThemeStore extends Singleton {
"lens-light": lensLightThemeJson as Theme, "lens-light": lensLightThemeJson as Theme,
}); });
@computed get activeThemeId(): string { @computed get activeThemeId(): ThemeId {
return UserStore.getInstance().colorTheme; return UserStore.getInstance().colorTheme;
} }
@computed get terminalThemeId(): ThemeId {
return UserStore.getInstance().terminalTheme;
}
@computed get activeTheme(): Theme { @computed get activeTheme(): Theme {
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> { @computed get terminalColors(): [string, string][] {
const { terminalTheme } = UserStore.getInstance(); const theme = this.themes.get(this.terminalThemeId) ?? this.activeTheme;
const theme = this.themes.get(terminalTheme) ?? this.activeTheme;
const xtermColors: Record<string, string> = {}; // see also "terminal.ts"
// Replacing keys stored in styles to format accepted by terminal return Object
// E.g. terminalBrightBlack -> brightBlack .entries(theme.colors)
for (const [name, color] of Object.entries(theme.colors)) { .filter(([name]) => name.startsWith(this.terminalColorPrefix));
if (!name.startsWith(this.terminalColorPrefix)) continue; // skip }
const xtermColorName = camelCase(name.replace(this.terminalColorPrefix, "")); // Replacing keys stored in styles to format accepted by terminal
// E.g. terminalBrightBlack -> brightBlack
xtermColors[xtermColorName] = color; @computed get xtermColors(): Record<string, string> {
} return Object.fromEntries(
this.terminalColors.map(([name, color]) => [
return xtermColors; camelCase(name.replace(this.terminalColorPrefix, "")),
color,
]),
);
} }
@computed get themeOptions(): SelectOption<string>[] { @computed get themeOptions(): SelectOption<string>[] {
@ -91,15 +95,19 @@ export class ThemeStore extends Singleton {
autoBind(this); autoBind(this);
// auto-apply active theme // auto-apply active theme
reaction(() => this.activeThemeId, themeId => { reaction(() => ({
themeId: this.activeThemeId,
terminalThemeId: this.terminalThemeId,
}), ({ themeId }) => {
try { try {
this.applyTheme(this.getThemeById(themeId)); this.applyTheme(themeId);
} catch (err) { } catch (err) {
logger.error(err); logger.error(err);
UserStore.getInstance().resetTheme(); UserStore.getInstance().resetTheme();
} }
}, { }, {
fireImmediately: true, fireImmediately: true,
equals: comparer.shallow,
}); });
} }
@ -107,20 +115,18 @@ export class ThemeStore extends Singleton {
return this.themes.get(themeId); return this.themes.get(themeId);
} }
protected applyTheme(theme: Theme) { protected applyTheme(themeId: ThemeId) {
if (!this.styles) { const theme = this.getThemeById(themeId);
this.styles = document.createElement("style"); const colors = Object.entries({
this.styles.id = "lens-theme"; ...theme.colors,
document.head.append(this.styles); ...Object.fromEntries(this.terminalColors),
}
const cssVars = Object.entries(theme.colors).map(([cssName, color]) => {
return `--${cssName}: ${color};`;
}); });
this.styles.textContent = `:root {\n${cssVars.join("\n")}}`; colors.forEach(([name, value]) => {
// Adding universal theme flag which can be used in component styles document.documentElement.style.setProperty(`--${name}`, value);
const body = document.querySelector("body"); });
body.classList.toggle("theme-light", theme.type === "light"); // Adding universal theme flag which can be used in component styles
document.body.classList.toggle("theme-light", theme.type === "light");
} }
} }