1
1
import subprocess
2
2
3
+ from textual import on
3
4
from textual .app import App , ComposeResult
4
5
from textual .containers import Container , Horizontal
5
6
from textual .widgets import Button , Footer , MarkdownViewer , Header , TextArea , Select , Label
@@ -15,10 +16,18 @@ class MarkdownApp(App):
15
16
CSS_PATH = "app.css"
16
17
BINDINGS = [
17
18
("t" , "toggle_table_of_contents" , "Toggle TOC" ),
18
- ("m " , "toggle_menu " , "Toggle Menu " ),
19
+ ("h " , "show_help " , "Show Help " ),
19
20
("q" , "quit" , "Quit" )
20
21
]
21
22
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] \n Refer to the project's README.md at https://github.com/sissues/cli/blob/main/README.MD,\n or open an issue at https://github.com/sissues/cli/issues
29
+ """
30
+
22
31
def __init__ (self ):
23
32
super ().__init__ ()
24
33
self .files_view_names = ExercisesUtils .generate_view_names_map ()
@@ -42,45 +51,26 @@ def compose(self) -> ComposeResult:
42
51
def on_mount (self ) -> None :
43
52
"""Initial setup when the app starts."""
44
53
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 )
53
55
54
56
def show_menu (self ) -> None :
55
57
menu = self .query_one ("#menu" )
56
58
menu .remove_children ()
57
59
58
60
exercises = list (EXERCISES_DIR .glob ("*.md" ))
59
61
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" )
61
63
62
64
menu .mount (select_file_widget )
63
- menu .mount (Button ("View" , id = "view" , variant = "primary" , classes = "menu_widget" ))
64
65
menu .mount (Button ("Start Project" , id = "start" , variant = "warning" , classes = "menu_widget" ))
65
66
menu .mount (Button ("Run Tests" , id = "test" , variant = "success" , classes = "menu_widget" ))
66
67
67
68
async def on_button_pressed (self , event : Button .Pressed ) -> None :
68
69
button_id = event .button .id
69
70
select_widget = self .query_one ("#exercise_select" , Select )
70
71
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
76
72
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" :
84
74
self .run_tests (exercise_name )
85
75
86
76
elif button_id == 'start' :
@@ -110,10 +100,16 @@ def action_toggle_table_of_contents(self) -> None:
110
100
markdown_viewer = self .query_one ("#markdown_viewer" , MarkdownViewer )
111
101
markdown_viewer .show_table_of_contents = not markdown_viewer .show_table_of_contents
112
102
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
117
113
118
114
119
115
if __name__ == "__main__" :
0 commit comments