Closed GiorgosXou closed 2 years ago
Silly of me running another subprocess on top of another thinking that the first one would had been terminated somehow (or whatever the fuck i was thinking that time).
It's more of a "how to restore the terminal after opening&closing a subprocess" issue rather than anything else. Somehow after such a sequence (of opening&closing) things can get messed up, especially keys and the mode of terminal [...]
A temporary but also potential solution could be os.exec*()
Yep, so far (the temp solution) works as expected (Image: termux)
Actually this line os.execl(sys.argv[0], sys.argv[0], self.directory)
does the job (I'm not sure why sys.argv[0]
needs to be pressent 2 times)
Also just a reminder to add
if unicurses.OPERATING_SYSTEM != 'Windows':
os.system('stty sane')
Or something like that anyways
I just found out that os.execl(sys.argv[0], sys.argv[0], self.directory)
works only if pip3 install .
the setup.py
and not if I just run python3 ...\__main__.py
with:
import sys
from os.path import dirname, abspath
sys.path.insert(0, dirname(dirname(abspath(__file__))))
Here another very intresting solution i found out:
@staticmethod
@contextmanager
def suspend():
"""
Suspend curses in order to open another subprocess in the terminal.
"""
try:
curses.endwin()
yield
finally:
curses.doupdate()
def open(...):
...
if open_with:
with self.suspend():
os.system('clear')
proc = subprocess.Popen([open_with, directory])
proc.wait()
Althought I've no idea of how it works
https://github.com/GiorgosXou/TUIFIManager/blob/19487a82f9c42152b46c58e2a04a942585533eda/TUIFIManager/__init__.py#L255/