Skip to content

Commit

Permalink
Option to disable all keys by using --disable_all_keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
tech-chad committed Oct 26, 2021
1 parent 57d12c4 commit 1219875
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dstatic/dstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def static(screen, color_mode: str, args: argparse.Namespace):
ch = screen.getch()
if args.screen_saver and ch != -1:
break
if ch in [81, 113]: # q, Q
if ch in [81, 113] and not args.disable_all_keys: # q, Q
break
if args.disable_keys:
if args.disable_keys or args.disable_all_keys:
pass
else:
if ch == 98: # b
Expand Down Expand Up @@ -336,6 +336,9 @@ def argument_parser(argv: Optional[Sequence[str]] = None) -> argparse.Namespace:
parser.add_argument("-D", dest="disable_keys", action="store_true",
help="Disable keys while running except for 'Q' or 'q' and "
"for ctrl-c. Does not affect screensaver mode.")
parser.add_argument("--disable_all_keys", action="store_true",
help="Disable all keys while running including 'Q' and 'q.'"
"Use ctrl-c to quit. Does not affect screensaver mode.")
parser.add_argument("--list_colors", action="store_true",
help="List available colors and exit.")
parser.add_argument("--list_commands", action="store_true",
Expand Down
32 changes: 32 additions & 0 deletions tests/test_dstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import mock

import pytest
import time
from hecate import Runner

from dstatic import dstatic
Expand Down Expand Up @@ -276,3 +277,34 @@ def test_dstatic_disable_keys_quit_works(test_keys):
h.write(test_keys)
h.press("Enter")
h.await_exit()


@pytest.mark.parametrize("test_keys", ["Q", "q"])
def test_dstatic_disable_all_keys_check_quit(test_keys):
with Runner(*dstatic_cmd("--disable_all_keys", "--test_mode")) as h:
h.default_timeout = 1
h.await_text("0")
h.write(test_keys)
h.press("Enter")
time.sleep(1)
h.await_text("0")
sc = h.screenshot()
assert "$" not in sc


def test_dstatic_disable_all_keys_run_timer_exit():
""" Test auto exit when using run timer. """
with Runner(*dstatic_cmd("-r2", "--disable_all_keys")) as h:
h.default_timeout = 3
h.await_text(chr(9617))
h.await_exit()


@pytest.mark.parametrize("test_keys", ["Q", "q", "1", "u", "+", "d", "a", " "])
def test_dstatic_disable_all_keys_screensaver_works(test_keys):
with Runner(*dstatic_cmd("--disable_all_keys", "-S")) as h:
h.default_timeout = 3
h.await_text(chr(9617))
h.write(test_keys)
h.press("Enter")
h.await_exit()
8 changes: 8 additions & 0 deletions tests/test_dstatic_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ def test_argument_parsing_additive_color_mode(test_values, expected_result):
def test_argument_parsing_disable_keys(test_values, expected_result):
result = dstatic.argument_parser(test_values)
assert result.disable_keys is expected_result


@pytest.mark.parametrize("test_values, expected_result", [
([], False), (["--disable_all_keys"], True),
])
def test_argument_parsing_disable_all_keys(test_values, expected_result):
result = dstatic.argument_parser(test_values)
assert result.disable_all_keys is expected_result

0 comments on commit 1219875

Please sign in to comment.