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

Multiple instances when opening and closing a file #10

Closed
GiorgosXou opened this issue Feb 10, 2022 · 6 comments
Closed

Multiple instances when opening and closing a file #10

GiorgosXou opened this issue Feb 10, 2022 · 6 comments

Comments

@GiorgosXou
Copy link
Owner

https://github.com/GiorgosXou/TUIFIManager/blob/19487a82f9c42152b46c58e2a04a942585533eda/TUIFIManager/__init__.py#L255/

@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Feb 14, 2022

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).

Issue

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 potential solution

A temporary but also potential solution could be os.exec*()

@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Feb 14, 2022

Yep, so far (the temp solution) works as expected
Screenshot_2022-02-14-14-26-46-749_com termux
(Image: termux)

@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Feb 15, 2022

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)

@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Feb 15, 2022

Also just a reminder to add

if unicurses.OPERATING_SYSTEM != 'Windows': 
    os.system('stty sane')

Or something like that anyways

@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Feb 28, 2022

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__))))

@GiorgosXou
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant