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

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

Open
Tracked by #44314 ...
maryamariyan opened this issue Nov 11, 2020 · 6 comments
Assignees
Labels
area-System.Console Cost:M Work that requires one engineer up to 2 weeks Priority:3 Work that is nice to have Team:Libraries User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@maryamariyan
Copy link
Member

maryamariyan commented Nov 11, 2020

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

@maryamariyan maryamariyan added area-System.Console untriaged New issue has not been triaged by the area owner User Story A single user-facing feature. Can be grouped under an epic. labels Nov 11, 2020
@maryamariyan maryamariyan added this to the 6.0.0 milestone Nov 11, 2020
@ghost
Copy link

ghost commented Nov 11, 2020

Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley
See info in area-owners.md if you want to be subscribed.


Issue meta data
Issue content: ### 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

Issue author: maryamariyan
Assignees: -
Milestone: [object Object]

@maryamariyan maryamariyan changed the title ANSI Rendering support: Add general VT/ANSI APIs to the System.Console Add general VT/ANSI APIs to the System.Console Nov 11, 2020
@eerhardt
Copy link
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.

@danmoseley danmoseley changed the title Add general VT/ANSI APIs to the System.Console System.Console offers general VT/ANSI APIs Nov 16, 2020
@SteveL-MSFT
Copy link
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).

@iSazonov
Copy link
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.

@danmoseley danmoseley added the Bottom Up Work Not part of a theme, epic, or user story label Nov 25, 2020
@danmoseley danmoseley changed the title System.Console offers general VT/ANSI APIs Developers using Console can employ VT/ANSI APIs (eg to use embedded color codes) Nov 29, 2020
@iSazonov
Copy link
Contributor

iSazonov commented Dec 8, 2020

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

@jeffhandley jeffhandley added the Priority:3 Work that is nice to have label Jan 14, 2021
@adamsitnik adamsitnik added the Cost:S Work that requires one engineer up to 1 week label Jan 14, 2021
@carlossanlop carlossanlop removed the untriaged New issue has not been triaged by the area owner label Jan 21, 2021
@jeffhandley
Copy link
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.

@jeffhandley jeffhandley modified the milestones: 6.0.0, 7.0.0 Jul 7, 2021
@jeffhandley jeffhandley added Cost:M Work that requires one engineer up to 2 weeks and removed Cost:S Work that requires one engineer up to 1 week Bottom Up Work Not part of a theme, epic, or user story labels Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Console Cost:M Work that requires one engineer up to 2 weeks Priority:3 Work that is nice to have Team:Libraries User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests

8 participants