Some cli improvements

- Adds cross platform clear console functionality
- Replaces "search_for_metadata" if tree with a match case
- Implements alternative command interface for handling the program
- Fixes bug of error being displayed when quitting the program
This commit is contained in:
Muffin-chan 2022-11-22 03:24:25 -05:00
parent fe1c849852
commit ad446a1099
4 changed files with 47 additions and 15 deletions

3
.gitignore vendored
View File

@ -10,3 +10,6 @@ __pycache__/
/build/* /build/*
!/build/build.sh !/build/build.sh
# Virtual Environment
venv

View File

@ -1,3 +1,4 @@
from .utils.functions import *
from .utils.shared import * from .utils.shared import *
from .metadata import ( from .metadata import (
@ -37,24 +38,42 @@ def get_existing_genre():
def search_for_metadata(): def search_for_metadata():
clear_console()
search = metadata_search.Search() search = metadata_search.Search()
while True: while True:
input_ = input( input_ = input(
"q to quit, .. for previous options, int for this element, str to search for query, ok to download\n") """
input_.strip() - - - Type the command you want to execute - - -
if input_.lower() == "ok": .. - Previous Options
(query_string) - Search for songs, albums, bands...
(int) - Select an item from the search results
d - Start the download
h - Help
q - Quit / Exit
command: """
)
match (input_.strip().lower()):
case "d" | "ok" | "dl" | "download":
break break
if input_.lower() == "q": case "q" | "quit" | "exit":
break clear_console()
if input_.lower() == "..": exit()
case "h" | "help":
print() print()
print(search.get_previous_options()) # TODO: Help text (mainly explaining query strings and alternative command functionalities)
continue print("Insert here help text....")
if input_.isdigit(): case inp if inp.isdigit():
print() print()
print(search.choose(int(input_))) print(search.choose(int(input_)))
continue continue
case ".." :
print()
print(search.get_previous_options())
print() print()
print(search.search_from_query(input_)) print(search.search_from_query(input_))
@ -81,6 +100,8 @@ def get_genre():
def cli(start_at: int = 0, only_lyrics: bool = False): def cli(start_at: int = 0, only_lyrics: bool = False):
clear_console()
if start_at <= 2 and not only_lyrics: if start_at <= 2 and not only_lyrics:
genre = get_genre() genre = get_genre()
logging.info(f"{genre} has been set as genre.") logging.info(f"{genre} has been set as genre.")
@ -107,3 +128,7 @@ def cli(start_at: int = 0, only_lyrics: bool = False):
if start_at <= 4: if start_at <= 4:
logging.info("starting to fetch the lyrics") logging.info("starting to fetch the lyrics")
lyrics.fetch_lyrics() lyrics.fetch_lyrics()
def gtk_gui():
pass

View File

@ -1,2 +1,2 @@
# tells what exists # tells what exists
__all__ = ["shared", "object_handeling", "phonetic_compares"] __all__ = ["shared", "object_handeling", "phonetic_compares", "functions"]

View File

@ -0,0 +1,4 @@
import os
def clear_console():
os.system('cls' if os.name in ('nt', 'dos') else 'clear')