11use crate :: game:: challenge:: Challenge ;
2- use crate :: Result ;
2+ use crate :: { extractor :: GitRepositoryInfo , Result } ;
33use crossterm:: {
44 cursor:: MoveTo ,
55 event:: { self , Event , KeyCode , KeyModifiers } ,
@@ -17,49 +17,28 @@ impl CountdownScreen {
1717 }
1818
1919 pub fn show_with_challenge ( challenge : Option < & Challenge > ) -> Result < ( ) > {
20+ Self :: show_with_challenge_and_repo ( challenge, & None )
21+ }
22+
23+ pub fn show_with_challenge_and_repo (
24+ challenge : Option < & Challenge > ,
25+ repo_info : & Option < GitRepositoryInfo > ,
26+ ) -> Result < ( ) > {
2027 let mut stdout = stdout ( ) ;
2128 let ( terminal_width, terminal_height) = terminal:: size ( ) ?;
2229 let center_row = terminal_height / 2 ;
2330 let center_col = terminal_width / 2 ;
2431
25- // Show source info if available
26- if let Some ( challenge) = challenge {
27- if let Some ( ref path) = challenge. source_file_path {
28- let source_msg =
29- if let ( Some ( start) , Some ( end) ) = ( challenge. start_line , challenge. end_line ) {
30- format ! ( "Source: {}:{}-{}" , path, start, end)
31- } else {
32- format ! ( "Source: {}" , path)
33- } ;
34- let source_col = center_col. saturating_sub ( source_msg. len ( ) as u16 / 2 ) ;
35- execute ! ( stdout, MoveTo ( source_col, center_row - 4 ) ) ?;
36- execute ! ( stdout, SetForegroundColor ( Color :: Cyan ) ) ?;
37- execute ! ( stdout, Print ( & source_msg) ) ?;
38- execute ! ( stdout, ResetColor ) ?;
39- }
40- }
32+ // Show source and repository info if available
33+ Self :: draw_source_and_repo_info ( & mut stdout, center_row, center_col, challenge, repo_info) ?;
4134
4235 // Show "Get Ready!" message
4336 let ready_msg = "Get Ready!" ;
4437 let ready_col = center_col. saturating_sub ( ready_msg. len ( ) as u16 / 2 ) ;
4538 execute ! ( stdout, terminal:: Clear ( ClearType :: All ) ) ?;
4639
47- // Show source again after clear
48- if let Some ( challenge) = challenge {
49- if let Some ( ref path) = challenge. source_file_path {
50- let source_msg =
51- if let ( Some ( start) , Some ( end) ) = ( challenge. start_line , challenge. end_line ) {
52- format ! ( "Source: {}:{}-{}" , path, start, end)
53- } else {
54- format ! ( "Source: {}" , path)
55- } ;
56- let source_col = center_col. saturating_sub ( source_msg. len ( ) as u16 / 2 ) ;
57- execute ! ( stdout, MoveTo ( source_col, center_row - 4 ) ) ?;
58- execute ! ( stdout, SetForegroundColor ( Color :: Cyan ) ) ?;
59- execute ! ( stdout, Print ( & source_msg) ) ?;
60- execute ! ( stdout, ResetColor ) ?;
61- }
62- }
40+ // Show source and repository info again after clear
41+ Self :: draw_source_and_repo_info ( & mut stdout, center_row, center_col, challenge, repo_info) ?;
6342
6443 execute ! ( stdout, MoveTo ( ready_col, center_row - 2 ) ) ?;
6544 execute ! (
@@ -77,23 +56,14 @@ impl CountdownScreen {
7756 for count in ( 1 ..=3 ) . rev ( ) {
7857 execute ! ( stdout, terminal:: Clear ( ClearType :: All ) ) ?;
7958
80- // Show source info if available
81- if let Some ( challenge) = challenge {
82- if let Some ( ref path) = challenge. source_file_path {
83- let source_msg = if let ( Some ( start) , Some ( end) ) =
84- ( challenge. start_line , challenge. end_line )
85- {
86- format ! ( "Source: {}:{}-{}" , path, start, end)
87- } else {
88- format ! ( "Source: {}" , path)
89- } ;
90- let source_col = center_col. saturating_sub ( source_msg. len ( ) as u16 / 2 ) ;
91- execute ! ( stdout, MoveTo ( source_col, center_row - 4 ) ) ?;
92- execute ! ( stdout, SetForegroundColor ( Color :: Cyan ) ) ?;
93- execute ! ( stdout, Print ( & source_msg) ) ?;
94- execute ! ( stdout, ResetColor ) ?;
95- }
96- }
59+ // Show source and repository info if available
60+ Self :: draw_source_and_repo_info (
61+ & mut stdout,
62+ center_row,
63+ center_col,
64+ challenge,
65+ repo_info,
66+ ) ?;
9767
9868 // Show "Get Ready!" message
9969 execute ! ( stdout, MoveTo ( ready_col, center_row - 2 ) ) ?;
@@ -128,6 +98,7 @@ impl CountdownScreen {
12898
12999 // Show "GO!" message
130100 execute ! ( stdout, terminal:: Clear ( ClearType :: All ) ) ?;
101+
131102 let go_msg = "GO!" ;
132103 let go_col = center_col. saturating_sub ( go_msg. len ( ) as u16 / 2 ) ;
133104 execute ! ( stdout, MoveTo ( go_col, center_row) ) ?;
@@ -153,50 +124,36 @@ impl CountdownScreen {
153124 stage_number : usize ,
154125 total_stages : usize ,
155126 challenge : Option < & Challenge > ,
127+ ) -> Result < ( ) > {
128+ Self :: show_stage_transition_with_challenge_and_repo (
129+ stage_number,
130+ total_stages,
131+ challenge,
132+ & None ,
133+ )
134+ }
135+
136+ pub fn show_stage_transition_with_challenge_and_repo (
137+ stage_number : usize ,
138+ total_stages : usize ,
139+ challenge : Option < & Challenge > ,
140+ repo_info : & Option < GitRepositoryInfo > ,
156141 ) -> Result < ( ) > {
157142 let mut stdout = stdout ( ) ;
158143 let ( terminal_width, terminal_height) = terminal:: size ( ) ?;
159144 let center_row = terminal_height / 2 ;
160145 let center_col = terminal_width / 2 ;
161146
162- // Show source info if available
163- if let Some ( challenge) = challenge {
164- if let Some ( ref path) = challenge. source_file_path {
165- let source_msg =
166- if let ( Some ( start) , Some ( end) ) = ( challenge. start_line , challenge. end_line ) {
167- format ! ( "Source: {}:{}-{}" , path, start, end)
168- } else {
169- format ! ( "Source: {}" , path)
170- } ;
171- let source_col = center_col. saturating_sub ( source_msg. len ( ) as u16 / 2 ) ;
172- execute ! ( stdout, MoveTo ( source_col, center_row - 4 ) ) ?;
173- execute ! ( stdout, SetForegroundColor ( Color :: Cyan ) ) ?;
174- execute ! ( stdout, Print ( & source_msg) ) ?;
175- execute ! ( stdout, ResetColor ) ?;
176- }
177- }
147+ // Show source and repository info if available
148+ Self :: draw_source_and_repo_info ( & mut stdout, center_row, center_col, challenge, repo_info) ?;
178149
179150 // Show "Next Stage" message
180151 let stage_text = format ! ( "Stage {} / {}" , stage_number, total_stages) ;
181152 let stage_col = center_col. saturating_sub ( stage_text. len ( ) as u16 / 2 ) ;
182153 execute ! ( stdout, terminal:: Clear ( ClearType :: All ) ) ?;
183154
184- // Show source again after clear
185- if let Some ( challenge) = challenge {
186- if let Some ( ref path) = challenge. source_file_path {
187- let source_msg =
188- if let ( Some ( start) , Some ( end) ) = ( challenge. start_line , challenge. end_line ) {
189- format ! ( "Source: {}:{}-{}" , path, start, end)
190- } else {
191- format ! ( "Source: {}" , path)
192- } ;
193- let source_col = center_col. saturating_sub ( source_msg. len ( ) as u16 / 2 ) ;
194- execute ! ( stdout, MoveTo ( source_col, center_row - 4 ) ) ?;
195- execute ! ( stdout, SetForegroundColor ( Color :: Cyan ) ) ?;
196- execute ! ( stdout, Print ( & source_msg) ) ?;
197- execute ! ( stdout, ResetColor ) ?;
198- }
199- }
155+ // Show source and repository info again after clear
156+ Self :: draw_source_and_repo_info ( & mut stdout, center_row, center_col, challenge, repo_info) ?;
200157
201158 execute ! ( stdout, MoveTo ( stage_col, center_row - 2 ) ) ?;
202159 execute ! (
@@ -214,23 +171,14 @@ impl CountdownScreen {
214171 for count in ( 1 ..=3 ) . rev ( ) {
215172 execute ! ( stdout, terminal:: Clear ( ClearType :: All ) ) ?;
216173
217- // Show source info if available
218- if let Some ( challenge) = challenge {
219- if let Some ( ref path) = challenge. source_file_path {
220- let source_msg = if let ( Some ( start) , Some ( end) ) =
221- ( challenge. start_line , challenge. end_line )
222- {
223- format ! ( "Source: {}:{}-{}" , path, start, end)
224- } else {
225- format ! ( "Source: {}" , path)
226- } ;
227- let source_col = center_col. saturating_sub ( source_msg. len ( ) as u16 / 2 ) ;
228- execute ! ( stdout, MoveTo ( source_col, center_row - 4 ) ) ?;
229- execute ! ( stdout, SetForegroundColor ( Color :: Cyan ) ) ?;
230- execute ! ( stdout, Print ( & source_msg) ) ?;
231- execute ! ( stdout, ResetColor ) ?;
232- }
233- }
174+ // Show source and repository info if available
175+ Self :: draw_source_and_repo_info (
176+ & mut stdout,
177+ center_row,
178+ center_col,
179+ challenge,
180+ repo_info,
181+ ) ?;
234182
235183 // Show stage number
236184 execute ! ( stdout, MoveTo ( stage_col, center_row - 2 ) ) ?;
@@ -265,6 +213,7 @@ impl CountdownScreen {
265213
266214 // Show "START!" message
267215 execute ! ( stdout, terminal:: Clear ( ClearType :: All ) ) ?;
216+
268217 let start_msg = "START!" ;
269218 let start_col = center_col. saturating_sub ( start_msg. len ( ) as u16 / 2 ) ;
270219 execute ! ( stdout, MoveTo ( start_col, center_row) ) ?;
@@ -300,4 +249,45 @@ impl CountdownScreen {
300249 }
301250 Ok ( ( ) )
302251 }
252+
253+ fn draw_source_and_repo_info (
254+ stdout : & mut std:: io:: Stdout ,
255+ center_row : u16 ,
256+ center_col : u16 ,
257+ challenge : Option < & Challenge > ,
258+ repo_info : & Option < GitRepositoryInfo > ,
259+ ) -> Result < ( ) > {
260+ if let Some ( challenge) = challenge {
261+ if challenge. source_file_path . is_some ( ) {
262+ // Show "Source:" label in Cyan
263+ let source_label = "Source:" ;
264+ let source_label_col = center_col. saturating_sub ( source_label. len ( ) as u16 / 2 ) ;
265+ execute ! ( stdout, MoveTo ( source_label_col, center_row - 6 ) ) ?;
266+ execute ! ( stdout, SetForegroundColor ( Color :: Cyan ) ) ?;
267+ execute ! ( stdout, Print ( source_label) ) ?;
268+ execute ! ( stdout, ResetColor ) ?;
269+
270+ // Show repository info in brackets if available, in DarkGrey
271+ if let Some ( repo) = repo_info {
272+ let repo_msg = format ! ( "[{}/{}]" , repo. user_name, repo. repository_name) ;
273+ let repo_col = center_col. saturating_sub ( repo_msg. len ( ) as u16 / 2 ) ;
274+ execute ! ( stdout, MoveTo ( repo_col, center_row - 5 ) ) ?;
275+ execute ! ( stdout, SetForegroundColor ( Color :: DarkGrey ) ) ?;
276+ execute ! ( stdout, Print ( & repo_msg) ) ?;
277+ execute ! ( stdout, ResetColor ) ?;
278+ }
279+
280+ // Show source file:line info in DarkGrey
281+ let source_file = challenge. get_display_title ( ) ;
282+ let source_col = center_col. saturating_sub ( source_file. len ( ) as u16 / 2 ) ;
283+ execute ! ( stdout, MoveTo ( source_col, center_row - 4 ) ) ?;
284+ execute ! ( stdout, SetForegroundColor ( Color :: DarkGrey ) ) ?;
285+ execute ! ( stdout, Print ( & source_file) ) ?;
286+ execute ! ( stdout, ResetColor ) ?;
287+
288+ // Add blank line after source info (center_row - 3 is now blank)
289+ }
290+ }
291+ Ok ( ( ) )
292+ }
303293}
0 commit comments