这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@mrnugget
Copy link

The previous code assumed that it could count every byte in the current
line towards the length of the visible line.

With invisible characters, though, such as ASCII color codes, the count
was wrong and lead to the output to "climb up the screen" because the
overflow handling broke and too many newlines were emitted.

The fix here introduces a little "state switch" that flips on when we
come across an ESC character and turns to off when we come across 'm',
the character that terminates an ASCII color code.

Here is code to reproduce the issue: https://gist.github.com/mrnugget/f46caf71b214ae6b6ffa9880a0036003

Notably missing: not all characters that end an escape sequence are supported.

Before

before_fix

After

after_fix

The previous code assumed that it could count every byte in the current
line towards the length of the visible line.

With invisible characters, though, such as ASCII color codes, the count
was wrong and lead to the output to "climb up the screen" because the
overflow handling broke and too many newlines were emitted.

The fix here introduces a little "state switch" that flips on when we
come across an ESC character and turns to off when we come across 'm',
the character that terminates an ASCII color code.
mrnugget added a commit to sourcegraph/src-cli that referenced this pull request Jan 28, 2020
mrnugget added a commit to sourcegraph/src-cli that referenced this pull request Jan 28, 2020
* Update all dependencies

* Use forked version of uilive that includes fix for "climbing" screen

See gosuri/uilive#30 for context
scjohns pushed a commit to sourcegraph/src-cli that referenced this pull request Apr 24, 2023
* Update all dependencies

* Use forked version of uilive that includes fix for "climbing" screen

See gosuri/uilive#30 for context
@suutaku
Copy link

suutaku commented Jul 21, 2023

why not accept this PR

Adaendra added a commit to Adaendra/uilive that referenced this pull request Jul 22, 2023
@Adaendra
Copy link

Hi @mrnugget
To let you know, I've made a fork of this project as it hasn't been updated for years. Here is the link : https://github.com/Adaendra/uilive/tree/master
In the latest version by my side, I've included your MR.

@mrnugget
Copy link
Author

Thanks @Adaendra for letting me know! We've moved on to a different library in the past 2 years, so this is not needed, but appreciate it. (We're now using this output package we built ourselves).

I'm going to close the PR then.

@mrnugget mrnugget closed this Jul 23, 2023
DevStar411112 added a commit to DevStar411112/src-cli that referenced this pull request Oct 13, 2025
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

Successfully merging this pull request may close these issues.

3 participants