diff --git a/assets/ts/terminal/Terminal.ts b/assets/ts/terminal/Terminal.ts index ceed0fe..f93ca16 100644 --- a/assets/ts/terminal/Terminal.ts +++ b/assets/ts/terminal/Terminal.ts @@ -6,6 +6,7 @@ import { Help } from "./commands/Help"; import { Kitties } from "./commands/Kitties"; import { List } from "./commands/List"; import { AutocompletingCommand } from "./AutocompletingCommand"; +import { Theme } from "./commands/Theme"; export class Terminal { private inputElement = document.getElementById("prompt-input") as HTMLSpanElement; @@ -20,6 +21,7 @@ export class Terminal { new Help(), new Kitties(), new List(), + new Theme(), ]; public initialise(): void { diff --git a/assets/ts/terminal/commands/Theme.ts b/assets/ts/terminal/commands/Theme.ts new file mode 100644 index 0000000..885dd33 --- /dev/null +++ b/assets/ts/terminal/commands/Theme.ts @@ -0,0 +1,37 @@ +import { Command } from "../Command"; +import { Terminal } from "../Terminal"; +import { setDarkMode } from "../../darkMode"; +import { Theme as ThemeType } from "../../types/main"; +import { AutocompletingCommand } from "../AutocompletingCommand"; + +export class Theme extends AutocompletingCommand { + public readonly name: string = "theme"; + public readonly description: string = + "Set the theme of the website. Available themes: light, dark, system"; + private readonly validThemes = ["light", "dark", "system"]; + + public execute(terminal: Terminal, args: string[]): void { + if (args.length < 1) { + terminal.print("theme: missing arguments"); + return; + } + + if (args.length > 1) { + terminal.print("theme: too many arguments"); + return; + } + + const theme = args[0]; + + if (!this.validThemes.includes(theme)) { + terminal.print("theme: unknown theme"); + return; + } + + setDarkMode(theme as ThemeType); + } + + suggestAutocompletions(arg: string): string[] { + return this.validThemes.filter((name: string) => name.startsWith(arg)); + } +}