Skip to content
ConsoleMonster
Class

ConsoleSettings

ConsoleMonster

Namespace
ConsoleMonster
Assembly
ConsoleMonster
Modifiers
static

The user's ConsoleMonster preferences: theme, colour, glyphs, motion, mouse, language and culture, read from one settings file so they follow the user into every session and every tool built on ConsoleMonster.

Inheritance

  • object
  • ConsoleSettings

Remarks

Strongest first: an explicit option on the call, this process (ConsoleSettings.Set), a CONSOLEMONSTER_* environment variable, the settings file, then detection. The file is settings.json in ChoiceStore.DefaultRoot; CONSOLEMONSTER_SETTINGS names another file, or none to ignore it. An invalid entry is ignored and listed in ConsoleSettings.Problems, so a bad file never stops a program. Test and headless terminals can read it too (saved accessibility or language settings reach them); a program or test that needs fixed output sets ConsoleSettings.FilePath to null.

Methods

public static string? DefaultFilePath() #

The default settings file path, or null when CONSOLEMONSTER_SETTINGS is none.

Returns

string? The path.
public static ConsoleSetting Get(string name) #

One effective setting.

Parameters

name string required
The setting name (case-insensitive).

Returns

ConsoleSetting The setting.

Exceptions

  • ArgumentException – There is no such setting.
public static void Reload() #

Re-reads the settings file, for example after it was edited by hand.

public static void Reset(string? name = null, bool save = false) #

Removes the value set for this process, and optionally from the file, so the next source applies.

Parameters

name string? = null optional
The setting name, or null for every setting.
save bool = false optional
Also remove it from the settings file.
public static void Set(string name, string value, bool save = false) #

Sets a value for this process, above environment variables, or with save writes it to the settings file (and still applies it now where an environment variable would otherwise win).

Parameters

name string required
The setting name.
value string required
One of the setting's values (Theme also takes a theme file path; Language and Culture a culture name).
save bool = false optional
Also write it to the settings file.

Exceptions

  • ArgumentException – The name or value is not valid.
  • IOException – The file could not be written, or holds invalid JSON that saving would lose.

Properties

public static IReadOnlyList<string> Names { get; } #

The setting names, in the order the settings picker shows them.

public static string? FilePath { get; set; } #

The settings file that is read and saved, or null to ignore it. Defaults to CONSOLEMONSTER_SETTINGS, or settings.json in ChoiceStore.DefaultRoot.

public static IReadOnlyList<ConsoleSetting> Current { get; } #

Every setting with its effective value and source.

public static IReadOnlyList<string> Problems { get; } #

Settings file and environment values that were ignored, with the reason.