ThemeController
class exported by @mwillbanks/tuil-theme.
class
Public class exported by @mwillbanks/tuil-theme.
export class ThemeController {
readonly #capabilities: TerminalCapabilities;
readonly #observers = new Set<() => void>();
#theme: Theme;
constructor(theme: Theme, capabilities: TerminalCapabilities) {
this.#capabilities = capabilities;
this.#theme = normalizeTheme(theme, capabilities);
}
get(): Theme {
return this.#theme;
}
set(theme: Theme | ThemeFactory): Theme {
const selected = typeof theme === "function" ? theme(this.#theme) : theme;
const next = normalizeTheme(selected, this.#capabilities);
if (next === this.#theme) return next;
this.#theme = next;
for (const observer of this.#observers) observer();
return next;
}
observe(observer: () => void): () => void {
this.#observers.add(observer);
return () => this.#observers.delete(observer);
}
}Members
| Member | Type | Required | Description | Related types |
|---|---|---|---|---|
#capabilities | TerminalCapabilities | Yes | The #capabilities member uses the TerminalCapabilities contract. | TerminalCapabilities |
#observers | Set<() => void> | Yes | The #observers member uses the Set<() => void> contract. | — |
#theme | Theme | Yes | The #theme member uses the Theme contract. | Theme |
__constructor | any | Yes | The __constructor member uses the any contract. | — |
get | () => Theme | Yes | The get member uses the () => Theme contract. | Theme |
set | (theme: Theme | ThemeFactory) => Theme | Yes | The set member uses the (theme: Theme | ThemeFactory) => Theme contract. | Theme, ThemeFactory |
observe | (observer: () => void) => () => void | Yes | The observe member uses the (observer: () => void) => () => void contract. | — |
Parameters
This declaration has no public members.
Returns
This declaration does not return a value.
Throws
No thrown errors are documented for this declaration.
Related types
Source
View the secondary source reference