-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ba9835
commit 605ef20
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |