Skip to content

Add Non-Color Attributes (Bold, Italic, Underline, etc.) to Attributes #4058

@tig

Description

@tig

As part of the ColorSchemes redesign discussed in

Terminal.Gui’s Attributes (within ColorScheme, proposed to be renamed Scheme) currently only support colors but will soon need to include non-color styles to align with modern terminal capabilities and user expectations. These styles, inspired by PowerShell’s $PSStyle ANSI styles and common terminal features, include Bold, Italic, Underline, Blink, Reverse, Hidden, and Strikethrough. Adding these to Attributes will enable richer visual styling for Terminal.Gui views, support PowerShell-like TUI applications, and align with efforts to honor user terminal settings (#2381).

This issue focuses on extending Attributes to support these non-color styles, keeping #457 as the master issue for the broader ColorSchemes redesign, including naming changes (#4057).

Current State:

  • Attributes (within ColorScheme) defines foreground and background colors for states like Normal, HotNormal, Focus, HotFocus, and Disabled.
  • No support exists for non-color styles (e.g., Bold, Italic), limiting Terminal.Gui’s ability to render advanced terminal effects.
  • PowerShell’s $PSStyle (PowerShell 7.2+) supports ANSI styles (Bold, Italic, Underline, Blink, Reverse, Hidden, Strikethrough), which Terminal.Gui should emulate for consistency with user terminal settings.

Proposed Changes:

  1. Extend Attributes struct:

    • Define an enum for flags for non-color styles: Bold, Italic, Underline, Blink, Reverse, Hidden, Strikethrough.
    • Add a property for this enum to Attribute
  2. Update Rendering:

  • Modify Terminal.Gui’s rendering engine to apply these styles using ANSI escape sequences or terminal-specific APIs, leveraging truecolor support (Truecolors (direct RGB colors) support #48).
  • Ensure compatibility with terminals supporting 16, 256, or 24-bit RGB colors.
  1. Integrate with Scheme:

    • Update Scheme (or ColorScheme, pending Rename ColorScheme to Scheme and Migrate Colors to ConfigurationManager.Themes #4057) to use the enhanced Attributes for all attributes (Normal, HotNormal, Focus, HotFocus, Disabled, Active, HotActive, ReadOnly).

    • Example:

      var scheme = new Scheme
      {
          Normal = new Attribute { Foreground = Color.White, Bold = true },
          HotNormal = new Attribute { Foreground = Color.Yellow, Underline = true }
      };
  2. Support User Terminal Settings:

  3. Accessibility:

    • Ensure non-color styles maintain readability (e.g., avoid Blink or Hidden for critical UI elements).
    • Enforce contrast for color-based attributes (WCAG 2.1’s 4.5:1 ratio).

Benefits:

Tasks:

  • Define Attributes API for non-color styles (e.g., boolean flags, enum, or bitmask).
  • Update rendering engine to support Bold, Italic, Underline, Blink, Reverse, Hidden, Strikethrough.
  • Integrate enhanced Attributes with Scheme attributes (Normal, Active, etc.).
  • Add support for querying $PSStyle ANSI styles or $TERM capabilities (Attribute System Should honor terminal settings #2381).
  • Ensure accessibility with contrast checks and style restrictions.
  • Update documentation and samples (e.g., add a styled TextView demo).
  • Add unit tests for non-color style rendering.

Related Issues:

Open Questions:

  • Which non-color styles are most critical (e.g., prioritize Bold, Italic over Blink)?
  • Should Attributes use boolean flags, an enum, or a bitmask for styles?
  • How do we handle terminals with limited style support (e.g., no Italic)?

Community feedback on the proposed styles, API design, and prioritization is welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    ✅ Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions