Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2181 - Adds configuration manager #2363

Merged
merged 1 commit into from
Feb 20, 2023
Merged

Conversation

tig
Copy link
Collaborator

@tig tig commented Feb 20, 2023

I've deleted #2284 and replaced it with this, targetting v2.

Fixes #2181
Fixes #29

Adds a Configuration Manager.

Configuration Management

Terminal.Gui provides configuration and theme management for Terminal.Gui applications via the [ConfigurationManager](~/api/Terminal.Gui/Terminal.Gui.Configuration.

  1. Settings. Settings are applied to the Application class. Settings are accessed via the Settings property of the ConfigurationManager class.
  2. Themes. Themes are a named collection of settings impacting how applications look. The default theme is named "Default". The built-in configuration stored within the Terminal.Gui library defines two additional themes: "Dark", and "Light". Additional themes can be defined in the configuration files.
  3. AppSettings. AppSettings allow applicaitons to use the ConfigurationManager to store and retrieve application-specific settings.

The The ConfigurationManager will look for configuration files in the .tui folder in the user's home directory (e.g. C:/Users/username/.tui or /usr/username/.tui), the folder where the Terminal.Gui application was launched from (e.g. ./.tui), or as a resource within the Terminal.Gui application's main assembly.

Settings that will apply to all applications (global settings) reside in files named config.json. Settings that will apply to a specific Terminal.Gui application reside in files named appname.config.json, where appname is the assembly name of the application (e.g. UICatalog.config.json).

Settings are applied using the following precedence (higher precedence settings overwrite lower precedence settings):

  1. App specific settings found in the users's home directory (~/.tui/appname.config.json). -- Highest precedence.

  2. App specific settings found in the directory the app was launched from (./.tui/appname.config.json).

  3. App settings in app resources (Resources/config.json).

  4. Global settings found in the the user's home directory (~/.tui/config.json).

  5. Global settings found in the directory the app was launched from (./.tui/config.json).

  6. Default settings defined in the Terminal.Gui assembly -- Lowest precedence.

The UI Catalog application provides an example of how to use the ConfigurationManager class to load and save configuration files. The Configuration Editor scenario provides an editor that allows users to edit the configuration files. UI Catalog also uses a file system watcher to detect changes to the configuration files to tell ConfigurationManager to reaload them; allowing users to change settings without having to restart the application.

What Can Be Configured

Settings

Settings for the Application class.
* QuitKey
* AlternateForwardKey
* AlternateBackwardKey
* UseSystemConsole
* IsMouseDisabled
* HeightAsBuffer

Themes

A Theme is a named collection of settings that impact the visual style of Terminal.Gui applications. The default theme is named "Default". The built-in configuration stored within the Terminal.Gui library defines two more themes: "Dark", and "Light". Additional themes can be defined in the configuration files.

The Json property Theme defines the name of the theme that will be used. If the theme is not found, the default theme will be used.

Themes support defining ColorSchemes as well as various default settings for Views. Both the default color schemes and user defined color schemes can be configured. See ColorSchemes for more information.

Example Configuration File

{
  "$schema": "https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json",
  "Application.QuitKey": {
    "Key": "Esc"
  },
  "AppSettings": {
    "UICatalog.StatusBar": false
  },
  "Theme": "UI Catalog Theme",
  "Themes": [
    {
      "UI Catalog Theme": {
        "ColorSchemes": [
          {
            "UI Catalog Scheme": {
              "Normal": {
                "Foreground": "White",
                "Background": "Green"
              },
              "Focus": {
                "Foreground": "Green",
                "Background": "White"
              },
              "HotNormal": {
                "Foreground": "Blue",
                "Background": "Green"
              },
              "HotFocus": {
                "Foreground": "BrightRed",
                "Background": "White"
              },
              "Disabled": {
                "Foreground": "BrightGreen",
                "Background": "Gray"
              }
            }
          },
          {
            "TopLevel": {
              "Normal": {
                "Foreground": "DarkGray",
                "Background": "White"
              ...
              }
            }
          }
        ],
        "Dialog.DefaultEffect3D": false
      }
    }
  ]
}

Configuration File Schema

Settings are defined in JSON format, according to the schema found here:

https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json


Current PR Status

Latest:

  • To add properties, just annotate any static property on any class with [SerializableConfigurationProperty]
  • Now supports AppSettings so apps can use CM for app-specific settings
  • Option throw json exceptions on load (off by default)
  • Refactored API and schema significantly (again)
  • More theme settings; note esp. Border

What's Missing:

  • Move file system watcher into library out of UI Catalog
  • Add support to ConsoleDriver such that default glyphs can be configured (e.g. Driver.LeftBracket or Driver.VLine
  • Expose ConsoleDriver.DiagnosticFlags
  • Find and expose all "arbitrary" constants (e.g. CollectionNavigator.TypingDelay
  • Figure out how to enable Commands to be configured externally!
  • Figure out how to enable KeyBindings to be configured externally!
  • Schema is out of date
  • @Tzind's ideas about Stream based API

@tig tig merged commit eb90d6a into gui-cs:v2 Feb 20, 2023
@tig tig added this to the v2.0 milestone Feb 20, 2023
@tig tig added the v2 For discussions, issues, etc... relavant for v2 label Feb 20, 2023
@tig tig deleted the v2_config_manager branch April 3, 2024 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 For discussions, issues, etc... relavant for v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant