Aptivi - Manual
ProjectsWebsiteBlog
Terminaux - Manual
Terminaux - Manual
  • Welcome!
  • Breaking changes
    • API v1.0
    • API v2.0
    • API v3.0
    • API v4.0
    • API v5.0
    • API v6.0
    • API v7.0
  • Usage
    • Preface
    • Console Tools
      • Console Checker
        • Console Size Requirements
      • Image Rendering
        • Icons
      • Console Writers
        • Individual Writers
        • Cyclic Writers
          • Geometric Shapes
          • Charts
          • Text
          • Artistic
          • Progress Bars
          • Lists and Calendars
          • Miscellaneous
        • Informational Boxes
      • Textual UI
        • Interactive TUI
        • Console Screen
        • Console Resize Listener
        • VT Sequences
      • Console Wrapper
      • Console Colors
      • Color Templates
      • Presentation System
      • Console Extensions
      • Nerd Fonts
      • Terminal Info
      • Test Fixtures
      • Terminal Structures
      • Console Logging
    • Input Reader
      • Shells
        • Shell Structure
          • Help System
          • Command Parsing
          • Command Information
          • Command Switches
          • Shell Presets
          • Command Aliasing
      • Other Input
        • Keybindings
        • Choice-based inputs
        • Editors and Viewers
        • Figlet Font Selector
        • Color Wheel
        • Spinner Selector
      • Reader State
      • Reader Settings
      • Syntax Highlighting
      • Pointer Events
    • Color Sequences
      • Color Model Conversions
      • Color Model Parsing
      • Interop with System.Drawing.Color
  • Report an issue
  • Source code
  • API Reference
Powered by GitBook
On this page
  • Examples
  • Registering the template from info
  • Registering the template from JSON
  • Setting the template as default
  • Unregistering a template
Edit on GitHub
  1. Usage
  2. Console Tools

Color Templates

Colors in one group.

The color templates allow you to organize your colors into one group, known as a template. It allows you to group all your colors and categorize them into a template for easier organization without resorting to building your own in your application. These templates can be built from a JSON string or a file, but should be of the below format:

{
    "Name": "template",
    "Components": {
        "Text": "#876543",
        "Component": "#345678",
        (...)
    }
}

The name and the list of components should be provided in order for the template reader to successfully parse your template and return a TemplateInfo class, which consists of the same read-only properties.

In addition to having these two properties being set, you must implement at least the following components:

  • Text: Neutral text color

The template reader function to parse your template JSON files is GetTemplateFromJson() that takes template JSON strings. You'll have to manually read the contents of the template file using File.ReadAllText() before using this function.

After you get a TemplateInfo class instance, you can use that to register it to the template manager. This way, you've added your template. This means that you can set it as a default template so that all of the functions that use your default template, such as GetColor(), can use it to get the colors from the template components.

You can also get a JSON representation of your template using GetTemplateToJson() to be able to save them to files for later use. You can also make your own template by calling a constructor of TemplateInfo.

Examples

Here are the examples of how you can use this feature. Please note that these examples are sequential and don't work independently.

Registering the template from info

// Custom template
var template = new TemplateInfo(name, new()
{
    { "Text", new("#876543") },
    { "Component", new(168555) },
});
TemplateTools.RegisterTemplate(template);

Registering the template from JSON

// Custom template
string templateJson =
    $$"""
    {
        "Name": "{{name}}",
        "Components": {
            "Text": "#876543",
            "Component": "#345678"
        }
    }
    """;
var template = TemplateTools.GetTemplateFromJson(templateJson);
TemplateTools.RegisterTemplate(template);

Setting the template as default

TextWriterColor.WriteColor("[Before - {0}] Hello world!", true, TemplateTools.GetColor(PredefinedComponentType.Text), TemplateTools.Exists(name));
TemplateTools.SetDefaultTemplate(name);
TextWriterColor.WriteColor("[After - Text] Hello world!", true, TemplateTools.GetColor(PredefinedComponentType.Text));
TextWriterColor.WriteColor("[After - Component] Hello world!\n", true, TemplateTools.GetColor("Component"));

Unregistering a template

TextWriterColor.WriteColor("\n[Reset - {0}] Hello world!", true, TemplateTools.GetColor(PredefinedComponentType.Text), TemplateTools.Exists(name));
TemplateTools.UnregisterTemplate(name);
TextWriterColor.WriteColor("[Reset - {0}] Hello world!\n", true, TemplateTools.GetColor(PredefinedComponentType.Text), TemplateTools.Exists(name));

Last updated 7 months ago