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

Option/command to clear system console #28632

Closed
ChipChance opened this issue May 3, 2019 · 11 comments
Closed

Option/command to clear system console #28632

ChipChance opened this issue May 3, 2019 · 11 comments

Comments

@ChipChance
Copy link

Please create a GDScript command that will clear the console window. (NOT just the OUTPUT window.)

Preferably something like console.clear().

Also, being able to re-print a line (so you can print "Loading... 5%" then (on the same line:) "Loading... 7%" etc... that would be cool too.

Please consider.

Thanks -

  • Mike
@bojidar-bg
Copy link
Contributor

Printing stuff on the same line is usually accomplished (under linux at least) via \r, which is supposed to return the cursor to the start of the line. Not sure if Godot's built in Output window supports that though.

@akien-mga akien-mga changed the title Feature Request: Clear Console Option/command to clear system console May 3, 2019
@akien-mga
Copy link
Member

This is a lot more complex than you would imagine, there are many different terminals and OSes and there is no builtin C/C++ system to clear their output. To achieve this, Godot would have to be turned into a terminal-aware application binding to libraries such as ncurses or terminfo, just for this small facility.

Instead, I'd suggest that someone makes a plugin for the asset library that can call OS.execute("clear") on Unix and OS.execute("cls") on Windows.

@Calinou
Copy link
Member

Calinou commented May 3, 2019

This can be done in GDScript using ANSI escape codes:

var escape := PoolByteArray([0x1b]).get_string_from_ascii()
print(escape + "[2J" + escape + "[;H" + "This text will be printed at the top.")

However, this won't work on Windows (until we declare Godot to be ANSI code-compatible on Windows 10), and it won't impact the editor's Output tab (which will print [2J[;HThis text will be printed at the top.).

@KoBeWi
Copy link
Member

KoBeWi commented May 27, 2020

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

@JonathanPicques
Copy link

This can be done in GDScript using ANSI escape codes:

var escape := PoolByteArray([0x1b]).get_string_from_ascii()
print(escape + "[2J" + escape + "[;H" + "This text will be printed at the top.")

However, this won't work on Windows (until we declare Godot to be ANSI code-compatible on Windows 10), and it won't impact the editor's Output tab (which will print [2J[;HThis text will be printed at the top.).

On Windows, you can set the terminal to interpret ANSI by opening regedit and adding a "VirtualTerminalLevel" DWORD with a value of 1 under HKEY_CURRENT_USER\Console

@Calinou
Copy link
Member

Calinou commented Jun 21, 2021

On Windows, you can set the terminal to interpret ANSI by opening regedit and adding a "VirtualTerminalLevel" DWORD with a value of 1 under HKEY_CURRENT_USER\Console

See also #44118 which will enable ANSI code processing by default on Windows 10.

@DreamHollow
Copy link

This can be done in GDScript using ANSI escape codes:

var escape := PoolByteArray([0x1b]).get_string_from_ascii()
print(escape + "[2J" + escape + "[;H" + "This text will be printed at the top.")

However, this won't work on Windows (until we declare Godot to be ANSI code-compatible on Windows 10), and it won't impact the editor's Output tab (which will print [2J[;HThis text will be printed at the top.).

On Windows, you can set the terminal to interpret ANSI by opening regedit and adding a "VirtualTerminalLevel" DWORD with a value of 1 under HKEY_CURRENT_USER\Console

This is terrible advice. I tried this and now every version of GODOT that I try to run has a non-functional Print function.

Please do not edit the registry for any reason unless required.

@Calinou
Copy link
Member

Calinou commented Apr 16, 2022

See also #44118, which would enable Windows support for using ANSI escape codes (including the one to clear the console).

#44118 doesn't fallback for Windows versions older than 10 yet, but if you only need to support Windows 10 and later, you could cherry-pick it and build the engine and Windows export templates from source.

@RPicster
Copy link
Contributor

RPicster commented Apr 4, 2024

Sorry if this is stupid, I have no clue how to expose a method in GDScript.
But wouldn't it be enough to expose this method here as a GDScript method?

void EditorLog::_clear_request() {

@Calinou
Copy link
Member

Calinou commented Apr 4, 2024

Sorry if this is stupid, I have no clue how to expose a method in GDScript. But wouldn't it be enough to expose this method here as a GDScript method?

void EditorLog::_clear_request() {

This method could be exposed to editor plugins, but it only clears the editor Output panel, not terminal console output.

@RPicster
Copy link
Contributor

RPicster commented Apr 4, 2024

Sorry if this is stupid, I have no clue how to expose a method in GDScript. But wouldn't it be enough to expose this method here as a GDScript method?

void EditorLog::_clear_request() {

This method could be exposed to editor plugins, but it only clears the editor Output panel, not terminal console output.

Could it also be done in a way to make it callable with something simple as clear_console in the same way print can be used.
I had the need in the past and I just watched this video which brought back this memory to check in here again:
https://www.youtube.com/watch?v=NSaczr74LzU

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

No branches or pull requests

9 participants