From 13ff174aaa9244d2870588d3bfccf480f42662c7 Mon Sep 17 00:00:00 2001 From: BOTAlex Date: Sun, 14 Jul 2024 02:13:46 +0200 Subject: [PATCH] Working repl version online --- OpenBirchWebsite/Pages/Home.razor | 104 ++++++++++++++++++++++---- OpenBirchWebsite/Pages/Home.razor.css | 12 +++ 2 files changed, 103 insertions(+), 13 deletions(-) diff --git a/OpenBirchWebsite/Pages/Home.razor b/OpenBirchWebsite/Pages/Home.razor index b6e6cc1..c7445c7 100644 --- a/OpenBirchWebsite/Pages/Home.razor +++ b/OpenBirchWebsite/Pages/Home.razor @@ -6,37 +6,115 @@
Welcome to
OpenBirch!!!
-
-
- -
+
+ +
+ @for (int i = 0; i < consoleHistory.Count; i++) + { + int temp = i; + @((consoleHistory[temp].source == ConsoleSource.User) ? ">" : "#") @consoleHistory[temp].text + } +
+ +
@code { - public string temp = " "; + public string inputField = " "; public bool hasInteracted = false; // Has the user interacted with the input field? + readonly string[] exampleInputs = { + "2+2;", + "69*420+50;", + "sin(2+4);", + "sqrt(9);", + "nroot(27, 3);", + "f(x):=2*x;", + "f(5);", + "pi;", + "e;", + "myvar := 5;", + "15 + myvar;", + "myfunctionvar := f;", + "myfunctionvar(10);", + "d/dx x;", + "d/dx x^2;", + "d/dx 69*x^2;", + "d/dx sin(x)*x^2;" + }; + + private void print(string e) + { + Console.WriteLine(e); + } + + public struct consoleLine + { + public ConsoleSource source; + public string text; + } + + public List consoleHistory = new(); + protected override async Task OnInitializedAsync() { StartAutoTyping(); } + async void OnKeyDown(KeyboardEventArgs args) + { + if (args.Key == "Enter") + { + await Task.Delay(100); + pushCommand(inputField); + inputField = ""; + StateHasChanged(); + } + } + + private void pushCommand(string command) + { + inputField = ""; // Clear input field + consoleHistory.Add(new consoleLine() { source = ConsoleSource.User, text = command }); + InvokeAsync(StateHasChanged); + ExecuteCommand(command); + } + + private async Task ExecuteCommand(string command) + { + string result = await jsRuntime.InvokeAsync("runEval", command); + consoleHistory.Add(new consoleLine() { source = ConsoleSource.OpenBirch, text = result }); + await InvokeAsync(StateHasChanged); + } + private async void StartAutoTyping() { await Task.Delay(1000); - foreach (char letter in "Balls... Itchy... HELP ME!!!") + foreach (string example in exampleInputs) { - temp += letter; - await InvokeAsync(StateHasChanged); // Trigger UI update - await Task.Delay(200); // Non-blocking delay + foreach (char letter in example) + { + inputField += letter; + await InvokeAsync(StateHasChanged); // Trigger UI update + await Task.Delay(200); // Non-blocking delay - if (!hasInteracted) continue; + if (!hasInteracted) continue; - temp = ""; // Clear input and let user input - await InvokeAsync(StateHasChanged); - return; + inputField = ""; // Clear input and let user input + await InvokeAsync(StateHasChanged); + return; + } + + pushCommand(inputField); + await Task.Delay(500); } } + + public enum ConsoleSource + { + User, // From the user + OpenBirch, // Guess + } } \ No newline at end of file diff --git a/OpenBirchWebsite/Pages/Home.razor.css b/OpenBirchWebsite/Pages/Home.razor.css index 1304edc..0e84a6f 100644 --- a/OpenBirchWebsite/Pages/Home.razor.css +++ b/OpenBirchWebsite/Pages/Home.razor.css @@ -2,9 +2,21 @@ display: grid; grid-template-columns: 1fr 1fr; /*border: red 1mm solid;*/ + gap: 2rem; +} + +.console-container { + display: grid; + grid-template-columns: 1fr 2fr 1fr 1fr; } .input-field { max-width: 400px; min-width: 300px; +} + +.reverse-stack-direction { + display: flex; + justify-content: flex-end; + flex-direction: column; } \ No newline at end of file