Skip to content

Commit 6b4ac82

Browse files
committed
Fix naughty behavior on windows
naughty behavior includes: - crashing - not working - being annoying to use
1 parent da69a1e commit 6b4ac82

File tree

4 files changed

+86
-55
lines changed

4 files changed

+86
-55
lines changed

Cargo.lock

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
deku = "0.18.1"
8+
edit = "0.1.5"
89
fancy-regex = "0.14.0"
910
fuzzy-matcher = "0.3.7"
1011
inquire = { version = "0.7.5", features = ["editor"] }

src/cemu.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,24 +271,17 @@ impl TestRunner {
271271
let folder = tempfile::tempdir().map_err(TestError::Io)?;
272272
let folder_path = folder.path();
273273

274-
let autotester_config_path = self.initialize_cemu_test(
275-
&folder_path.canonicalize().map_err(TestError::Io)?,
276-
program,
277-
inputs,
278-
outputs,
279-
)?;
274+
let autotester_config_path =
275+
self.initialize_cemu_test(folder_path, program, inputs, outputs)?;
280276

281-
let autotester_path = if cfg!(debug_assertions) {
277+
let autotester_path =
282278
env::current_dir()
283-
} else {
284-
env::current_exe()
285-
}
286-
.map_err(TestError::Io)?
287-
.join(if cfg!(target_os = "windows") {
288-
"autotester.exe"
289-
} else {
290-
"autotester"
291-
});
279+
.map_err(TestError::Io)?
280+
.join(if cfg!(target_os = "windows") {
281+
"autotester.exe"
282+
} else {
283+
"autotester"
284+
});
292285

293286
let cemu_status = Command::new(autotester_path)
294287
.arg(&autotester_config_path)

src/cli.rs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use std::{
33
fs, io,
44
};
55

6+
use edit::edit;
67
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
78
use inquire::{
89
validator::{StringValidator, Validation},
9-
Autocomplete, Confirm, CustomUserError, Editor, Select, Text,
10+
Autocomplete, Confirm, CustomUserError, Select, Text,
1011
};
1112
use markdown::mdast::{Code, Node};
1213
use 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

Comments
 (0)