@@ -50,24 +50,28 @@ def run_choice_tree(question: QuestionNode):
50
50
Args:
51
51
question: Root question from which the choice tree will start
52
52
"""
53
- # 3M-TODO: allow exit with Ctrl+C and Q
53
+ # 3M-TODO: allow exit with Q
54
54
prev_args = []
55
55
prev_message = ""
56
56
next_question = question
57
- while True :
58
- option , _ = pick (
59
- list (map (lambda a : a .label , next_question .answers )) + ["Exit" ],
60
- prev_message + "\n \n " + next_question .label ,
61
- indicator = "=>" ,
62
- )
63
- if option == "Exit" :
64
- return
65
- selected_answer = find (next_question .answers , lambda a : a .label == option )
66
- prev_message , prev_args = selected_answer .action (* prev_args )
67
- next_question = selected_answer .next_question
68
- if next_question is None :
69
- pick (["Press 'Enter' to continue" ], prev_message , indicator = "" )
70
- return
57
+ try :
58
+ while True :
59
+ option , _ = pick (
60
+ list (map (lambda a : a .label , next_question .answers )) + ["Exit" ],
61
+ prev_message + "\n \n " + next_question .label ,
62
+ indicator = "=>" ,
63
+ )
64
+ if option == "Exit" :
65
+ return
66
+ selected_answer = find (next_question .answers , lambda a : a .label == option )
67
+ prev_message , prev_args = selected_answer .action (* prev_args )
68
+ next_question = selected_answer .next_question
69
+ if next_question is None :
70
+ pick (["Press 'Enter' to continue" ], prev_message , indicator = "" )
71
+ return
72
+
73
+ except KeyboardInterrupt :
74
+ pass
71
75
72
76
73
77
# Example:
0 commit comments