Skip to content

Commit

Permalink
Option to disable keys by using -D.
Browse files Browse the repository at this point in the history
  • Loading branch information
tech-chad committed Oct 26, 2021
1 parent 6b603a0 commit 57d12c4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 38 deletions.
82 changes: 44 additions & 38 deletions dstatic/dstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,49 +191,52 @@ def static(screen, color_mode: str, args: argparse.Namespace):
ch = screen.getch()
if args.screen_saver and ch != -1:
break
elif ch in [81, 113]: # q, Q
if ch in [81, 113]: # q, Q
break
elif ch == 98: # b
set_curses_colors("bw", [])
cycle_colors = False
additive_mode = False
elif ch == 67: # C
set_curses_colors("color", [])
cycle_colors = False
additive_mode = False
elif ch == 99: # c
cycle_colors = True
additive_mode = False
elif ch == 100 or ch == 68: # d, D
cycle_colors = False
set_curses_colors("color", [])
delay_time = convert_delay_number_to_delay_time(4)
additive_mode = False
elif ch == 97: # a
if additive_mode:
if args.disable_keys:
pass
else:
if ch == 98: # b
set_curses_colors("bw", [])
cycle_colors = False
additive_mode = False
elif ch == 67: # C
set_curses_colors("color", [])
else:
cycle_colors = False
additive_mode = True
additive_colors = ["black"]
additive_mode = False
elif ch == 99: # c
cycle_colors = True
additive_mode = False
elif ch == 100 or ch == 68: # d, D
cycle_colors = False
set_curses_colors("color", [])
delay_time = convert_delay_number_to_delay_time(4)
additive_mode = False
elif ch == 97: # a
if additive_mode:
additive_mode = False
set_curses_colors("color", [])
else:
cycle_colors = False
additive_mode = True
additive_colors = ["black"]
set_curses_colors("additive", additive_colors)
elif additive_mode and ch in ch_color_codes:
color = curses_ch_codes_color[ch]
if color in additive_colors:
additive_colors.pop(additive_colors.index(color))
else:
additive_colors.append(color)
set_curses_colors("additive", additive_colors)
elif additive_mode and ch in ch_color_codes:
color = curses_ch_codes_color[ch]
if color in additive_colors:
additive_colors.pop(additive_colors.index(color))
else:
additive_colors.append(color)
set_curses_colors("additive", additive_colors)
elif not additive_mode and ch in ch_color_codes:
color = curses_ch_codes_color[ch]
set_curses_colors(color, [])
cycle_colors = False
elif ch in ch_number_codes:
number = curses_number_ch_codes[ch]
delay_time = convert_delay_number_to_delay_time(number)
elif cycle_delay and ch in ch_shift_num_codes:
cycle_delay = curses_shift_num_codes[ch]
elif not additive_mode and ch in ch_color_codes:
color = curses_ch_codes_color[ch]
set_curses_colors(color, [])
cycle_colors = False
elif ch in ch_number_codes:
number = curses_number_ch_codes[ch]
delay_time = convert_delay_number_to_delay_time(number)
elif cycle_delay and ch in ch_shift_num_codes:
cycle_delay = curses_shift_num_codes[ch]
sleep(delay_time)

# clear screen before returning
Expand Down Expand Up @@ -330,6 +333,9 @@ def argument_parser(argv: Optional[Sequence[str]] = None) -> argparse.Namespace:
parser.add_argument("-a", dest="additive", action="store_true",
help="Additive color mode. Use color keys "
"(r,t,y,u,i,o,p,[) to add and remove colors")
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("--list_colors", action="store_true",
help="List available colors and exit.")
parser.add_argument("--list_commands", action="store_true",
Expand Down
28 changes: 28 additions & 0 deletions tests/test_dstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,31 @@ def test_dstatic_list_colors():
def test_dstatic_display_version():
with Runner(*dstatic_cmd("--version")) as h:
h.await_text(f"{dstatic.version}")


@pytest.mark.parametrize("test_keys", ["Q", "q", "1", "u", "+", "d", "a", " "])
def test_dstatic_disable_keys_screensaver_works(test_keys):
with Runner(*dstatic_cmd("-D", "-S")) as h:
h.default_timeout = 3
h.await_text(chr(9617))
h.write(test_keys)
h.press("Enter")
h.await_exit()


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


@pytest.mark.parametrize("test_keys", ["Q", "q"])
def test_dstatic_disable_keys_quit_works(test_keys):
with Runner(*dstatic_cmd("-D")) 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 @@ -149,3 +149,11 @@ def test_argument_parsing_cycle_colors(test_values, expected_results):
def test_argument_parsing_additive_color_mode(test_values, expected_result):
result = dstatic.argument_parser(test_values)
assert result.additive is expected_result


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

0 comments on commit 57d12c4

Please sign in to comment.