mirror of
https://github.com/RGBCube/CSAssignments
synced 2025-07-26 05:27: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
|
### Windows
|
||||||
|
|
||||||
```bat
|
```bat
|
||||||
run.bat
|
.\run.bat
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,23 +1,78 @@
|
||||||
import interactive_runner as lib
|
from typing import Literal, overload
|
||||||
|
|
||||||
s = lib.Sources()
|
from chalky.shortcuts.sty import bold
|
||||||
for l in s.languages.values():
|
|
||||||
print("lname", l.name)
|
from . import Sources
|
||||||
print("lsname", l.styled_name)
|
from .helpers import chalk_from_int as color
|
||||||
print("ldesc", l.description)
|
|
||||||
print("lbc", l._build_command)
|
__print = print
|
||||||
print("ldni", l.check_dependencies_installed())
|
__input = input
|
||||||
print("lisc", l.is_compiled)
|
__int = int
|
||||||
print("lrcmd", l._run_command)
|
|
||||||
print()
|
green = color(0x39ff14)
|
||||||
for a in l.assignments.values():
|
red = color(0xff0000)
|
||||||
print("alang", a.language)
|
|
||||||
print("aname", a.name)
|
invalid_input = red | "Invalid input! Try again."
|
||||||
print("agivend", a.given_date)
|
|
||||||
print("adesc", a.description)
|
sources = Sources()
|
||||||
print("adirs", a.directions)
|
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
a.run()
|
val = __int(r)
|
||||||
except Exception as e:
|
if valid and val not in valid:
|
||||||
print("errrun", e)
|
print(invalid_input)
|
||||||
print()
|
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:
|
def chalk_from_int(foreground: int, background: int = None, /) -> Chalk:
|
||||||
return Chalk(
|
return Chalk(
|
||||||
foreground=TrueColor(*__rgb_from_int(foreground)),
|
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++) {
|
for (int i = 0; i < 21; i++) {
|
||||||
printf("Review number %i, enter rating (1 to 5): ", i+1);
|
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]);
|
scanf("%i", &ratings[i]);
|
||||||
|
|
||||||
int rating = ratings[i];
|
int rating = ratings[i];
|
||||||
|
@ -18,7 +18,7 @@ int main() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// increment the star count for the stars
|
// Increment the star count for the stars.
|
||||||
// (-1 is because indexes start from 0)
|
// (-1 is because indexes start from 0)
|
||||||
++rating_frequency[rating-1];
|
++rating_frequency[rating-1];
|
||||||
total_stars += rating;
|
total_stars += rating;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue