Skip to content

Commit d7f6896

Browse files
committed
compleate the basice confirm data tui :D
1 parent cde14ea commit d7f6896

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

solve.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
discription = main_div.find("div", {"class": "_1l1MA"})
6464

6565
# Show the tui for confirm the data and choose the language to solve the problem
66-
data = tui.confirm_data(Data(title, level, problem_path))
66+
data = Data(title, level, problem_path)
67+
tui.confirm_data(data)
68+
print(data)
69+
exit(0)
6770

6871
# Download the images if there are any
6972
for img in discription.find_all("img"):

utils/pytermgui_tui.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,21 @@ def get_the_url(base_url: str) -> str:
6161
wm.run()
6262
return problem_url
6363

64-
def confirm_data(data: Data) -> Data:
64+
def parse_data(manager: ptg.WindowManager, window: ptg.Window, data: Data) -> None:
65+
""" Parse the data and choose the language to solve the problem """
66+
for widget in window:
67+
if isinstance(widget, ptg.InputField):
68+
if widget.prompt == "Title: ":
69+
data.title = widget.value
70+
elif widget.prompt == "Level: ":
71+
data.level = widget.value
72+
elif widget.prompt == "Base path:":
73+
data.problem_path = widget.value
74+
elif widget.prompt == "Solve with:":
75+
data.solve_with = [str(s).strip() for s in widget.value.split(",")]
76+
manager.stop()
77+
78+
def confirm_data(data: Data) -> None:
6579
""" Show the tui using the pytermgui for confirm the data and choose the language to solve the problem """
6680
with ptg.WindowManager() as wm:
6781
wm.layout.add_slot("Body")
@@ -71,16 +85,14 @@ def confirm_data(data: Data) -> Data:
7185
ptg.InputField(data.title, prompt="Title: "),
7286
ptg.InputField(data.level, prompt="Level: "),
7387
ptg.InputField(data.problem_path, prompt="Base path:"),
88+
ptg.InputField("rust,", prompt="Solve with:"),
7489
"",
75-
["Confirm", lambda *_: wm.stop()],
90+
["Confirm", lambda *_: parse_data(wm, window, data)],
7691
width=60,
7792
box="DOUBLE",
7893
)
7994
.set_title("[green bold]Confirm the data")
8095
.center()
8196
)
8297
wm.add(window)
83-
wm.run()
84-
85-
data.solve_with = ["python", "java", "c++", "c", "go"]
86-
return data
98+
wm.run()

0 commit comments

Comments
 (0)