diff --git a/.gitignore b/.gitignore index e63e8920..7a634ecc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ docsrc/_build docsrc/reference/generated examples/_old + +*-pygbag.??? +/build +/dist diff --git a/main.py b/main.py new file mode 100644 index 00000000..aa4c27ba --- /dev/null +++ b/main.py @@ -0,0 +1,40 @@ +import wcwidth +import termios +import tty +import numpy +import cv2 +import nurses_2 +os.chdir("examples/basic") + +# BASIC + +# OK +# buttons color_picker io_events.py line_plot.py menu.py +# optical_illusion.py progress_bar.py scroll_view.py slider.py +# subscription.py + +# NOT +# animations file_chooser easings image parallax.py split_layout.py +# tile.py video_in_terminal.py windows.py shadow_casting.py +# sliding_puzzle.py + +os.chdir("../advanced") + +# OK +# digital_clock.py doom_fire.py exploding_logo.py game_of_life.py +# isotiles.py navier_stokes.py pong.py reaction_diffusion.py + +# NOT +# exploding_logo_redux.py + +#? +# labyrinth.py snake.py + +for test in "tetris sph sandbox rubiks raycaster minesweeper connect4 cloth".split(' '): + if test in sys.argv: + sys.path.append(test) + exec(f"from {test} import __main__", globals(), globals()) + break + +# NOT +# tetris diff --git a/nurses_2/app.py b/nurses_2/app.py index 9b0c6589..af04f55e 100644 --- a/nurses_2/app.py +++ b/nurses_2/app.py @@ -137,16 +137,24 @@ def run(self): Run the app. """ try: - with redirect_stderr(StringIO()) as defer_stderr: - asyncio.run(self._run_async()) - except asyncio.CancelledError: - pass - finally: - if self.log_file: - with open(self.log_file, "w") as log: - print(defer_stderr.getvalue(), file=log, end="") + if sys.platform in ('emscripten','wasi'): + pass else: - print(defer_stderr.getvalue(), file=sys.stderr, end="") + asyncio.get_running_loop() + return asyncio.create_task(self._run_async()) + except RuntimeError: + # we will run app directly + try: + with redirect_stderr(StringIO()) as defer_stderr: + asyncio.run(self._run_async()) + except asyncio.CancelledError: + pass + finally: + if self.log_file: + with open(self.log_file, "w") as log: + print(defer_stderr.getvalue(), file=log, end="") + else: + print(defer_stderr.getvalue(), file=sys.stderr, end="") def exit(self): """ diff --git a/nurses_2/io/input/vt100/console_input.py b/nurses_2/io/input/vt100/console_input.py index cedd705d..599feab9 100644 --- a/nurses_2/io/input/vt100/console_input.py +++ b/nurses_2/io/input/vt100/console_input.py @@ -22,6 +22,7 @@ def read_stdin(): """ Read (non-blocking) from stdin and return it decoded. """ + if not select.select(*SELECT_ARGS)[0]: return "" @@ -30,6 +31,12 @@ def read_stdin(): except OSError: return "" +if sys.platform in ('emscripten','wasi'): + import embed + embed.warn("@@@ 36: read_stdin override") + def read_stdin(): + return DECODER.decode(embed.os_read()) + def _create_mouse_event(data): """ Create a MouseEvent from ansi escapes. @@ -105,11 +112,15 @@ def events(): """ Yield input events. """ - data = "".join(iter(read_stdin, "")) + #embed.warn("@@@@ 115 Yield input events.") + if sys.platform in ('emscripten','wasi'): + data = DECODER.decode(embed.os_read()) + else: + data = "".join(iter(read_stdin, "")) while data: data = _find_longest_match(data) yield from _EVENTS - _EVENTS.clear() \ No newline at end of file + _EVENTS.clear() diff --git a/nurses_2/io/input/vt100/vt100_input.py b/nurses_2/io/input/vt100/vt100_input.py index 038f166e..7cb465d9 100644 --- a/nurses_2/io/input/vt100/vt100_input.py +++ b/nurses_2/io/input/vt100/vt100_input.py @@ -30,6 +30,10 @@ def attach(callback): Context manager that makes this input active in the current event loop. """ _EVENTS.clear() + try: + embed.warn(f"@@@ 34 : TODO SIGWINCH {callback=}") + except: + pass stdin = sys.stdin.fileno() @@ -52,6 +56,7 @@ def on_resize(signum, stack): @contextmanager def raw_mode(): + import tty stdin = sys.stdin.fileno() attrs_before = termios.tcgetattr(stdin)