55import time
66import _nx
77import nx
8- from nx .utils import AnsiMenu
8+ from nx .utils import AnsiMenu , clear_terminal
99
1010
1111sys .argv = ["" ] # workaround needed for runpy
1818def run_python_module (path : str ):
1919 runpy .run_path (path , run_name = '__main__' )
2020 _nx .gfx_set_mode (TILED_DOUBLE )
21- print ("{} exited." .format (selected ), flush = True )
22-
23-
24- def clear_screen ():
25- sys .stdout .buffer .write (b"\x1b [2J" )
26- sys .stdout .buffer .flush ()
21+ print ("{} exited." .format (selected ))
2722
2823
2924def confirmation_prompt (program_name : str ):
3025 name = program_name [:- 3 ] if program_name .endswith ('.py' ) else program_name
3126 name = name [:- 1 ] if name .endswith (os .sep ) else name
3227 print ("Do you want to execute the Python program {}?\n "
33- "Press A to confirm, B to cancel." .format (name ), flush = True )
28+ "Press A to confirm, B to cancel." .format (name ))
3429 while True :
3530 nx .refresh_inputs ()
3631 if nx .p1 .a_button .is_pressed :
@@ -42,26 +37,29 @@ def confirmation_prompt(program_name: str):
4237
4338if __name__ == '__main__' :
4439 while True :
45- clear_screen ()
40+ clear_terminal ()
4641 dirs = ["../" ] + glob ("*/" )
4742 scripts = glob ("*.py" )
4843 if os .getcwd () == PYNX_DIR_PATH and MAIN_PY in scripts :
4944 scripts .remove (MAIN_PY )
45+ for _dir in dirs :
46+ if os .path .isfile (os .path .join (_dir , MAIN_PY )):
47+ dirs .replace (_dir , _dir [:- 1 ])
5048 listing = dirs + scripts
5149 file_menu = AnsiMenu (listing )
52- print ("Listing for {}:" .format (os .getcwd ()), flush = True )
50+ print ("Listing for {}:" .format (os .getcwd ()))
5351 selected = listing [file_menu .query ()]
54- clear_screen ()
52+ clear_terminal ()
5553 if selected in dirs :
5654 os .chdir (selected )
5755 if os .path .isfile (MAIN_PY ) and not selected == '../' and not os .getcwd () == PYNX_DIR_PATH :
5856 response = confirmation_prompt (selected )
59- clear_screen ()
57+ clear_terminal ()
6058 if response is True :
6159 run_python_module (MAIN_PY )
6260 os .chdir (os .pardir )
6361 else :
6462 response = confirmation_prompt (selected )
65- clear_screen ()
63+ clear_terminal ()
6664 if response is True :
6765 run_python_module (selected )
0 commit comments