mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-24 18:20:25 +01:00
feat(pty): parse env so it can be used with fork
Adds method to convert env from a Dictionary to a PackedStringArray so it can be used with fork(). Consider making env a PackedStringArray to begin with.
This commit is contained in:
parent
8cd11fdae6
commit
ee920a45fd
2 changed files with 14 additions and 1 deletions
|
@ -111,7 +111,7 @@ Error PTY::fork(const String &file, const PackedStringArray &args, const String
|
|||
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
String helper_path = ProjectSettings::get_singleton()->globalize_path("res://addons/godot_xterm/native/bin/spawn-helper");
|
||||
result = PTYUnix::fork(fork_file, args, PackedStringArray(), cwd, cols, rows, -1, -1, true, helper_path, Callable(this, "_on_exit"));
|
||||
result = PTYUnix::fork(fork_file, args, _parse_env(fork_env), cwd, cols, rows, -1, -1, true, helper_path, Callable(this, "_on_exit"));
|
||||
#endif
|
||||
|
||||
Error err = static_cast<Error>((int)result["error"]);
|
||||
|
@ -278,6 +278,18 @@ Dictionary PTY::_get_fork_env() const {
|
|||
return os_env;
|
||||
}
|
||||
|
||||
PackedStringArray PTY::_parse_env(const Dictionary &env) const {
|
||||
PackedStringArray parsed_env;
|
||||
PackedStringArray keys = PackedStringArray(env.keys());
|
||||
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
String key = keys[i];
|
||||
parsed_env.push_back(key + "=" + String(env[key]));
|
||||
}
|
||||
|
||||
return parsed_env;
|
||||
}
|
||||
|
||||
void PTY::_on_exit(int exit_code, int exit_signal) {
|
||||
emit_signal(StringName("exited"), exit_code, exit_signal);
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ namespace godot
|
|||
|
||||
String _get_fork_file(const String &file) const;
|
||||
Dictionary _get_fork_env() const;
|
||||
PackedStringArray _parse_env(const Dictionary &env) const;
|
||||
void _on_exit(int exit_code, int exit_signal);
|
||||
void _close();
|
||||
|
||||
|
|
Loading…
Reference in a new issue