@@ -17,31 +17,55 @@ class CompileScreen(Screen):
17
17
# Child process running the libraries compilation
18
18
child_process = None
19
19
20
- def print_output (self , renderable : RenderableType ) -> None :
20
+ log_widget : RichLog
21
+ button_widget : Button
22
+
23
+ def print_output (self , renderable : RenderableType , style = None ) -> None :
21
24
# Print output to the RichLog widget
22
- self .query_one (RichLog ).write (renderable )
25
+ if style is None :
26
+ self .log_widget .write (renderable )
27
+ else :
28
+ # Check the available styles at https://rich.readthedocs.io/en/stable/style.html
29
+ self .log_widget .write ("[" + str (style ) + "]" + renderable )
30
+
31
+ def print_error (self , error : str ) -> None :
32
+ # Print error to the RichLog widget
33
+ self .log_widget .write ("[b bright_red]" + error )
34
+ self .button_widget .add_class ("-error" )
35
+ #print("Error: " + error) # For debugging
36
+
37
+ def print_success (self , message : str ) -> None :
38
+ # Print success message to the RichLog widget
39
+ self .log_widget .write ("[b bright_green]" + message )
40
+ self .button_widget .add_class ("-success" )
41
+ #print("Success: " + message) # For debugging
42
+
43
+ def print_info (self , message : str ) -> None :
44
+ # Print info message to the RichLog widget
45
+ self .log_widget .write ("[b bright_cyan]" + message )
46
+ #print("Info: " + message) # For debugging
23
47
24
48
@work (name = "compliation_worker" , group = "compilation" , exclusive = True , thread = True )
25
49
def compile_libs (self ) -> None :
26
50
# Compile the libraries
51
+ print ("Starting compilation process" )
27
52
28
53
label = self .query_one ("#compile-title" , Static )
29
54
self .child_process = None
30
55
target = self .app .setting_target
31
56
32
- print ("Compiling for " + target .upper ())
33
57
label .update ("Compiling for " + target .upper ())
34
- self .print_output ("======== Compiling for " + target .upper () + " ========" )
58
+ self .print_info ("======== Compiling for " + target .upper () + " ========" )
35
59
36
60
command = ["./build.sh" , "-t" , target , "-D" , self .app .setting_debug_level ]
61
+
37
62
#command.append("--help") # For testing output without compiling
38
63
39
64
if self .app .setting_enable_copy :
40
65
if os .path .isdir (self .app .setting_arduino_path ):
41
66
command .extend (["-c" , self .app .setting_arduino_path ])
42
67
else :
43
- print ("Invalid path to Arduino core: " + self .app .setting_arduino_path )
44
- self .print_output ("Invalid path to Arduino core: " + self .app .setting_arduino_path )
68
+ self .print_error ("Invalid path to Arduino core: " + self .app .setting_arduino_path )
45
69
label .update ("Invalid path to Arduino core" )
46
70
return
47
71
@@ -54,8 +78,7 @@ def compile_libs(self) -> None:
54
78
if self .app .setting_idf_commit :
55
79
command .extend (["-i" , self .app .setting_idf_commit ])
56
80
57
- self .print_output ("Running: " + " " .join (command ) + "\n " )
58
- print ("Running: " + " " .join (command ))
81
+ self .print_info ("Running: " + " " .join (command ) + "\n " )
59
82
self .child_process = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
60
83
try :
61
84
for output in self .child_process .stdout :
@@ -69,19 +92,25 @@ def compile_libs(self) -> None:
69
92
print ("Process might have terminated" )
70
93
71
94
if not self .child_process :
72
- print ("Compilation failed for " + target .upper () + "Child process failed to start" )
95
+ self . print_error ("Compilation failed for " + target .upper () + "Child process failed to start" )
73
96
label .update ("Compilation failed for " + target .upper () + "Child process failed to start" )
74
97
return
75
98
else :
76
99
self .child_process .wait ()
77
100
78
101
if self .child_process .returncode != 0 :
79
- print ("Compilation failed for " + target .upper () + ". Return code: " + str (self .child_process .returncode ))
80
- self .print_output ("Compilation failed for " + target .upper () + ". Return code: " + str (self .child_process .returncode ))
81
- self .print_output ("Error: " + self .child_process .stderr .read ())
102
+ self .print_error ("Compilation failed for " + target .upper () + ". Return code: " + str (self .child_process .returncode ))
103
+ self .print_error ("Errors:" )
104
+ try :
105
+ for error in self .child_process .stderr :
106
+ if error :
107
+ self .print_error (error .strip ())
108
+ self .child_process .stderr .close ()
109
+ except Exception as e :
110
+ print ("Error reading child process errors: " + str (e ))
82
111
label .update ("Compilation failed for " + target .upper ())
83
112
else :
84
- print ("Compilation successful for " + target .upper ())
113
+ self . print_success ("Compilation successful for " + target .upper ())
85
114
label .update ("Compilation successful for " + target .upper ())
86
115
87
116
def on_button_pressed (self , event : Button .Pressed ) -> None :
@@ -103,16 +132,19 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
103
132
def on_resume (self ) -> None :
104
133
# Event handler called every time the screen is activated
105
134
print ("Compile screen resumed. Clearing logs and starting compilation process" )
106
- log = self .query_one (RichLog )
107
- log .clear ()
108
- log .focus ()
135
+ self .button_widget .remove_class ("-error" )
136
+ self .button_widget .remove_class ("-success" )
137
+ self .log_widget .clear ()
138
+ self .log_widget .focus ()
109
139
self .compile_libs ()
110
140
111
141
def compose (self ) -> ComposeResult :
112
142
# Compose the compilation screen
113
143
yield Header ()
114
144
with Container (id = "compile-log-container" ):
115
- yield RichLog (markup = True , id = "compile-log" )
145
+ self .log_widget = RichLog (markup = True , id = "compile-log" )
146
+ yield self .log_widget
116
147
with Container (id = "compile-status-container" ):
117
148
yield Static ("Compiling for ..." , id = "compile-title" )
118
- yield Button ("Back" , id = "compile-back-button" )
149
+ self .button_widget = Button ("Back" , id = "compile-back-button" )
150
+ yield self .button_widget
0 commit comments