You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
using Ctrl + L to clear console sometimes leaves behind old output #8428
RStudio Edition : Desktop
RStudio Version : 1.4.1043
OS Version : macOS 11.0.1
R Version : 4.0.3
Steps to reproduce the problem
First, ensure that "Limit visible console output" is set to on:
Restart the IDE in case you needed to toggle this from off to on. Then, do something that generates a lot of console output. In my case, I did:
remotes::install_github("rstudio/plumber")
Then, press Ctrl + L to clear the console.
Describe the problem in detail
Some console output is left behind and will not be cleared. Also note how some newlines are lost in the 'saved' output (separate lines get collapsed into a single, wrapped line).
I'm surprised that this setting isn't on by default (and will open a thread with @mikebessuille and @adamconroy on the subject); if we decide to enable it by default for 1.4 we will want to fix this.
I strangely am not seeing the same exact symptoms as you with that code. I am getting this error, however:
Error: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
at Node.$insertBefore (rstudio-0.js:29065)
at VirtualConsole_1_g$.VirtualConsole.insertText
It would make sense due to the way I rejigger the divs but it's very odd that I don't see the remnant items that you do. Will need verification that the fix I'm working on also fixes your issue.
Kevin managed to find test cases that exposed, at minimum, 3 bugs. This ticket has turned into much more than it's seemed. I think it'll be very good for the health of this feature to have all these fixed but it's led me down some rabbit holes.
[fixed ✓]1. The original issue: left over junk in the console, even upon a clear. My initial approach was assuming that it was just some junk left over from the virtualconsole.js initialization. It doesn't init until the first time you write to the console so, due to some race conditions, you could have some non-virtualconsole.js content in there originally. When it inits we move all that content over and I assumed I just had to clean some stuff up in there.
So what we try to do with virtualconsole.js is keep it in sync with all the other moving parts (VirtualConsole, ConsoleOutputWriter, the backend R session, the C++ state). This is not easy and it's compounded by many moving parts on the frontend modifying the console out of the void sometimes (see ensureStartingOnNewLine()). It turns out that a lot of weirdness with newlines [sometimes not] showing up where they should/shouldn't be was because the frontend is modifying it in certain places outside of the main R session submit() functions.
I've added cleanup functions and my own ensureStartingOnNewLine (which fixes some weird prompt stuff also) to keep these more in sync but it adds complexity I don't like. There is still an issue of some excess prompts related to carriage returns but they clean up with control+L now and it's an improvement over what's there at the moment.
[wont fix]2. Sourcing one line at a time versus sourcing multiple lines at once gets different output. I was testing what looked like a bug with the virtualconsole.js functionality running the Hello/Bye/1+1 example both as single sourced and multiple sourced lines but was worried when I saw it with the feature turned off. Oh no, did I break something fundamental? I rushed to my laptop with 1.3 on it and tested there. Whew, not a regression but a bug/quirk we've had for a while.
When running cat("\Hello\rBye") by itself you correctly get the output "Byelo". When you run that line and then 1+1 after by itself everything is fine. When you select both lines and run them you get "Bye1+1\n[1] 2", which is different output than if you sourced the full document into R. Perhaps this is expected quirky functionality in RStudio but it's not what I would have expected as a user.
[in progress]3. Unicode actin' all crazy. I finally just narrowed it down this morning. I was breaking down the installation progress update example to try to figure out exactly what was causing it to be so weird. I was originally assuming there was something fundamentally wrong with how I was [potentially not] staying in sync with with the cursor_ that allows us to overwrite ranges for things like the carriage return. After a lot of debug logging show that the cursor_ is identical with the feature on/off I moved to building up from a simple example. It turned out the inflection point that made it super broken was the checkmarks/unicode characters.
It's some confluence of the unicode and the carriage returns that makes them overrun the buckets (which is why they weren't cleaned up). It is possible that unicode is not the only possible cause but it's the biggest clue that I have. With more concrete cause and effect I can start breaking this down and finding the exact culprit. Once it's found I'm confident that the fix won't be overly complex.
I was creating a reprex with an add-in when an error occurred. After that, I'm not able to clean some contents in the console (see the gif). Is it the same issue discussed in this thread? (I do not use Ctrl + L)
Activity
jmcphers commentedon Nov 18, 2020
I'm surprised that this setting isn't on by default (and will open a thread with @mikebessuille and @adamconroy on the subject); if we decide to enable it by default for 1.4 we will want to fix this.
kevinushey commentedon Nov 23, 2020
There's definitely something weird happening with console output here. Perhaps ANSI escapes aren't being properly handled? Compare:
Limit Console Output [on]
Limit Console Output [off]
kevinushey commentedon Nov 23, 2020
Here's a somewhat more minimal example:
Limit Console Output [on]
Limit Console Output [off]
kevinushey commentedon Nov 23, 2020
It looks like this might be caused by lines that start with
\r? For example, if I execute this code line-by-line:Then, after I clear the console, I'm left with the line
1 + 1in the console history:This "accumulates" for every time that pair of lines is executed; e.g.
adamconroy commentedon Nov 23, 2020
Thanks for this repro. It was very sporadic for me so I was kind of using a shotgun approach for testing it.
adamconroy commentedon Nov 23, 2020
I strangely am not seeing the same exact symptoms as you with that code. I am getting this error, however:
It would make sense due to the way I rejigger the divs but it's very odd that I don't see the remnant items that you do. Will need verification that the fix I'm working on also fixes your issue.
kevinushey commentedon Nov 23, 2020
If it's relevant, this was with me testing with a dev. build on macOS 10.11.1 -- perhaps some part is environment-specific?
adamconroy commentedon Nov 23, 2020
Just tested on my Mac and that does seem to be the case. It acts different on my Windows dev build. SIGH. Ok at least I can repro.
adamconroy commentedon Dec 1, 2020
Just checking in with all my findings:
Kevin managed to find test cases that exposed, at minimum, 3 bugs. This ticket has turned into much more than it's seemed. I think it'll be very good for the health of this feature to have all these fixed but it's led me down some rabbit holes.
[fixed ✓]1. The original issue: left over junk in the console, even upon a clear. My initial approach was assuming that it was just some junk left over from the virtualconsole.js initialization. It doesn't init until the first time you write to the console so, due to some race conditions, you could have some non-virtualconsole.js content in there originally. When it inits we move all that content over and I assumed I just had to clean some stuff up in there.
So what we try to do with virtualconsole.js is keep it in sync with all the other moving parts (VirtualConsole, ConsoleOutputWriter, the backend R session, the C++ state). This is not easy and it's compounded by many moving parts on the frontend modifying the console out of the void sometimes (see ensureStartingOnNewLine()). It turns out that a lot of weirdness with newlines [sometimes not] showing up where they should/shouldn't be was because the frontend is modifying it in certain places outside of the main R session submit() functions.
I've added cleanup functions and my own ensureStartingOnNewLine (which fixes some weird prompt stuff also) to keep these more in sync but it adds complexity I don't like. There is still an issue of some excess prompts related to carriage returns but they clean up with control+L now and it's an improvement over what's there at the moment.
[wont fix]2. Sourcing one line at a time versus sourcing multiple lines at once gets different output. I was testing what looked like a bug with the virtualconsole.js functionality running the Hello/Bye/1+1 example both as single sourced and multiple sourced lines but was worried when I saw it with the feature turned off. Oh no, did I break something fundamental? I rushed to my laptop with 1.3 on it and tested there. Whew, not a regression but a bug/quirk we've had for a while.
When running cat("\Hello\rBye") by itself you correctly get the output "Byelo". When you run that line and then 1+1 after by itself everything is fine. When you select both lines and run them you get "Bye1+1\n[1] 2", which is different output than if you sourced the full document into R. Perhaps this is expected quirky functionality in RStudio but it's not what I would have expected as a user.
[in progress]3. Unicode actin' all crazy. I finally just narrowed it down this morning. I was breaking down the installation progress update example to try to figure out exactly what was causing it to be so weird. I was originally assuming there was something fundamentally wrong with how I was [potentially not] staying in sync with with the cursor_ that allows us to overwrite ranges for things like the carriage return. After a lot of debug logging show that the cursor_ is identical with the feature on/off I moved to building up from a simple example. It turned out the inflection point that made it super broken was the checkmarks/unicode characters.
It's some confluence of the unicode and the carriage returns that makes them overrun the buckets (which is why they weren't cleaned up). It is possible that unicode is not the only possible cause but it's the biggest clue that I have. With more concrete cause and effect I can start breaking this down and finding the exact culprit. Once it's found I'm confident that the fix won't be overly complex.
GegznaV commentedon Dec 2, 2020
I was creating a reprex with an add-in when an error occurred. After that, I'm not able to clean some contents in the console (see the gif). Is it the same issue discussed in this thread? (I do not use Ctrl + L)
I use Windows 10, RStudio 1.4.1071, R 4.0.3.
adamconroy commentedon Dec 2, 2020
That does appear to be it! It should be fixed in the PR I opened a few hours ago so it'll be in a daily soon. Thanks for the report.
kfeinauer commentedon Dec 3, 2020
Looks like this is working great on 1.4.1075.