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

pygbag support #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,7 @@ docsrc/_build
docsrc/reference/generated

examples/_old

*-pygbag.???
/build
/dist
40 changes: 40 additions & 0 deletions 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
26 changes: 17 additions & 9 deletions nurses_2/app.py
Expand Up @@ -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):
"""
Expand Down
15 changes: 13 additions & 2 deletions nurses_2/io/input/vt100/console_input.py
Expand Up @@ -22,6 +22,7 @@ def read_stdin():
"""
Read (non-blocking) from stdin and return it decoded.
"""

if not select.select(*SELECT_ARGS)[0]:
return ""

Expand All @@ -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.
Expand Down Expand Up @@ -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()
_EVENTS.clear()
5 changes: 5 additions & 0 deletions nurses_2/io/input/vt100/vt100_input.py
Expand Up @@ -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()

Expand All @@ -52,6 +56,7 @@ def on_resize(signum, stack):

@contextmanager
def raw_mode():
import tty
stdin = sys.stdin.fileno()
attrs_before = termios.tcgetattr(stdin)

Expand Down