question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Leverage ANSI escape sequences as the mechanism for rich formatting w/in Terminal.Gui apps

See original GitHub issue

Right now we don’t parse ANSI escape sequences anywhere. Thus any text input that includes them gets drawn funky.

Ideally, any control that renders text should honor ANSI sequences, e.g. changing the color of the text (but also ignoring things like cursor movement).

See: https://github.com/PowerShell/GraphicalTools/issues/131

This could be fixed in ocgv’s input parsing to at least strip out the sequences. But what users really want is for formatting (like color) to be honored and displayed.

Related: https://github.com/migueldeicaza/gui.cs/issues/17

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

2reactions
tznindcommented, Sep 7, 2022

There are 2 seperate user stories being discussed here

  • How can I easily add color to my Terminal.Gui controls with as little effort as possible
  • I have console output with ANSI escape codes in it that I got from another process. Can Terminal.Gui use these to render color in a View?

Easily Add Color

The proposed solution for the story is to adopt the same markup as Spectre Console. It is a very simple markup which is easy to pick up, even for beginner programmers. Implementing it would be a big task but could start small (e.g. with Label). The feature should be ‘opt in’ so that it doesn’t break backwards compatibility. Finally we would need methods like EscapeMarkup

Handling Process outputs that already contain ANSI

This is more complicated and would require writting a parser such as this one in teds-terminal. As highlighted by @migueldeicaza , this may not belong in Terminal.Gui itself and might be better as a standalone library.

Seeing as this library runs and renders within the terminal, I would expect ANSI escape support.

@KieranDevvs given we don’t currently have an ANSI parser and are unlikely to soon. You might want to consider starting by stripping the ANSI codes? There is a post on Stack Overflow that contains some Regex that will do that (example is in Python but the regex patterns are the interesting bit).

Alternatively you could use the Regex to detect which bits of output have the color markups you are looking to parse and implement the highlighting using an approach similar to the syntax highlighting Scenario

https://github.com/gui-cs/Terminal.Gui/blob/d368215e0799b37c6e2b11d1770021cbe61bab2a/UICatalog/Scenarios/SyntaxHighlighting.cs#L153-L166

The pseudocode for that might be something like:

 // Read input from process
 // Foreach escape code
     // record location in string (after removing the escape sequence)
 // Set TextView.Text to the stripped string

Then override the ColorNormal method to set the appropriate color.

2reactions
tigcommented, Feb 10, 2021

Renamed the issue to make this customer centric.

As a developer, I want to richly format output w/in terminal.gui apps. For example, within a ListView, I want some elements to be red and some to be blue.

That is not supported today. We could implement a new model for formatting, or, we could simply leverage ANSI escape sequences.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leverage ANSI escape sequences as the mechanism for ...
As a developer, I want to richly format output w/in terminal.gui apps. For example, within a ListView, I want some elements to be...
Read more >
Write better looking console applications using ANSI escape ...
Write better looking console applications using ANSI escape codes · Figure 1: A simple GUI with a centered main menu and a custom...
Read more >
Build your own Command Line with ANSI escape codes
Rich Text. The most basic Ansi escape codes are those involved in rendering text. These let you add decorations like Colors, Background Colors ......
Read more >
Better terminal output from Ink with ANSI escape codes
ANSI escape codes are an in-band signaling mechanism, meaning the commands are sent as a part of the normal stream of text being...
Read more >
Console Virtual Terminal Sequences
Virtual terminal sequences are control character sequences that can control cursor movement, color/font mode, and other operations when ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found