Skip to content

Commit

Permalink
Fix naughty behavior on windows
Browse files Browse the repository at this point in the history
naughty behavior includes:
- crashing
- not working
- being annoying to use
  • Loading branch information
rpitasky committed Jan 5, 2025
1 parent da69a1e commit 6b4ac82
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 55 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
deku = "0.18.1"
edit = "0.1.5"
fancy-regex = "0.14.0"
fuzzy-matcher = "0.3.7"
inquire = { version = "0.7.5", features = ["editor"] }
Expand Down
25 changes: 9 additions & 16 deletions src/cemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,17 @@ impl TestRunner {
let folder = tempfile::tempdir().map_err(TestError::Io)?;
let folder_path = folder.path();

let autotester_config_path = self.initialize_cemu_test(
&folder_path.canonicalize().map_err(TestError::Io)?,
program,
inputs,
outputs,
)?;
let autotester_config_path =
self.initialize_cemu_test(folder_path, program, inputs, outputs)?;

let autotester_path = if cfg!(debug_assertions) {
let autotester_path =
env::current_dir()
} else {
env::current_exe()
}
.map_err(TestError::Io)?
.join(if cfg!(target_os = "windows") {
"autotester.exe"
} else {
"autotester"
});
.map_err(TestError::Io)?
.join(if cfg!(target_os = "windows") {
"autotester.exe"
} else {
"autotester"
});

let cemu_status = Command::new(autotester_path)
.arg(&autotester_config_path)
Expand Down
77 changes: 38 additions & 39 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::{
fs, io,
};

use edit::edit;
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
use inquire::{
validator::{StringValidator, Validation},
Autocomplete, Confirm, CustomUserError, Editor, Select, Text,
Autocomplete, Confirm, CustomUserError, Select, Text,
};
use markdown::mdast::{Code, Node};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -191,51 +192,49 @@ impl UserInterface {
+ &lesson_data.starting_program
});

let result = Editor::new(&savings_message)
.with_predefined_text(&boilerplate)
.with_file_extension(".8xp.txt")
.prompt();

if let Ok(raw_text) = result {
if raw_text.trim() == "" {
return;
}
if let Ok(true) = Confirm::new("Would you like to open your attempt?").with_default(true).prompt() {
let result = edit(boilerplate);
if let Ok(raw_text) = result {
if raw_text.trim() == "" {
return;
}

self.save.attempts.insert(lesson_id, raw_text.clone());
self.save.attempts.insert(lesson_id, raw_text.clone());

let tokens_struct = process_submission(raw_text);
let tokens = tokens_struct.clone().collect::<Vec<_>>();
let byte_count: usize = byte_count(&tokens);
let tokens_struct = process_submission(raw_text);
let tokens = tokens_struct.clone().collect::<Vec<_>>();
let byte_count: usize = byte_count(&tokens);

println!("{} tokens, {} bytes.", tokens.len(), byte_count);
println!("{} tokens, {} bytes.", tokens.len(), byte_count);

let byte_threshold = lesson_data.byte_threshold();
if byte_count > byte_threshold {
println!("Too large: target is {} bytes", byte_threshold);
self.last_attempt = Some(lesson_id);
} else {
println!("Testing...");
match self
.test_runner
.run_tests(tokens_struct, &lesson_data.tests)
{
Err(test_error) => {
eprintln!("{}", test_error);
std::process::exit(1)
}

Ok(ProgramTestResult::Fail(reason)) => {
println!("{}", reason);
self.last_attempt = Some(lesson_id);
}
Ok(ProgramTestResult::Pass) => {
self.complete_lesson(lesson_id);
self.last_attempt = None;
let byte_threshold = lesson_data.byte_threshold();
if byte_count > byte_threshold {
println!("Too large: target is {} bytes", byte_threshold);
self.last_attempt = Some(lesson_id);
} else {
println!("Testing...");
match self
.test_runner
.run_tests(tokens_struct, &lesson_data.tests)
{
Err(test_error) => {
eprintln!("{}", test_error);
std::process::exit(1)
}

Ok(ProgramTestResult::Fail(reason)) => {
println!("{}", reason);
self.last_attempt = Some(lesson_id);
}
Ok(ProgramTestResult::Pass) => {
self.complete_lesson(lesson_id);
self.last_attempt = None;
}
}
}
}

self.save();
self.save();
}
}
}

Expand Down

0 comments on commit 6b4ac82

Please sign in to comment.