public void RunAll(IInteractivity interactivity, IDictionary <String, Object> scope, Action <String> evaluate) { var snippets = GetAllTutorials(); interactivity.Write(Environment.NewLine); for (var i = 0; i < snippets.Count; i++) { var snippet = snippets[i]; WriteTitle(interactivity, i, snippet); WriteExample(interactivity, evaluate, snippet); WriteTask(interactivity, snippet); var success = TryToLearn(interactivity, scope, evaluate, snippet); if (success) { interactivity.Write("Great!"); interactivity.Write(Environment.NewLine); } else { WriteSolution(interactivity, evaluate, snippet); } } }
private Object PerformWrite(Object value) { var str = Stringify.This(value); _interactivity.Write(str); return(null); }
private static void WriteExample(IInteractivity interactivity, Action <String> evaluate, ITutorialSnippet snippet) { interactivity.Write("Example:"); interactivity.Write(Environment.NewLine); interactivity.Write("SWM> "); interactivity.Write(snippet.ExampleCommand); interactivity.Write(Environment.NewLine); evaluate.Invoke(snippet.ExampleCommand); }
public void Tutorial(ITutorialRunner tutorials) { Startup(); _interactivity.Write("Welcome to MAGES! Press ENTER to to start the interactive tutorial ..."); _interactivity.ReadLine(); tutorials.RunAll(_interactivity, _engine.Scope, input => Evaluate(input, true)); Teardown(); }
private static void WriteSolution(IInteractivity interactivity, Action <String> evaluate, ITutorialSnippet snippet) { interactivity.Write("Solution:"); interactivity.Write(Environment.NewLine); interactivity.WritePrompt(); interactivity.Write(snippet.Solution); interactivity.Write(Environment.NewLine); evaluate.Invoke(snippet.Solution); interactivity.Write(Environment.NewLine); }
public void Tutorial() { Startup(); _interactivity.IsPromptShown = false; _interactivity.Write("Welcome to MAGES! Press ENTER to to start the interactive tutorial ..."); _interactivity.Read(); _interactivity.IsPromptShown = true; Tutorials.RunAll(_interactivity, _engine.Scope, input => Evaluate(input, true)); Teardown(); }
private static void WriteTitle(IInteractivity interactivity, Int32 index, ITutorialSnippet snippet) { var nr = index + 1; interactivity.Write("#" + nr + " " + snippet.Title); interactivity.Write(Environment.NewLine); interactivity.Write(Environment.NewLine); interactivity.Write(snippet.Description); interactivity.Write(Environment.NewLine); interactivity.Write(Environment.NewLine); }
private static Boolean TryToLearn(IInteractivity interactivity, IDictionary <String, Object> scope, Action <String> evaluate, ITutorialSnippet snippet) { var hints = snippet.Hints.GetEnumerator(); var success = true; do { if (!success) { interactivity.Info(hints.Current); interactivity.Write(Environment.NewLine); } var input = interactivity.ReadLine(); evaluate.Invoke(input); success = snippet.Check(scope); }while (!success && hints.MoveNext()); return(success); }
private static void WriteTask(IInteractivity interactivity, ITutorialSnippet snippet) { interactivity.Write("Your task: "); interactivity.Write(snippet.Task); interactivity.Write(Environment.NewLine); }