mirror of
https://github.com/RGBCube/CSAssignments
synced 2025-07-25 13:07:46 +00:00
Start making the interactive runner & use punctuation and stuff
This commit is contained in:
parent
58f5c52db5
commit
9a63e4127d
4 changed files with 80 additions and 25 deletions
|
@ -31,5 +31,5 @@ You can download it from [here](https://www.python.org/downloads/).
|
|||
### Windows
|
||||
|
||||
```bat
|
||||
run.bat
|
||||
.\run.bat
|
||||
```
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue