Skip to content

Commit

Permalink
chore: use simple terminal menu for control script
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanElsner committed Jul 7, 2024
1 parent 6f5581a commit 184804a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
27 changes: 12 additions & 15 deletions src/garmi_gui/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import argparse
import xmlrpc.client

import simple_term_menu # type: ignore[import-not-found]


def main() -> None:
"""Simple terminal program that allows you to connect to a GARMI GUI remotely
Expand All @@ -22,30 +24,25 @@ def main() -> None:
server_url = f"http://{args.hostname}:{args.port}"
proxy = xmlrpc.client.ServerProxy(server_url)

menu = simple_term_menu.TerminalMenu(
["Show Image", "Play Sound", "Show Video", "Show Text", "Render Text", "Exit"]
)
while True:
print("\nOptions:")
print("1. Show Image")
print("2. Play Sound")
print("3. Show Video")
print("4. Show Text")
print("5. Render Text")
print("6. Exit")

choice = input("Select an option by entering the corresponding number: ")
choice = menu.show()

if choice == "1":
if choice == 0:
image_path = input("Enter the path to the image: ")
proxy.show_image(image_path)
print(f"Image '{image_path}' displayed.")
elif choice == "2":
elif choice == 1:
sound_path = input("Enter the path to the sound file: ")
proxy.play_sound(sound_path)
print(f"Sound '{sound_path}' played.")
elif choice == "3":
elif choice == 2:
video_path = input("Enter the path to the video file: ")
proxy.show_video(video_path)
print(f"Video '{video_path}' displayed.")
elif choice == "4":
elif choice == 3:
print("Enter the text to display: ")
lines = []
while True:
Expand All @@ -62,7 +59,7 @@ def main() -> None:
font_size = int(font_size_str) if font_size_str else 100
proxy.show_text(text, color, font_size)
print(f"Text '{text}' displayed.")
elif choice == "5":
elif choice == 4:
print("Enter the text to render (finish input by entering an empty line):")
lines = []
while True:
Expand All @@ -83,7 +80,7 @@ def main() -> None:
font_size = int(font_size_str) if font_size_str else 100
proxy.render_text(text, speed, color, font_size)
print(f"Text '{text}' rendered.")
elif choice == "6":
elif choice == 5:
print("Exiting.")
break
else:
Expand Down
56 changes: 54 additions & 2 deletions tests/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,59 @@
from garmi_gui import control


@mock.patch("builtins.input", return_value="6")
def test_control(*args):
@mock.patch("builtins.input", return_value="")
@mock.patch("simple_term_menu.TerminalMenu.show", return_value=5)
def test_exit(*args):
del args
control.main()


@mock.patch("builtins.input", return_value="test.png")
@mock.patch("simple_term_menu.TerminalMenu.show", side_effect=[0, 5])
@mock.patch("xmlrpc.client.ServerProxy")
def test_show_image(mock_proxy, mock_show, mock_input):
del mock_show, mock_input
control.main()
mock_proxy.return_value.show_image.assert_called_once_with("test.png")


@mock.patch("builtins.input", return_value="test.wav")
@mock.patch("simple_term_menu.TerminalMenu.show", side_effect=[1, 5])
@mock.patch("xmlrpc.client.ServerProxy")
def test_play_sound(mock_proxy, mock_show, mock_input):
del mock_show, mock_input
control.main()
mock_proxy.return_value.play_sound.assert_called_once_with("test.wav")


@mock.patch("builtins.input", return_value="test.mp4")
@mock.patch("simple_term_menu.TerminalMenu.show", side_effect=[2, 5])
@mock.patch("xmlrpc.client.ServerProxy")
def test_show_video(mock_proxy, mock_show, mock_input):
del mock_show, mock_input
control.main()
mock_proxy.return_value.show_video.assert_called_once_with("test.mp4")


@mock.patch("builtins.input", side_effect=["line1", "line2", "", "255, 255, 255", "75"])
@mock.patch("simple_term_menu.TerminalMenu.show", side_effect=[3, 5])
@mock.patch("xmlrpc.client.ServerProxy")
def test_show_text(mock_proxy, mock_show, mock_input):
del mock_show, mock_input
control.main()
mock_proxy.return_value.show_text.assert_called_once_with(
"line1\nline2", (255, 255, 255), 75
)


@mock.patch(
"builtins.input", side_effect=["line1", "line2", "", "15", "255, 255, 255", "75"]
)
@mock.patch("simple_term_menu.TerminalMenu.show", side_effect=[4, 5])
@mock.patch("xmlrpc.client.ServerProxy")
def test_render_text(mock_proxy, mock_show, mock_input):
del mock_show, mock_input
control.main()
mock_proxy.return_value.render_text.assert_called_once_with(
"line1\nline2", 15, (255, 255, 255), 75
)

0 comments on commit 184804a

Please sign in to comment.