Skip to content

Console.Clear() does not clear buffers on macOS #8260

Closed

Description

@SimonCahill

Description

In a C# Console Application on .net 6 and higher, (unknown if this affects previous versions!), using Console.Clear() does not clear the terminal buffers.

Expected behaviour
According to the documentation:

Clears the console buffer and corresponding console window of display information.

I.e.: calls reset or an equivalent to printf "\033c" on non-Windows terminals.

In fact, calling Console.Clear() does not clear the buffers; the previously written text is still clearly visible when scrolling up.
Instead, it seems Console.Clear() flushes N lines to the buffer similar to scrolling down a page.

Configuration

This code has been run on .net6.0 and .net7.0 on macOS Ventura; I don't know if this bug affects previous versions.
Architecture: AARCH64.

I assume this bug affects many (if not all) of the non-Windows terminals. Haven't tested this theory however!

Other information

Screenshot of the behaviour:
image

The code executed when clear is typed to the console:

Console.Clear();

AFAICT there are no real (portable) workarounds, because the Console class does not provide access to the buffer on all platforms.

Using

Console.Write("\x1bc"); // the hex equivalent of "\033c" (octal)

also does not clear the console, instead it prints Ƽ on macOS.

Of course one could always write thousands upon thousands of lines of code in an attempt to run into the line limit and clear the terminal that way, but that's not a feasable solution.

Activity

  1. liveans commented on Mar 6, 2023

    @liveans

    Hello,

    This is duplicate of dotnet/runtime#28355.
    However, you can use this code as workaround:

    Console.Write("\f\u001bc\x1b[3J");
  2. added
    area-runtime
    on Mar 6, 2023
  3. SimonCahill commented on Mar 6, 2023

    @SimonCahill
    Author

    I'll give that a try, thanks!
    If that solves the issue, I'll close this one.

    This should really be fixed though.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions