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

Suggestion: Ignore special control characters / virtual terminal sequences in row length calculation #38

Open
Decimation opened this issue May 6, 2022 · 4 comments

Comments

@Decimation
Copy link

Decimation commented May 6, 2022

Description

Special control characters such as ANSI escape codes are included in calculation of row length (which is determined by string length). This results in table rows appearing larger than they should be.

Example:

This is used for the row (outlined); the ANSI escape sequence is red
yWxj5WcF8h_2022-05-06_(03h47m50s)

This results in the following output:

c1hBYeWyNq_2022-05-06_(03h49m30s)
(The affected row is red)

This is because the length of the ANSI escape characters in the example is 7, which results in 7 additional characters in the row cell:

VsDebugConsole_2LEKSjhfj0

Possible Solution

A possible solution would be using regex to filter such characters and escape sequences from the row content string, and using the resulting string length to determine the row length.

See Console virtual terminal sequences

@Decimation Decimation changed the title Suggestion: Ignore special control characters / virtual terminal sequences Suggestion: Ignore special control characters / virtual terminal sequences in row length calculation May 6, 2022
@minhhungit
Copy link
Owner

thank you @Decimation I will check it when I have more time, sorry quite busy these days

@minhhungit
Copy link
Owner

@Decimation can you pls give me a sample of code so I can reproduce it

@Decimation
Copy link
Author

@Decimation can you pls give me a sample of code so I can reproduce it

The first picture in the OP contains one but I'll send a more concrete example later when possible

@mchudinov
Copy link

mchudinov commented Dec 3, 2023

The issue makes ugly the to colorize output, because color characters in console are calculated as table width.
For example showing negative numbers in RED

  .WithFormatter(4, text =>
  {
      if (Int32.Parse(text.ToString()) < 0)
      {
          return text.ToString().Pastel(Color.Red);
      }
      return text.ToString();
  })

Is shown like this

 | Days                       | 
-|----------------------------| 
 | -811  |                      
 | -553  |                      
 | -546  |                      

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants