summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-04-30 12:41:02 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-04-30 13:12:23 -0400
commit79bf87d1e333ea5fe0dfeb61c707eb9bddfd0255 (patch)
tree1e04c689b17f752732c67a10bcc76cb4cf4bee1a
parent37d415b4bbfd6efd383a20062df68f627451ccf7 (diff)
downloadcmd2-git-79bf87d1e333ea5fe0dfeb61c707eb9bddfd0255.tar.gz
Removed cmd2.Cmd.quit_on_sigint.
-rw-r--r--CHANGELOG.md1
-rw-r--r--cmd2/cmd2.py21
-rw-r--r--docs/features/initialization.rst2
-rw-r--r--docs/features/misc.rst18
-rwxr-xr-xtests/test_cmd2.py27
5 files changed, 10 insertions, 59 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 92501fc1..3e6ca9cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,7 @@
and just opens an interactive Python shell.
* Changed default behavior of `runcmds_plus_hooks()` to not stop when Ctrl-C is pressed and instead
run the next command in its list.
+ * Removed `cmd2.Cmd.quit_on_sigint` flag, which when `True`, quit the application when Ctrl-C was pressed at the prompt.
* Enhancements
* Added support for custom tab completion and up-arrow input history to `cmd2.Cmd2.read_input`.
See [read_input.py](https://github.com/python-cmd2/cmd2/blob/master/examples/read_input.py)
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index cc1d5e6b..418f8a4f 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -293,7 +293,6 @@ class Cmd(cmd.Cmd):
# Attributes which should NOT be dynamically settable via the set command at runtime
self.default_to_shell = False # Attempt to run unrecognized commands as shell commands
- self.quit_on_sigint = False # Ctrl-C at the prompt will quit the program instead of just resetting prompt
self.allow_redirection = allow_redirection # Security setting to prevent redirection of stdout
# Attributes which ARE dynamically settable via the set command at runtime
@@ -2490,13 +2489,10 @@ class Cmd(cmd.Cmd):
nextline = '\n'
self.poutput(nextline)
line = f'{self._multiline_in_progress}{nextline}'
- except KeyboardInterrupt as ex:
- if self.quit_on_sigint:
- raise ex
- else:
- self.poutput('^C')
- statement = self.statement_parser.parse('')
- break
+ except KeyboardInterrupt:
+ self.poutput('^C')
+ statement = self.statement_parser.parse('')
+ break
finally:
self._at_continuation_prompt = False
@@ -3067,12 +3063,9 @@ class Cmd(cmd.Cmd):
# Get commands from user
try:
line = self._read_command_line(self.prompt)
- except KeyboardInterrupt as ex:
- if self.quit_on_sigint:
- raise ex
- else:
- self.poutput('^C')
- line = ''
+ except KeyboardInterrupt:
+ self.poutput('^C')
+ line = ''
# Run the command along with all associated pre and post hooks
stop = self.onecmd_plus_hooks(line)
diff --git a/docs/features/initialization.rst b/docs/features/initialization.rst
index ab792c2c..e3acf859 100644
--- a/docs/features/initialization.rst
+++ b/docs/features/initialization.rst
@@ -146,8 +146,6 @@ override:
everything available with **self_in_py**)
- **quiet**: if ``True`` then completely suppress nonessential output (Default:
``False``)
-- **quit_on_sigint**: if ``True`` Ctrl-C at the prompt will quit the program
- instead of just resetting prompt
- **settable**: dictionary that controls which of these instance attributes
are settable at runtime using the *set* command
- **timing**: if ``True`` display execution time for each command (Default:
diff --git a/docs/features/misc.rst b/docs/features/misc.rst
index 3825065f..c2f14b5b 100644
--- a/docs/features/misc.rst
+++ b/docs/features/misc.rst
@@ -99,21 +99,3 @@ method be called.
(Cmd) my dog has fleas
sh: my: not found
*** Unknown syntax: my dog has fleas
-
-
-Quit on SIGINT
---------------
-
-On many shells, SIGINT (most often triggered by the user pressing Ctrl+C)
-while at the prompt only cancels the current line, not the entire command
-loop. By default, a ``cmd2`` application matches this behavior. However, if
-``quit_on_sigint`` is set to ``True``, the command loop will quit instead.
-
-::
-
- (Cmd) typing a comma^C
- (Cmd)
-
-.. warning::
- The default SIGINT behavior will only function properly if **cmdloop** is running
- in the main thread.
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 64237f09..cfa30830 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -962,36 +962,13 @@ def say_app():
return app
-def test_interrupt_quit(say_app):
- say_app.quit_on_sigint = True
-
- # Mock out the input call so we don't actually wait for a user's response on stdin
- m = mock.MagicMock(name='input')
- m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof']
- builtins.input = m
-
- try:
- say_app.cmdloop()
- except KeyboardInterrupt:
- pass
-
- # And verify the expected output to stdout
- out = say_app.stdout.getvalue()
- assert out == 'hello\n'
-
-
-def test_interrupt_noquit(say_app):
- say_app.quit_on_sigint = False
-
+def test_ctrl_c_at_prompt(say_app):
# Mock out the input call so we don't actually wait for a user's response on stdin
m = mock.MagicMock(name='input')
m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof']
builtins.input = m
- try:
- say_app.cmdloop()
- except KeyboardInterrupt:
- pass
+ say_app.cmdloop()
# And verify the expected output to stdout
out = say_app.stdout.getvalue()