File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from typing import Any
2+
3+ from rich .console import Console
4+
5+
6+ def uinput (console : Console , msg : str , qtype : int ) -> Any :
7+ """Takes user input and return the evaluated output.
8+
9+ Args:
10+ console -- Console instance
11+ msg -- question to ask the user
12+ qtype -- question type, whether y/N, string input or number input
13+ 1 is yes or no input
14+ 2 is number/list input
15+
16+ Returns:
17+ The evaluated input based on the user response, e.g.:
18+ y -> True
19+ N -> False
20+ 1, 2, 3 -> list[int]
21+ """
22+
23+ match qtype :
24+ case 1 :
25+ console .print (
26+ f"{ msg } [bold][[green]y[/green]/[red]N[/red]][/bold]" , end = " "
27+ )
28+ if input ().lower ().strip () == "y" :
29+ return True
30+ case 2 :
31+ console .print (
32+ (
33+ f"{ msg } [bold][NUMBER/LIST INPUT"
34+ ", separate by comma ','][/bold]"
35+ ), end = " "
36+ )
37+ return input ()
38+
39+ return False
You can’t perform that action at this time.
0 commit comments