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

Garbled text / buffering issue with fast updates and colored text #4777

Closed
jimhester opened this issue May 9, 2019 · 3 comments
Closed

Garbled text / buffering issue with fast updates and colored text #4777

jimhester opened this issue May 9, 2019 · 3 comments
Assignees
Labels
Milestone

Comments

@jimhester
Copy link
Contributor

System details

RStudio Edition : Desktop
RStudio Version : 1.12.1335
OS Version      :  macOS Mojave
R Version       : 3.6

Steps to reproduce the problem

Run the following code in the RStudio console pane. The first two show_progress() calls should work as expected, the third generates garbled text.

library(crayon)
library(progress)

show_progress <- function(format, size, width = 80) {
  pb <- progress_bar$new(total = size, format = format, width = width)
  for (i in 1:size) {
    pb$tick()
    Sys.sleep(1 / size)
  }
}

# Works with colors and 1 ms updates
show_progress(":bar " %+% green(":rate"), 1000)

# Works without colors and .1 ms updates
show_progress(":bar " %+% ":rate", 10000)

# Doesn't work with colors and .1 ms updates
show_progress(":bar " %+% green(":rate"), 10000)

The same code works fine in a terminal outside of RStudio and even in a R session started in the RStudio terminal pane.

My guess is there is some sort of buffering going on in the RStudio console that is messing up the updates when they happen quickly enough.

jimhester added a commit to tidyverse/vroom that referenced this issue May 9, 2019
This alone unfortunately does not fix
rstudio/rstudio#4777
@gtritchie gtritchie self-assigned this May 9, 2019
@gtritchie gtritchie added this to the v1.3 milestone May 9, 2019
@gtritchie
Copy link
Member

This is a bug in the IDE's handling of carriage returns with a line containing different colors, and is triggered by the progress-bar output being inconsistent in length (the part before the colored text):

For example, here's a subset of what is being written to the console in the third scenario, notice the difference in output length; every-time this happens the console messes up and doesn't overwrite the previous output.

"====>----------------------------------------------------------------- "
"====>------------------------------------------------------------------ "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>----------------------------------------------------------------- "
"====>-------------------------------------------------------------------- "
"====>----------------------------------------------------------------- "

@gtritchie gtritchie modified the milestones: v1.3, v1.2-patch May 12, 2019
gtritchie added a commit that referenced this issue May 12, 2019
…olor ranges

Fixes #4777

I think this is reasonably safe to take for 1.2-patch. This code is finicky but does have good unit test coverage.
@gtritchie
Copy link
Member

Fixed in 1.2-patch via 0be83fa.

@ronblum
Copy link
Contributor

ronblum commented Jun 3, 2019

Verified in RStudio Desktop 1.2.1526 on Windows 10.

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

No branches or pull requests

3 participants