diff --git a/README.md b/README.md index 5a62879..77aacb4 100644 --- a/README.md +++ b/README.md @@ -31,5 +31,5 @@ You can download it from [here](https://www.python.org/downloads/). ### Windows ```bat -run.bat +.\run.bat ``` diff --git a/interactive_runner/__main__.py b/interactive_runner/__main__.py index 132414a..15f9f88 100644 --- a/interactive_runner/__main__.py +++ b/interactive_runner/__main__.py @@ -1,23 +1,78 @@ -import interactive_runner as lib +from typing import Literal, overload -s = lib.Sources() -for l in s.languages.values(): - print("lname", l.name) - print("lsname", l.styled_name) - print("ldesc", l.description) - print("lbc", l._build_command) - print("ldni", l.check_dependencies_installed()) - print("lisc", l.is_compiled) - print("lrcmd", l._run_command) - print() - for a in l.assignments.values(): - print("alang", a.language) - print("aname", a.name) - print("agivend", a.given_date) - print("adesc", a.description) - print("adirs", a.directions) +from chalky.shortcuts.sty import bold + +from . import Sources +from .helpers import chalk_from_int as color + +__print = print +__input = input +__int = int + +green = color(0x39ff14) +red = color(0xff0000) + +invalid_input = red | "Invalid input! Try again." + +sources = Sources() + + +def print(*s: str, nl: bool = False) -> None: + __print(*s) + if nl: + __print() + + +@overload +def input( + *s: str, + nl: bool = False, + int: bool = Literal[True], + valid: set[int] | None = None +) -> int: + ... + + +@overload +def input(*s: str, nl: bool = False) -> str: + ... + + +def input(*s: str, nl: bool = False, int: bool = False, valid: set[int] | None = None) -> str | int: + r = __input(*s).lower().strip() + if r == "exit": + print(red | "Exiting...") + exit() + elif int: try: - a.run() - except Exception as e: - print("errrun", e) - print() + val = __int(r) + if valid and val not in valid: + print(invalid_input) + val = input(*s, int=int, valid=valid) + if nl: + print() + except ValueError: + print(invalid_input) + val = input(*s, int=int, valid=valid) + finally: + return val + else: + if nl: + print() + return r + + +while True: + print("----------", green & bold | "MAIN MENU", "----------") + print(f"{green | 1}: Browse languages.") + print(f"{green | 2}: Invalidate all cache.", nl=True) + + choice = input("Choose an option by its number: ", nl=True, int=True, valid={1, 2}) + + match choice: + case 1: + ... + + case 2: + sources.refresh() + print(green | "Successfully invalidated all cache.", nl=True) diff --git a/interactive_runner/helpers.py b/interactive_runner/helpers.py index 606a88b..fcbeb10 100644 --- a/interactive_runner/helpers.py +++ b/interactive_runner/helpers.py @@ -21,7 +21,7 @@ def __rgb_from_int(i: int, /) -> tuple[int, int, int]: def chalk_from_int(foreground: int, background: int = None, /) -> Chalk: return Chalk( foreground=TrueColor(*__rgb_from_int(foreground)), - background=TrueColor(*__rgb_from_int(background)) + background=TrueColor(*__rgb_from_int(background)) if background else None ) diff --git a/sources/c/star rating/star_rating.c b/sources/c/star rating/star_rating.c index 6b3ac9e..b13d910 100644 --- a/sources/c/star rating/star_rating.c +++ b/sources/c/star rating/star_rating.c @@ -8,7 +8,7 @@ int main() { for (int i = 0; i < 21; i++) { printf("Review number %i, enter rating (1 to 5): ", i+1); - // read the input as int + // Read the input as int. scanf("%i", &ratings[i]); int rating = ratings[i]; @@ -18,7 +18,7 @@ int main() { return 1; } - // increment the star count for the stars + // Increment the star count for the stars. // (-1 is because indexes start from 0) ++rating_frequency[rating-1]; total_stars += rating;