From d66a0f37f2258fb53b5e26f0d4580f8d166abffa Mon Sep 17 00:00:00 2001 From: Dummi26 Date: Tue, 25 Apr 2023 15:15:03 +0200 Subject: [PATCH] tutor --- mers/src/tutor/base_values.rs | 2 +- mers/src/tutor/menu.rs | 27 +++++++++++++++++++-------- mers/src/tutor/mod.rs | 8 +++++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/mers/src/tutor/base_values.rs b/mers/src/tutor/base_values.rs index e709e84..5c772f0 100644 --- a/mers/src/tutor/base_values.rs +++ b/mers/src/tutor/base_values.rs @@ -21,7 +21,7 @@ pub fn run(tutor: &mut Tutor) { // thread: Represents a different thread. The thread's return value can be retrieved by using .await(). Thread values are returned by the builtin thread() function. // reference: A mutable reference to some data. Used by things like push() and remove() to avoid having to clone the entire list just to make a small change. // enums: An enum can wrap any type. Enums are identified by their names and can be created using EnumName: inner_value. The type is written EnumName(InnerType). -// return a value of type GoBackToMenu([int]) to return to the menu. +// return any enum to return to the menu. ")); loop { match tutor.let_user_make_change().run(vec![]).data { diff --git a/mers/src/tutor/menu.rs b/mers/src/tutor/menu.rs index 0758b46..a99cb90 100644 --- a/mers/src/tutor/menu.rs +++ b/mers/src/tutor/menu.rs @@ -2,7 +2,7 @@ use crate::script::val_data::VDataEnum; use super::Tutor; -pub const MAX_POS: usize = 3; +pub const MAX_POS: usize = 6; pub fn run(mut tutor: Tutor) { loop { @@ -11,26 +11,37 @@ pub fn run(mut tutor: Tutor) { " // Welcome to the mers tutor! // This is the main menu. Change the number to navigate to a specific part. -0 +fn go_to() 0 // 1 Comments -// 2 Values -// 3 Returns +// 2 Functions +// 3 Values +// 4 Variables +// 5 Returns +// 6 Types + +go_to() ", )); loop { match tutor.let_user_make_change().run(vec![]).data { - VDataEnum::Int(pos) => { + VDataEnum::Int(pos) if pos != 0 => { tutor.current_pos = (pos.max(0) as usize).min(MAX_POS); match tutor.current_pos { 0 => continue, 1 => super::base_comments::run(&mut tutor), - 2 => super::base_values::run(&mut tutor), - 3 => super::base_return::run(&mut tutor), + 2 => super::base_functions::run(&mut tutor), + 3 => super::base_values::run(&mut tutor), + 4 => super::base_variables::run(&mut tutor), + 5 => super::base_return::run(&mut tutor), + 6 => super::base_types::run(&mut tutor), _ => unreachable!(), } } other => { - tutor.set_status(format!(" - Returned {} instead of an integer", other)); + tutor.set_status(format!( + " - Returned {} instead of a nonzero integer", + other + )); } } break; diff --git a/mers/src/tutor/mod.rs b/mers/src/tutor/mod.rs index 199c2b1..143b56d 100644 --- a/mers/src/tutor/mod.rs +++ b/mers/src/tutor/mod.rs @@ -6,8 +6,11 @@ use crate::{ }; mod base_comments; +mod base_functions; mod base_return; +mod base_types; mod base_values; +mod base_variables; mod menu; pub fn start(spawn_new_terminal_for_editor: bool) { @@ -36,6 +39,7 @@ false editor_join_handle, file_path, receiver, + i_name: None, }; loop { if let VDataEnum::Bool(true) = tutor.let_user_make_change().run(vec![]).data { @@ -54,11 +58,13 @@ pub struct Tutor { editor_join_handle: JoinHandle<()>, file_path: PathBuf, receiver: std::sync::mpsc::Receiver>, + // i_ are inputs from the user + pub i_name: Option, } impl Tutor { /// only returns after a successful compile. before returning, does not call self.update() - you have to do that manually. pub fn let_user_make_change(&mut self) -> RScript { - // eprintln!(" - - - - - - - - - - - - - - - - - - - - - - - - -"); + eprintln!(" - - - - - - - - - - - - - - - - - - - - - - - - -"); let script = loop { match self.receiver.recv().unwrap() { Err(e) => {