Skip to content

using Ctrl + L to clear console sometimes leaves behind old output #8428

Closed

Description

@kevinushey

System details

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:

Screen Shot 2020-11-18 at 10 51 03 AM

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).

Screen Shot 2020-11-18 at 10 50 07 AM

Describe the behavior you expected

Ctrl + L should always clear the console.


  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting a RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. jmcphers commented on Nov 18, 2020

    @jmcphers
    Member

    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.

  2. added this to the v1.4 milestone on Nov 18, 2020
  3. kevinushey commented on Nov 23, 2020

    @kevinushey
    CollaboratorAuthor

    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-on

    Limit Console Output [off]

    limit-console-output-off

  4. kevinushey commented on Nov 23, 2020

    @kevinushey
    CollaboratorAuthor

    Here's a somewhat more minimal example:

    lines <- c(
      "  \r   checking for file ‘/private/tmp/Rtmpd4ZGIv/remotes17afffd3ef4/rstudio-plumber-c39ae52/DESCRIPTION’ ...\r  \r",
      "\u001b[32m✓\u001b[39m  \u001b[38;5;247mchecking for file ‘/private/tmp/Rtmpd4ZGIv/remotes17afffd3ef4/rstudio-plumber-c39ae52/DESCRIPTION’\u001b[39m\u001b[36m\u001b[39m\n\r",
      "  \r\u001b[32m✓\u001b[39m  \u001b[38;5;247mchecking DESCRIPTION meta-information\u001b[39m\u001b[36m\u001b[39m\n\r",
      "  \r\u001b[32m✓\u001b[39m  \u001b[38;5;247mchecking DESCRIPTION meta-information\u001b[39m\u001b[36m\u001b[39m\n\r"
    )
    
    cat(lines, sep = "")
    

    Limit Console Output [on]

    Screen Shot 2020-11-23 at 11 32 14 AM

    Limit Console Output [off]

    Screen Shot 2020-11-23 at 11 32 30 AM

  5. kevinushey commented on Nov 23, 2020

    @kevinushey
    CollaboratorAuthor

    It looks like this might be caused by lines that start with \r? For example, if I execute this code line-by-line:

    cat("\rHello\r")
    1 + 1
    

    Then, after I clear the console, I'm left with the line 1 + 1 in the console history:

    Screen Shot 2020-11-23 at 12 01 54 PM

    This "accumulates" for every time that pair of lines is executed; e.g.

    Screen Shot 2020-11-23 at 12 03 08 PM

  6. adamconroy commented on Nov 23, 2020

    @adamconroy
    Contributor

    Thanks for this repro. It was very sporadic for me so I was kind of using a shotgun approach for testing it.

  7. adamconroy commented on Nov 23, 2020

    @adamconroy
    Contributor

    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.

  8. kevinushey commented on Nov 23, 2020

    @kevinushey
    CollaboratorAuthor

    If it's relevant, this was with me testing with a dev. build on macOS 10.11.1 -- perhaps some part is environment-specific?

  9. adamconroy commented on Nov 23, 2020

    @adamconroy
    Contributor

    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.

  10. adamconroy commented on Dec 1, 2020

    @adamconroy
    Contributor

    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.

  11. GegznaV commented on Dec 2, 2020

    @GegznaV

    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)

    rs-bug--does-not-clear

    I use Windows 10, RStudio 1.4.1071, R 4.0.3.

  12. adamconroy commented on Dec 2, 2020

    @adamconroy
    Contributor

    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.

  13. kfeinauer commented on Dec 3, 2020

    @kfeinauer
    Contributor

    Looks like this is working great on 1.4.1075.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions