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

Add support for non-blocking IO mode to OS.execute_with_pipe. #94434

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Jul 16, 2024

Adds an extra argument to the OS.execute_with_pipe to allow pipes it creates to work in non-blocking mode.

e.g., a super primitive terminal emulation can be done without threads:

func _ready() -> void:
	if OS.get_name() == "Windows":
		pipe = OS.execute_with_pipe("cmd.exe", [], false)
	else:
		pipe = OS.execute_with_pipe("/bin/zsh", [], false)

func _process(delta: float) -> void:
	if pipe["stdio"].is_open():
		var buffer = PackedByteArray()
		while true:
			buffer.append_array(pipe["stdio"].get_buffer(2048))
			if pipe["stdio"].get_error() != OK:
				break;

		if !buffer.is_empty():
			$TextEdit.text += buffer.get_string_from_utf8()

func _on_line_edit_text_submitted(new_text: String) -> void:
	if pipe["stdio"].is_open() and !new_text.is_empty():
		pipe["stdio"].store_buffer((new_text + "\n").to_utf8_buffer())
		$LineEdit.text = ""

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Sep 6, 2024
@bruvzg bruvzg requested review from a team as code owners September 6, 2024 11:19
@akien-mga akien-mga merged commit 8aae31b into godotengine:master Sep 6, 2024
20 checks passed
@akien-mga
Copy link
Member

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.

3 participants