jedib0t / go-pretty

Table-writer and more in golang!
MIT License
3.02k stars 119 forks source link

Why carriage return character '\r' is dropped when rendering? #284

Closed jievince closed 10 months ago

jievince commented 11 months ago

Is your feature request related to a problem? Please describe.

I am using go-pretty library to render a result set for a CLI in linux environment. I found that go-pretty drops the \r but the expected behavior is to move the cursor to the head of a line.

For example:

> return "abc\rde"
+---------+
| "abcde" |
+---------+
| "abcde" |
+---------+

"abc\rde" is printed as "abcde" but the expected is "dec"

The related code in go-pretty:

strings.ReplaceAll(colStr, "\r", "")

Additional context

I tested the effect of the above string print on the linux machine, C++, golang and python, and it was all the "dec" I expected.

jedib0t commented 11 months ago

Hmmm. The reason for the behavior was that I didn't want to deal with the complexity of dealing with \r when I initially created this library. Will try to fix it in the near future. If you want to submit a fix, it'd be awesome too.

jedib0t commented 10 months ago

Hey @jievince https://github.com/jedib0t/go-pretty/releases/tag/v6.5.2 has the fix for this issue.

jievince commented 10 months ago

Hey @jievince https://github.com/jedib0t/go-pretty/releases/tag/v6.5.2 has the fix for this issue.

Hi @jedib0t , thanks for your work. I upgrade to v6.5.2 just now but the result seems still not right:

> return "abc\rde"
+-----+
| de" |
+-----+
| de" |
+-----+

It should return "dec" not "de".

I have commented in your pr: https://github.com/jedib0t/go-pretty/commit/9755509e525fe5f78ca64fbdbf85087e082387d3#r136463617

jedib0t commented 10 months ago

Hey @jievince please try the latest code on the main branch. Will cut a tag once you've verified.

jedib0t commented 9 months ago

Cut a tag anyway: https://github.com/jedib0t/go-pretty/releases/tag/v6.5.3

jievince commented 9 months ago

Hey @jievince please try the latest code on the main branch. Will cut a tag once you've verified.

Cut a tag anyway: https://github.com/jedib0t/go-pretty/releases/tag/v6.5.3

Hi @jedib0t, I tried v6.5.3 and it works right now! Thanks a lot!