@@ -3,10 +3,11 @@ use std::{
33 fs, io,
44} ;
55
6+ use edit:: edit;
67use fuzzy_matcher:: { skim:: SkimMatcherV2 , FuzzyMatcher } ;
78use inquire:: {
89 validator:: { StringValidator , Validation } ,
9- Autocomplete , Confirm , CustomUserError , Editor , Select , Text ,
10+ Autocomplete , Confirm , CustomUserError , Select , Text ,
1011} ;
1112use markdown:: mdast:: { Code , Node } ;
1213use serde:: { Deserialize , Serialize } ;
@@ -191,51 +192,49 @@ impl UserInterface {
191192 + & lesson_data. starting_program
192193 } ) ;
193194
194- let result = Editor :: new ( & savings_message)
195- . with_predefined_text ( & boilerplate)
196- . with_file_extension ( ".8xp.txt" )
197- . prompt ( ) ;
198-
199- if let Ok ( raw_text) = result {
200- if raw_text. trim ( ) == "" {
201- return ;
202- }
195+ if let Ok ( true ) = Confirm :: new ( "Would you like to open your attempt?" ) . with_default ( true ) . prompt ( ) {
196+ let result = edit ( boilerplate) ;
197+ if let Ok ( raw_text) = result {
198+ if raw_text. trim ( ) == "" {
199+ return ;
200+ }
203201
204- self . save . attempts . insert ( lesson_id, raw_text. clone ( ) ) ;
202+ self . save . attempts . insert ( lesson_id, raw_text. clone ( ) ) ;
205203
206- let tokens_struct = process_submission ( raw_text) ;
207- let tokens = tokens_struct. clone ( ) . collect :: < Vec < _ > > ( ) ;
208- let byte_count: usize = byte_count ( & tokens) ;
204+ let tokens_struct = process_submission ( raw_text) ;
205+ let tokens = tokens_struct. clone ( ) . collect :: < Vec < _ > > ( ) ;
206+ let byte_count: usize = byte_count ( & tokens) ;
209207
210- println ! ( "{} tokens, {} bytes." , tokens. len( ) , byte_count) ;
208+ println ! ( "{} tokens, {} bytes." , tokens. len( ) , byte_count) ;
211209
212- let byte_threshold = lesson_data. byte_threshold ( ) ;
213- if byte_count > byte_threshold {
214- println ! ( "Too large: target is {} bytes" , byte_threshold) ;
215- self . last_attempt = Some ( lesson_id) ;
216- } else {
217- println ! ( "Testing..." ) ;
218- match self
219- . test_runner
220- . run_tests ( tokens_struct, & lesson_data. tests )
221- {
222- Err ( test_error) => {
223- eprintln ! ( "{}" , test_error) ;
224- std:: process:: exit ( 1 )
225- }
226-
227- Ok ( ProgramTestResult :: Fail ( reason) ) => {
228- println ! ( "{}" , reason) ;
229- self . last_attempt = Some ( lesson_id) ;
230- }
231- Ok ( ProgramTestResult :: Pass ) => {
232- self . complete_lesson ( lesson_id) ;
233- self . last_attempt = None ;
210+ let byte_threshold = lesson_data. byte_threshold ( ) ;
211+ if byte_count > byte_threshold {
212+ println ! ( "Too large: target is {} bytes" , byte_threshold) ;
213+ self . last_attempt = Some ( lesson_id) ;
214+ } else {
215+ println ! ( "Testing..." ) ;
216+ match self
217+ . test_runner
218+ . run_tests ( tokens_struct, & lesson_data. tests )
219+ {
220+ Err ( test_error) => {
221+ eprintln ! ( "{}" , test_error) ;
222+ std:: process:: exit ( 1 )
223+ }
224+
225+ Ok ( ProgramTestResult :: Fail ( reason) ) => {
226+ println ! ( "{}" , reason) ;
227+ self . last_attempt = Some ( lesson_id) ;
228+ }
229+ Ok ( ProgramTestResult :: Pass ) => {
230+ self . complete_lesson ( lesson_id) ;
231+ self . last_attempt = None ;
232+ }
234233 }
235234 }
236- }
237235
238- self . save ( ) ;
236+ self . save ( ) ;
237+ }
239238 }
240239 }
241240
0 commit comments