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

[OS] Add functions to determine standard I/O device type. #91201

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Apr 26, 2024

  • Adds methods to check std handle type.
  • Adds console wrapper detection (on Windows) to prevent non-functional stdin reads when not using wrapper (will return "invalid" type).
  • Adds buffer size argument to the stdio read method.
  • Adds method to read stdin as raw data instead of UTF-8 encoded string.

Required to filter escape sequences for the redirected streams (a filter similar to #90900, or probably can be filtered directly in the rich_print to avoid extra regex, will add it later as a separate PR).

Production edit (keywords for easier searching): TTY, CLI, terminal

@Calinou
Copy link
Member

Calinou commented Apr 26, 2024

or probably can be filtered directly in the rich_print to avoid extra regex, will add it later).

Note that unlike the regex, this approach will not work with manually inserted ANSI escape sequences in print() or printraw(). It's probably not critical but it's something to consider.

@bruvzg
Copy link
Member Author

bruvzg commented Apr 28, 2024

filter similar to #90900

In this case, adding regex will not be straightforward. StdLogger is created before ClassDB init, and RegEx class can't be created before it's registered in ClassDB.

@bruvzg bruvzg force-pushed the con_type branch 5 times, most recently from f0c9469 to c9a0a7c Compare May 3, 2024 09:28
@bruvzg bruvzg marked this pull request as ready for review May 15, 2024 08:29
@bruvzg bruvzg requested review from a team as code owners May 15, 2024 08:29
Comment on lines +160 to +166
static String exe_renames[] = {
".console.exe",
"_console.exe",
" console.exe",
"console.exe",
String(),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also support -console.exe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not supported by wrapper, be I guess could be added.

static PCWSTR exe_renames[] = {
L".console.exe",
L"_console.exe",
L" console.exe",
L"console.exe",
nullptr,
};

doc/classes/OS.xml Outdated Show resolved Hide resolved
doc/classes/OS.xml Outdated Show resolved Hide resolved
doc/classes/OS.xml Outdated Show resolved Hide resolved
doc/classes/OS.xml Outdated Show resolved Hide resolved
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

Test 1

bin/godot.linuxbsd.editor.x86_64 --path ~/Documents/Godot/test_pr_91201 < out.txt > out2.txt

Screenshot_20241106_121521

Test 2

bin/godot.linuxbsd.editor.x86_64 --path ~/Documents/Godot/test_pr_91201 < out.txt &> out3.txt

Screenshot_20241106_121535

Test 3

bin/godot.linuxbsd.editor.x86_64 --path ~/Documents/Godot/test_pr_91201 < out.txt

Screenshot_20241106_121549

core/core_bind.cpp Show resolved Hide resolved
doc/classes/OS.xml Outdated Show resolved Hide resolved
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me.

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Nov 12, 2024
@Repiteo Repiteo merged commit 179321a into godotengine:master Nov 12, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 12, 2024

Thanks!

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

Successfully merging this pull request may close these issues.

5 participants