From 5ff4ca6c28e247c6d30e53eff5eda658c66085db Mon Sep 17 00:00:00 2001 From: blinry Date: Fri, 8 Sep 2023 15:23:48 +0200 Subject: [PATCH] Try to fix web-shell when called from Godot --- scenes/game.gd | 1 + scenes/helpers.gd | 1 + scenes/repository.gd | 1 + scenes/shell.gd | 11 ++++------- scenes/shell_command.gd | 2 +- scenes/terminal.gd | 1 - web/web-shell/script.js | 5 +++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scenes/game.gd b/scenes/game.gd index 86576b0..06cbd6c 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -108,6 +108,7 @@ func load_state(): # filename is relative to the tmp directory! func create_file_in_game_env(filename, content): + print("CD-ing to tmp in create_file") await global_shell.cd(tmp_prefix) # Quoted HERE doc doesn't do any substitutions inside. await global_shell.run("cat > '%s' <<'HEREHEREHERE'\n%s\nHEREHEREHERE" % [filename, content]) diff --git a/scenes/helpers.gd b/scenes/helpers.gd index e9b8ed9..cf37d72 100644 --- a/scenes/helpers.gd +++ b/scenes/helpers.gd @@ -102,6 +102,7 @@ func careful_delete(path_inside): if path_inside.substr(0,expected_prefix.length()) != expected_prefix: helpers.crash("Refusing to delete directory %s that does not start with %s" % [path_inside, expected_prefix]) else: + print("CD-ing to tmp in careful_delete") await game.global_shell.cd(game.tmp_prefix) await game.global_shell.run("rm -rf '%s'" % path_inside) diff --git a/scenes/repository.gd b/scenes/repository.gd index 8b8cbd5..2f1ba54 100644 --- a/scenes/repository.gd +++ b/scenes/repository.gd @@ -71,6 +71,7 @@ func set_path(new_path): if path_node: path_node.text = path if new_path != "": + print("CD-ing repo shell to " + new_path) shell.cd(new_path) for o in objects.values(): o.queue_free() diff --git a/scenes/shell.gd b/scenes/shell.gd index b6f7d2e..55a4157 100644 --- a/scenes/shell.gd +++ b/scenes/shell.gd @@ -20,14 +20,13 @@ func cd(dir): # Run a shell command given as a string. Run this if you're interested in the # output of the command. func run(command, crash_on_fail=true): - print("run " + command) var shell_command = ShellCommand.new() shell_command.command = command shell_command.crash_on_fail = crash_on_fail run_async_thread(shell_command) await shell_command.done - print("output in run (" +command+ "): " + shell_command.output) + print("output of (" +command+ "): >>" + shell_command.output + "<<") exit_code = shell_command.exit_code return shell_command.output @@ -39,7 +38,6 @@ func run_async_web(command, crash_on_fail=true): return shell_command func run_async_thread(shell_command): - print("in async thread " + shell_command.command) var debug = false var command = shell_command.command @@ -58,6 +56,8 @@ func run_async_thread(shell_command): hacky_command += "export PATH=\'"+game.tmp_prefix+":'\"$PATH\";" hacky_command += "cd '%s' || exit 1;" % _cwd hacky_command += command + + print("running >>" + hacky_command + "<<") var result if _os == "Linux" or _os == "OSX": @@ -95,7 +95,7 @@ func run_async_thread(shell_command): #print(hacky_command) shell_command.js_callback = JavaScriptBridge.create_callback(Callable(shell_command, "callback")) - web_shell.run_in_vm(hacky_command).then(shell_command.js_callback) + web_shell.run(hacky_command).then(shell_command.js_callback) else: helpers.crash("Unimplemented OS: %s" % _os) @@ -115,9 +115,6 @@ func _shell_binary(): else: helpers.crash("Unsupported OS: %s" % _os) -func callback(args): - print(args) - func read_from(c): var total_available = c.get_available_bytes() print(str(total_available)+" bytes available") diff --git a/scenes/shell_command.gd b/scenes/shell_command.gd index a8eabe8..f3eba0f 100644 --- a/scenes/shell_command.gd +++ b/scenes/shell_command.gd @@ -16,7 +16,7 @@ func _unused(): func callback(_output): #print(_output) - print(_output[0]) output = _output[0] + print("output of async command (" + command + "): >>"+output+"<<" ) exit_code = 0 emit_signal("done") diff --git a/scenes/terminal.gd b/scenes/terminal.gd index 8be80a9..29c919c 100644 --- a/scenes/terminal.gd +++ b/scenes/terminal.gd @@ -90,7 +90,6 @@ func send_command(command): shell.cd(repository.path) - print("running " + command) var cmd = shell.run_async_web(command, false) await cmd.done call_deferred("command_done", cmd) diff --git a/web/web-shell/script.js b/web/web-shell/script.js index 1257e3c..5fc765d 100644 --- a/web/web-shell/script.js +++ b/web/web-shell/script.js @@ -112,9 +112,10 @@ function boot() { emulator = window["emulator"] = new V86Starter(config) // Wait for the emulator to start, then resolve the promise. - var interval = setInterval(() => { + var interval = setInterval(async () => { if (emulator.is_running()) { - run("PS1='# '") + await run("PS1='# '") + await run("stty -echo") clearInterval(interval) resolve(true) }