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

CTRL+C and CTRL+D kill tbp #3

Closed
John-Robbins opened this issue Aug 26, 2024 · 2 comments · Fixed by #48
Closed

CTRL+C and CTRL+D kill tbp #3

John-Robbins opened this issue Aug 26, 2024 · 2 comments · Fixed by #48
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@John-Robbins
Copy link
Owner

Right now I'm not handling CTRL+C or CTRL+D at the tbp prompt (tbp:>) or the debug prompt (DEBUG[111]:>). Should I be? What is the best practice for this kind of approach?

In the Python REPL, CTRL+C is reported as a KeyboardInterrupt but does not kill the process, were CTRL+D does.

I should note that I'm already handling CTRL+C and CTRL+D in the INPUT statement.

tbp:>input a
[A]? Error #350: Aborting RUN from INPUT entry.
tbp:>input a
[A]? ^DError #350: Aborting RUN from INPUT entry.
tbp:>

What's the overall plan for these keystrokes? Should INPUT be different like it is now?

@John-Robbins John-Robbins added bug Something isn't working enhancement New feature or request labels Aug 26, 2024
@John-Robbins John-Robbins self-assigned this Aug 26, 2024
@John-Robbins John-Robbins added this to the V 1.0.0 milestone Sep 10, 2024
@John-Robbins
Copy link
Owner Author

John-Robbins commented Sep 11, 2024

I did some thinking and playing with the Python REPL to come up with how I think CTRL+C and CTRL+D should be handled.

Reminder:

  • CTRL+C generates a KeyboardInterrupt exception.
  • CTRL+D generates a EOFError exception.

Right now my helpers.read_input method is eating both exceptions. That will obviously have to change. These two exceptions need to be handled in Driver.party_like_it_is_1976 where the main prompt loop resides.

The handling will be based on the state of the Interpreter, which will be read by the exception handler in Driver.party_like_it_is_1976. Here's how each state will be handled. See the Interpreter.State enum for the meaning of each state.

LINE_STATE or BREAK_STATE:

  • CTRL+C: Nothing (may require a newline, will check)
  • CTRL+D: Exit's tbp back to the shell with exit of 1.

RUNNING_STATE:

  • Note that this is when executing code or sitting at an INPUT prompt.
  • CTRL+C: Call Interpreter.initialize_runtime_state.
  • CTRL+D: Call Interpreter.initialize_runtime_state.

FILE_STATE or ERROR_FILE_STATE:

  • These states are when loading and parsing files.
  • CTRL+C will call Interpreter.initialize_runtime_state and Interpreter.clear_program.

@John-Robbins
Copy link
Owner Author

John-Robbins commented Sep 11, 2024

The Plan

  • Change helpers.read_input to return a string and not eat the exceptions. Update the callers in Driver and Interpreter.
  • Prototype a test where I Monkey Patch helpers.read_input and come up with a way to pump in text and raise the exceptions for full testing.
  • Add a current_state property or method to Interpreter that returns the Interpreter.State enum. Remove the Interpreter.at_breakpoint and change callers to use the current_state property.
  • Make the changes to the Driver.party_like_it_is_1976 method to do the exception handling outlined in the previous comment.

John-Robbins added a commit that referenced this issue Sep 13, 2024
Full implementation of the CTRL+C and CTRL+D processing as outlined in issue #3.

A few other small fixes to tests and better output.
John-Robbins added a commit that referenced this issue Sep 16, 2024
- Added the `%exit` command language command to exit the tbp debugger. Closes #1.
- Now tbp behaves like a normal command line application when the user hits `CTRL+C` and `CTRL+D`. Closes #3. 
- Fixed the copyright on top of all Python files. For some reason I thought it was 2004. Closes #43.
- Added the combined coverage report summary to the CI.yml output. That makes it easier to see what didn't have coverage. Closes #44.
- Added the `tiny_basic_grammar.ebnf` and `grammar_tests.txt` that I forgot to bring over from the dead repository. Closes #45.
- Added better error reporting on `INPUT` entry errors and escaped syntax error strings, so characters like `\n` are displayed correctly. Closes #46.
- Did a pass to eliminate any dead code. Closes #47.
- Did a final editing pass on all documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@John-Robbins and others