Skip to content
FutureBlitz

    Install

    Import std.io.preferences

    std.io.preferences

    std.io's preferences: a program's settings, kept between its runs in the folder each OS keeps its users' programs' settings in, in a file of the program's own, which a save replaces whole.

    std/io/preferences.fb

    Types

    Preferences class

    Public Class Preferences

    A program's settings, by name, kept in //preferences.txt, where the folder is the OS's for its users' settings (Windows' %APPDATA%, macOS's ~/Library/Application Support, and elsewhere $XDG_CONFIG_HOME or ~/.config) unless one's given. Nothing is written until Save, which writes them atomically; IsChanged says whether there's something to save. The file is UTF-8 text a person can read and change: a "key=value" line for each setting, with "\", "\n", and "\r" for a backslash, a line break, and a carriage return in both, "=" for an '=' in a key and "#" for a '#' at its start; a line that starts with '#', or has no '=', is skipped, and so is a byte order mark an editor writes before the first.

    std/io/preferences.fb, line 29

    • Public ReadOnly Field App: String field #

      The program the preferences are for.

    • Public ReadOnly Field Location: Path field #

      The file they're kept in.

    • @PanicsAtCaller Public New(app: String) Throws IOError constructor #

      The program app's preferences, read from the OS's folder for them, or none when there's no file yet. Panics for an app's name that can't be a file's, and throws an IOError when the OS doesn't say where its folder is, or the file can't be read.

    • @PanicsAtCaller Public New(app: String, folder: Path) Throws IOError constructor #

      The preferences of app kept in folder in place of the OS's folder, as tests keep theirs in a temporary folder.

    • Public Static Method Folder(): Path Throws IOError static method #

      The OS's folder for its users' programs' settings, which Preferences keep theirs in: Windows' %APPDATA%, macOS's ~/Library/Application Support, and elsewhere $XDG_CONFIG_HOME when it's a path from the root, or ~/.config. Throws an IOError of OTHER when the OS doesn't say.

    • @PanicsAtCaller Public Static Async Method OpenAsync(app: String): Preferences Throws IOError static method #

      New's Async twin, which reads the file without blocking the main thread.

    • @PanicsAtCaller Public Static Async Method OpenAsync(app: String, folder: Path): Preferences Throws IOError static method #

      New's Async twin, for folder, which reads the file without blocking the main thread.

    • Public Method Get(key: String): String? method #

      The setting key, or Null when there's none.

    • Public Method Get(key: String, fallback: String): String method #

      The setting key, or fallback when there's none.

    • Public Method GetInt(key: String): Int64? method #

      The setting key as an integer, as Int64.Parse reads it, or Null when there's none, or it isn't one.

    • Public Method GetInt(key: String, fallback: Int64): Int64 method #

      The setting key as an integer, or fallback when there's none, or it isn't one.

    • Public Method GetDouble(key: String): Double? method #

      The setting key as a Double, as Double.Parse reads it, or Null when there's none, or it isn't one.

    • Public Method GetDouble(key: String, fallback: Double): Double method #

      The setting key as a Double, or fallback when there's none, or it isn't one.

    • Public Method GetBool(key: String): Bool? method #

      The setting key as a Bool, "True" or "False", or Null when there's none, or it's another.

    • Public Method GetBool(key: String, fallback: Bool): Bool method #

      The setting key as a Bool, or fallback when there's none, or it's another.

    • Public Method Set(key: String, value: String) method #

      Sets key to value, which Save keeps.

    • Public Method SetInt(key: String, value: Int64) method #

      Sets key to the integer's text, which GetInt reads back.

    • Public Method SetDouble(key: String, value: Double) method #

      Sets key to the Double's text, the shortest that reads back as it, which GetDouble does, NaN and the infinities too.

    • Public Method SetBool(key: String, value: Bool) method #

      Sets key to "True" or "False", which GetBool reads back.

    • Public Method Remove(key: String): Bool method #

      Takes out the setting key, and gives whether there was one.

    • Public Method Contains(key: String): Bool method #

      Whether there's a setting key.

    • Public Method Keys(): String[] method #

      The settings' names, in the order they were set, where one that's taken out and set again goes last, and in the file's order after a read.

    • Public Method Count(): Int method #

      How many settings there are.

    • Public Method IsChanged(): Bool method #

      Whether they've changed since they were read or saved.

    • Public Method Clear() method #

      Takes out every setting.

    • Public Method Save() Throws IOError method #

      Writes the settings to their file, making its folder when it isn't there, atomically, so it holds either all of them or what it held before.

    • Public Async Method SaveAsync() Throws IOError method #

      Save's Async twin. A change made while it writes isn't in the file, so IsChanged stays True.

    Report an issue with this page or with FutureBlitz on GitHub.