summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/themes/theme-manager.ts
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-04-22 18:57:47 -0700
committerN. Taylor Mullen <[email protected]>2025-04-22 22:08:13 -0700
commit4c2a5045a0d209cfda5723a4dc84fe59670b558e (patch)
tree2a874aa35a524f683a39f89d5fc288b0a09596f7 /packages/cli/src/ui/themes/theme-manager.ts
parente163e024996ff8bb1152284322831c4f35696801 (diff)
Add theming support.
- Added a number of common themes to our support matrix: - AtomOneDark - Dracula - VS - GitHub - GoogleCode - XCode - ... Admittedly these all were randomly picked, we could probably curate these better... - Added a new `ThemeDialog` UI that can be accessed via `/theme`. It shows your currentlyt available themes and allows you to change them freely. It does **not**: - Save the theme between sessions - Allow you to hit escape - Show a preview prior to selection. - These themes are from reacts highlight js library. Fixes https://b.corp.google.com/issues/412797985
Diffstat (limited to 'packages/cli/src/ui/themes/theme-manager.ts')
-rw-r--r--packages/cli/src/ui/themes/theme-manager.ts47
1 files changed, 46 insertions, 1 deletions
diff --git a/packages/cli/src/ui/themes/theme-manager.ts b/packages/cli/src/ui/themes/theme-manager.ts
index e083575c..7e375574 100644
--- a/packages/cli/src/ui/themes/theme-manager.ts
+++ b/packages/cli/src/ui/themes/theme-manager.ts
@@ -4,20 +4,65 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import { AtomOneDark } from './atom-one-dark.js';
+import { Dracula } from './dracula.js';
+import { GitHub } from './github.js';
+import { GoogleCode } from './googlecode.js';
+import { VS } from './vs.js';
import { VS2015 } from './vs2015.js';
+import { XCode } from './xcode.js';
import { Theme } from './theme.js';
+export interface ThemeDisplay {
+ name: string;
+ active: boolean;
+}
+
class ThemeManager {
private static readonly DEFAULT_THEME: Theme = VS2015;
private readonly availableThemes: Theme[];
private activeTheme: Theme;
constructor() {
- this.availableThemes = [VS2015];
+ this.availableThemes = [
+ AtomOneDark,
+ Dracula,
+ VS,
+ VS2015,
+ GitHub,
+ GoogleCode,
+ XCode,
+ ];
this.activeTheme = ThemeManager.DEFAULT_THEME;
}
/**
+ * Returns a list of available theme names.
+ */
+ getAvailableThemes(): ThemeDisplay[] {
+ return this.availableThemes.map((theme) => ({
+ name: theme.name,
+ active: theme === this.activeTheme,
+ }));
+ }
+
+ /**
+ * Sets the active theme.
+ * @param themeName The name of the theme to activate.
+ */
+ setActiveTheme(themeName: string): void {
+ const foundTheme = this.availableThemes.find(
+ (theme) => theme.name === themeName,
+ );
+
+ if (foundTheme) {
+ this.activeTheme = foundTheme;
+ } else {
+ throw new Error(`Theme "${themeName}" not found.`);
+ }
+ }
+
+ /**
* Returns the currently active theme object.
*/
getActiveTheme(): Theme {