Skip to content

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

Merged
akien-mga merged 1 commit into
godotengine:masterfrom
bruvzg:nonblock_pipes
Sep 6, 2024
Merged

Add support for non-blocking IO mode to OS.execute_with_pipe.#94434
akien-mga merged 1 commit into
godotengine:masterfrom
bruvzg:nonblock_pipes

Conversation

@bruvzg

@bruvzg bruvzg commented Jul 16, 2024

Copy link
Copy Markdown
Member

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 = ""

Comment thread doc/classes/OS.xml Outdated
Comment thread doc/classes/OS.xml Outdated
@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
@akien-mga

Copy link
Copy Markdown
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