aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-01-29 22:30:58 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-01-29 22:35:44 +0100
commitb4cc152c778c9f21f1e0a151b9d29760fbbf1476 (patch)
treefae0310211143734fee5182a6a90365860ad9b19
parentea33d92514c809a2efaa9940ce05a5765f3cb41c (diff)
downloadmihi-b4cc152c778c9f21f1e0a151b9d29760fbbf1476.tar.gz
mihi-b4cc152c778c9f21f1e0a151b9d29760fbbf1476.zip
exercises: simplify the kind
As for now, all exercises I have follow the same pattern and there can be multiple workflows that can fit to it. Yes, maybe in the future it might be interesting to add other kinds of exercises, but for now I'm good and we can keep things simple. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--crates/cli/src/exercises.rs15
-rw-r--r--crates/cli/src/run.rs21
-rw-r--r--lib/mihi/src/exercise.rs22
3 files changed, 16 insertions, 42 deletions
diff --git a/crates/cli/src/exercises.rs b/crates/cli/src/exercises.rs
index ef89a0c..8cac7b0 100644
--- a/crates/cli/src/exercises.rs
+++ b/crates/cli/src/exercises.rs
@@ -37,19 +37,6 @@ fn ask_for_exercise_based_on(exercise: Exercise) -> Result<Exercise, String> {
return Err("the title is required".to_string());
}
- let kinds = vec![
- ExerciseKind::Pensum,
- ExerciseKind::Translation,
- ExerciseKind::Transformation,
- ExerciseKind::Numerical,
- ];
- let Ok(kind) = Select::new("Kind:", kinds)
- .with_starting_cursor(exercise.kind as usize)
- .prompt()
- else {
- return Err("abort!".to_string());
- };
-
let Ok(enunciate) = Editor::new("Enunciate:")
.with_predefined_text(&exercise.enunciate)
.with_file_extension(".md")
@@ -89,7 +76,7 @@ fn ask_for_exercise_based_on(exercise: Exercise) -> Result<Exercise, String> {
enunciate,
solution,
lessons,
- kind,
+ kind: ExerciseKind::Simple,
})
}
diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs
index 86136aa..5f06870 100644
--- a/crates/cli/src/run.rs
+++ b/crates/cli/src/run.rs
@@ -508,18 +508,17 @@ fn run_exercises(exercises: Vec<Exercise>) -> bool {
}
for exercise in exercises {
- let Ok(solution) = Editor::new(
- format!("Exercise '{}' (kind: {}):", exercise.title, exercise.kind).as_str(),
- )
- .with_predefined_text(
- format!(
- "---Enunciate: {}\n{}\n---!",
- exercise.title, exercise.enunciate
+ let Ok(solution) = Editor::new(format!("Exercise '{}':", exercise.title).as_str())
+ .with_predefined_text(
+ format!(
+ "---Enunciate: {}\n{}\n---!",
+ exercise.title, exercise.enunciate
+ )
+ .as_str(),
)
- .as_str(),
- )
- .with_file_extension(".md")
- .prompt() else {
+ .with_file_extension(".md")
+ .prompt()
+ else {
return false;
};
diff --git a/lib/mihi/src/exercise.rs b/lib/mihi/src/exercise.rs
index 10fada1..5f45079 100644
--- a/lib/mihi/src/exercise.rs
+++ b/lib/mihi/src/exercise.rs
@@ -5,19 +5,13 @@ use rusqlite::params;
#[derive(Clone, Copy, Debug, Default)]
pub enum ExerciseKind {
#[default]
- Pensum = 0,
- Translation,
- Transformation,
- Numerical,
+ Simple = 0,
}
impl std::fmt::Display for ExerciseKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
- Self::Pensum => write!(f, "Pensum"),
- Self::Translation => write!(f, "Translation"),
- Self::Transformation => write!(f, "Transformation"),
- Self::Numerical => write!(f, "Numerical"),
+ Self::Simple => write!(f, "Simple"),
}
}
}
@@ -27,10 +21,7 @@ impl TryFrom<isize> for ExerciseKind {
fn try_from(value: isize) -> Result<Self, Self::Error> {
match value {
- 0 => Ok(Self::Pensum),
- 1 => Ok(Self::Translation),
- 2 => Ok(Self::Transformation),
- 3 => Ok(Self::Numerical),
+ 0 => Ok(Self::Simple),
_ => Err("unknonwn exercise kind"),
}
}
@@ -41,11 +32,8 @@ impl TryFrom<&str> for ExerciseKind {
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
- "pensum" => Ok(Self::Pensum),
- "translation" => Ok(Self::Translation),
- "transformation" => Ok(Self::Transformation),
- "numerical" => Ok(Self::Numerical),
- _ => Err("unknonwn exercise kind. Available: pensum, translation, transformation and numerical"),
+ "simple" => Ok(Self::Simple),
+ _ => Err("unknonwn exercise kind. Available: simple"),
}
}
}