Skip to content

Developers using Console can employ VT/ANSI APIs (eg to use embedded color codes) #44513

Open

Description

@maryamariyan

Usage in Microsoft.Extensions.Logging.Console

Console Formatters introduced in .NET 5.0 allow for the built-in SimpleConsoleFormatter to embed color codes to each log message. But this implementation required knowledge about hardcoding a mapping between VT100 color codes and different background/foreground color changes.

Instead of typing colors to the formatter, we should decouple this by exposing a generic VT100 builder for colors (maybe even a parser) into System.Console. This way, we can simplify the architecture in Microsoft.Extensions.Logging.Console by making ConsoleFormatters's job purely about building up string of log messages structured in a specific format when having colors involved.

Usage in System.CommandLine.Rendering

cc: @eerhardt

Activity

  1. added
    untriaged
    User Story
    on Nov 11, 2020
  2. added this to the 6.0.0 milestone on Nov 11, 2020
  3. changed the title [-]ANSI Rendering support: Add general VT/ANSI APIs to the System.Console[/-] [+]Add general VT/ANSI APIs to the System.Console[/+] on Nov 11, 2020
  4. eerhardt commented on Nov 11, 2020

    @eerhardt
    Member

    System.CommandLine.Rendering/Ansi.cs shows similar logic being duplicated in dotnet/command-line-api as well.

    Another useful part of System.CommandLine.Rendering that we may want to pull into the BCL is the ConsoleFormatInfo class. This allows for ANSI control codes to be included or omitted dynamically depending on the current environment, or explicitly configured by a caller. (The design follows the same design as formatting a number or a date in the rest of .NET.)
    See dotnet/command-line-api#966 for more info.

  5. changed the title [-]Add general VT/ANSI APIs to the System.Console[/-] [+]System.Console offers general VT/ANSI APIs [/+] on Nov 16, 2020
  6. SteveL-MSFT commented on Nov 24, 2020

    @SteveL-MSFT
    Contributor

    I think the biggest help to PowerShell is a .NET API that returns the plain text version of a string (removing all ANSI decoration).

  7. iSazonov commented on Nov 24, 2020

    @iSazonov
    Contributor

    If we look not PowerShell itself but PowerShell module PSReadline - I believe we can find some other methods which could be great candidates for System.Console VT/ANSI APIs.
    I hope @daxian-dbw could add more info.

  8. added
    Bottom Up Work
    on Nov 25, 2020
  9. changed the title [-]System.Console offers general VT/ANSI APIs [/-] [+]Developers using Console can employ VT/ANSI APIs (eg to use embedded color codes)[/+] on Nov 29, 2020
  10. iSazonov commented on Dec 8, 2020

    @iSazonov
    Contributor

    In short:

    1. Transparent support more terminals by utilizing TermInfo (on Windows too). This allows an application turn on/off coloring (and other feature) on the fly and to work on any terminal without recompile.
    2. Support modern coloring 24/32bits Discussion: PowerShell needs to support 24bit color. Where? How? PowerShell/PowerShell#2381
    3. API for calculating string length with and without escape codes.
    4. API for calculating string length for cells to support fullwidth forms. PSReadline workaround
    5. Maybe a rendering engine based on TermInfo entities. This could significantly reduce allocations in custom code, add formattings in resource strings and so on.
    6. API for managing cursor position, getting info about a terminal sizing and resizing.
    7. Supporting alternative terminal buffers.
    8. Supporting scrolling
    9. Supporting clearing screen and whole buffer.
    10. Full featured cross-platform line editor. Enhance Console.ReadLine() to return at Tab #800

    /cc @DHowett

  11. added
    Priority:3
    on Jan 14, 2021
  12. 1 remaining item

  13. self-assigned this
    on Jan 14, 2021
  14. added
    Cost:S
    on Jan 14, 2021
  15. removed
    untriaged
    on Jan 21, 2021
  16. jeffhandley commented on Jul 7, 2021

    @jeffhandley
    Member

    Moving this issue to .NET 7. We will consider this as part of a potential effort for a System.Console redesign as described in #52374.

  17. modified the milestones: 6.0.0, 7.0.0 on Jul 7, 2021
  18. added
    Cost:M
    and removed
    Cost:S
    Bottom Up Work
    on Jan 9, 2022
  19. modified the milestones: 7.0.0, 8.0.0 on Aug 9, 2022
  20. modified the milestones: 8.0.0, 9.0.0 on Jul 28, 2023
  21. modified the milestones: 9.0.0, Future on Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Cost:MPriority:3Team:LibrariesUser Storyarea-System.Console

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions