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

Nice tool! / Ctrl+Z not working / Exit code and window resizes not forwarded #1

Open
hartwork opened this issue Dec 11, 2023 · 7 comments

Comments

@hartwork
Copy link

Hi @qingyunha,

very nice tool! I tried…

  • python3 -m ppty -- htop
  • python3 -m ppty -- sh -c 'exit 123' ; echo $?

…and learned that…

  • Ctrl+Z is not working in htop, and that
  • window resizes (signal SIGWINCH) are not forwarded to htop, and that
  • the exit code is not passed through in the second case.

Would you be interested in fixing these issues?

@qingyunha
Copy link
Owner

Hi, @hartwork, window resize and exit code should be fixed. But I don't have a simple fix for Ctrl-Z, see go-delve/delve#2157 .

@hartwork
Copy link
Author

hartwork commented Dec 12, 2023

@qingyunha wow, that was quick!

Regarding Ctrl+Z I already found out that the pty needs to be put in "isim" mode but just catching the signal and sending SIGSTOP to the child process is not enough, it needs something more. If you want to play with it also, this snippet may help:

    import subprocess
    subprocess.check_call(['stty', 'isig'])

    def handle_sigtstp(*args, **kwargs):
        print('got SIGTSTP')

    signal.signal(signal.SIGTSTP, handle_sigtstp)

Regarding go-delve/delve#2157 — what in there did you intend to point me to, specifically?

@qingyunha qingyunha reopened this Dec 12, 2023
@qingyunha
Copy link
Owner

It seems using stty isig  is enough to support Ctrl-Z, the tty will send SIGTSTP to ppty itself. But it also makes Ctrl-C interrupt ppty.

@hartwork
Copy link
Author

It seems using stty isig is enough to support Ctrl-Z, the tty will send SIGTSTP to ppty itself.

@qingyunha I'm not sure I understand. When running a Bash shell, launching htop and pressing Ctrl+Z the htop "window" disappears, Bash says something like [1]+ Stopped htop, and running fg will continue htop execution and bring the window back up. Now if we insert a transparent PTY runner like ppty in the middle — running htop through ppty — as a user I would expect no noticeable difference in behavior. My understanding is that ppty would need to play a part in this to make it work seamlessly. What do you think?

@qingyunha
Copy link
Owner

You can try python3 -m ppty -- htop with the new branch ctrl-z I just pushed.

@hartwork
Copy link
Author

hartwork commented Dec 13, 2023

@qingyunha when I run python3 -m ppty -- htop in Bash and hit Ctrl+Z with the code on branch ctrl-z:

  • The htop "window" freezes (it does not go away)
  • Below that frozen htop it reads [4]+ Stopped python3 -m ppty -- htop (which is good)
  • The terminal is in a broken state though (e.g. echo is still off and clicking with the mouse adds text to the Bash prompt), I need to run reset
  • When running fg now, htop comes back alive but the rendering is broken, in particular the the top 8 or so lines.
  • When I hit Ctrl+C then, I get a backtrace ending in line KeyboardInterrupt

@qingyunha
Copy link
Owner

We should reset/restory the tty status before C-Z and fg. I update the branch but it still not work very well.

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

2 participants