Skip to content

Conversation

@certik
Copy link
Collaborator

@certik certik commented Sep 13, 2024

This allows to catch Ctrl-C from within a running command, but unfortunately still exits. Also there seems to be some thread (?) still running in the background, since I get some later error message while I am already back in Bash:

~/repos/shell(ctrl_c2)$ cat
^CReceived Ctrl+C

~/repos/shell(ctrl_c2)$ cat: Input/output error (os error 5)
Error: Errno(EIO)

~/repos/shell(ctrl_c2)$

Fixes #120.

@certik
Copy link
Collaborator Author

certik commented Sep 13, 2024

On Windows on the other hand it does not exit the shell:

~/repos/shell(ctrl_c2)$ ../lfortran/src/bin/lfortran
Interactive Fortran. Experimental prototype, not ready for end users.
LFortran version: 0.40.0-57-gb50db1203
  * Use Ctrl-D to exit
  * Use Enter to submit
  * Use Alt-Enter or Ctrl-N to make a new line
    - Editing (Keys: Left, Right, Home, End, Backspace, Delete)
    - History (Keys: Up, Down)
>>> Received Ctrl+C                                                           1,1   ]
~/repos/shell(ctrl_c2)$

Although it leaves the terminal in a bad state (up arrow prints [A instead of showing the previous command), but that's a separate issue.

@certik
Copy link
Collaborator Author

certik commented Sep 20, 2024

On Linux with /bin/cat, it seems to work:

~/repos/shell(ctrl_c2)$ /bin/cat
s
s
^CReceived Ctrl+C
~/repos/shell(ctrl_c2)$

But on the builtin cat it just hangs, will not exit. I must exit it with Ctrl-D.

@certik
Copy link
Collaborator Author

certik commented Sep 27, 2024

This seems to greatly help with 3rd party programs, that the terminal doesn't get killed. I am going to merge it and we'll further iterate if needed.

@certik certik marked this pull request as ready for review September 27, 2024 20:13
@certik certik enabled auto-merge (squash) September 27, 2024 20:15
@certik certik merged commit 1113c78 into prefix-dev:main Sep 27, 2024
6 checks passed
@certik certik deleted the ctrl_c2 branch September 27, 2024 20:18
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

Successfully merging this pull request may close these issues.

Windows: Ctrl-C in a program kills the shell

1 participant