Skip to content

Commit 4811e45

Browse files
automated view & help message
1 parent 3d8a646 commit 4811e45

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# A

app.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
22

3+
from textual import on
34
from textual.app import App, ComposeResult
45
from textual.containers import Container, Horizontal
56
from textual.widgets import Button, Footer, MarkdownViewer, Header, TextArea, Select, Label
@@ -15,10 +16,18 @@ class MarkdownApp(App):
1516
CSS_PATH = "app.css"
1617
BINDINGS = [
1718
("t", "toggle_table_of_contents", "Toggle TOC"),
18-
("m", "toggle_menu", "Toggle Menu"),
19+
("h", "show_help", "Show Help"),
1920
("q", "quit", "Quit")
2021
]
2122

23+
help_text = """Pick an exercise, and generate a project template by click 'Start Project'
24+
Once you are done implementing the exercise requirements, click on 'Run Tests'.\n
25+
If all the tests passed, congrats!\n
26+
If not, keep at it, one test at a time :)\n
27+
28+
[b][i]Got stuck?[/b][/i] \nRefer to the project's README.md at https://github.com/sissues/cli/blob/main/README.MD,\nor open an issue at https://github.com/sissues/cli/issues
29+
"""
30+
2231
def __init__(self):
2332
super().__init__()
2433
self.files_view_names = ExercisesUtils.generate_view_names_map()
@@ -42,45 +51,26 @@ def compose(self) -> ComposeResult:
4251
def on_mount(self) -> None:
4352
"""Initial setup when the app starts."""
4453
self.show_menu()
45-
menu = self.query_one("#menu")
46-
menu.notify(title="Hello World!", message="Pick an exercise you find interesting, read it by clicking on "
47-
"'View', create a template for a project by clicking on 'Start "
48-
"Project', and once you are done implementing the exercise, "
49-
"you can verify you did everything right by clicking on 'Run "
50-
"Tests'. Pretty Simple. But not easy :)\n\n"
51-
"Also... don't forget to read the README.md file once you click "
52-
"'Start Project'", timeout=30)
54+
self.notify(title="Hello World!", message=self.help_text, timeout=30)
5355

5456
def show_menu(self) -> None:
5557
menu = self.query_one("#menu")
5658
menu.remove_children()
5759

5860
exercises = list(EXERCISES_DIR.glob("*.md"))
5961
exercise_names = [(self.files_view_names[exercise.stem], exercise.stem) for exercise in exercises]
60-
select_file_widget = Select(options=exercise_names, prompt="Select Exercise", id="exercise_select", classes="menu_widget", tooltip="Select an exercise to preview")
62+
select_file_widget = Select(options=exercise_names, allow_blank=False, prompt="Select Exercise", id="exercise_select", classes="menu_widget", tooltip="Select an exercise to preview")
6163

6264
menu.mount(select_file_widget)
63-
menu.mount(Button("View", id="view", variant="primary", classes="menu_widget"))
6465
menu.mount(Button("Start Project", id="start", variant="warning", classes="menu_widget"))
6566
menu.mount(Button("Run Tests", id="test", variant="success", classes="menu_widget"))
6667

6768
async def on_button_pressed(self, event: Button.Pressed) -> None:
6869
button_id = event.button.id
6970
select_widget = self.query_one("#exercise_select", Select)
7071
exercise_name = select_widget.value
71-
selected_exercise = EXERCISES_DIR / f"{exercise_name}.md"
72-
73-
if exercise_name == Select.BLANK:
74-
select_widget.notify("Please select a file", severity="error", timeout=5)
75-
return
7672

77-
if button_id == "view":
78-
self.current_markdown_path = selected_exercise
79-
markdown_viewer = self.query_one("#markdown_viewer", MarkdownViewer)
80-
await markdown_viewer.go(selected_exercise)
81-
self.query_one("#content").display = True
82-
83-
elif button_id == "test":
73+
if button_id == "test":
8474
self.run_tests(exercise_name)
8575

8676
elif button_id == 'start':
@@ -110,10 +100,16 @@ def action_toggle_table_of_contents(self) -> None:
110100
markdown_viewer = self.query_one("#markdown_viewer", MarkdownViewer)
111101
markdown_viewer.show_table_of_contents = not markdown_viewer.show_table_of_contents
112102

113-
def action_toggle_menu(self) -> None:
114-
"""Toggle the display of the menu."""
115-
menu = self.query_one("#menu")
116-
menu.visible = not menu.visible
103+
def action_show_help(self):
104+
self.notify(title="Hello World!", message=self.help_text, timeout=30)
105+
106+
@on(Select.Changed)
107+
async def view_select(self, event: Select.Changed):
108+
selected_exercise = EXERCISES_DIR / f"{event.value}.md"
109+
self.current_markdown_path = selected_exercise
110+
markdown_viewer = self.query_one("#markdown_viewer", MarkdownViewer)
111+
await markdown_viewer.go(selected_exercise)
112+
self.query_one("#content").display = True
117113

118114

119115
if __name__ == "__main__":

0 commit comments

Comments
 (0)