2024-07-13 03:21:35 +02:00
|
|
|
@page "/"
|
2024-07-15 04:08:10 +02:00
|
|
|
@inject OpenBirchConsole console
|
2024-07-14 00:18:54 +02:00
|
|
|
@inject IJSRuntime jsRuntime
|
2024-07-14 16:24:54 +02:00
|
|
|
@inject NavigationManager nav
|
2024-07-13 03:21:35 +02:00
|
|
|
|
|
|
|
<PageTitle>Home</PageTitle>
|
|
|
|
|
2024-07-13 04:51:36 +02:00
|
|
|
<div class="double_centered_boxes">
|
|
|
|
<MudText Align="Align.Center" Typo="Typo.h2">Welcome to<br /><b>OpenBirch!!!</b></MudText>
|
|
|
|
<div></div>
|
2024-07-14 02:13:46 +02:00
|
|
|
<div style="height: 200px; display: grid; place-items: end center;">
|
|
|
|
<MudPaper Style="background-color: #191724; height: 200px;" Elevation="4" Class="input-field pt-0 console-container">
|
|
|
|
<div style="height: 100%;" class="reverse-stack-direction overflow-hidden">
|
2024-07-15 04:08:10 +02:00
|
|
|
@for (int i = 0; i < console.history.Count; i++)
|
2024-07-14 02:13:46 +02:00
|
|
|
{
|
|
|
|
int temp = i;
|
2024-07-15 04:08:10 +02:00
|
|
|
<MudText Align="Align.Start"> @((console.history[temp].source == ConsoleSource.User) ? ">" : "#") @console.history[temp].text</MudText>
|
2024-07-14 02:13:46 +02:00
|
|
|
}
|
|
|
|
</div>
|
2024-07-15 04:08:10 +02:00
|
|
|
<MudTextField Class="" Style="color: #e0def4;" @bind-Value="inputField" OnKeyDown="OnKeyDown" Variant="Variant.Outlined" @onclick='OnInputClicked'></MudTextField>
|
2024-07-14 02:13:46 +02:00
|
|
|
</MudPaper>
|
2024-07-13 04:51:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
@code {
|
2024-07-14 02:13:46 +02:00
|
|
|
public string inputField = " ";
|
2024-07-13 04:51:36 +02:00
|
|
|
public bool hasInteracted = false; // Has the user interacted with the input field?
|
2024-07-15 04:08:10 +02:00
|
|
|
private Task AutoTypingTask;
|
2024-07-13 04:51:36 +02:00
|
|
|
|
2024-07-14 02:13:46 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-07-15 04:08:10 +02:00
|
|
|
protected override async Task OnInitializedAsync()
|
2024-07-14 02:13:46 +02:00
|
|
|
{
|
2024-07-15 04:08:10 +02:00
|
|
|
AutoTypingTask = StartAutoTyping();
|
|
|
|
}
|
2024-07-14 02:13:46 +02:00
|
|
|
|
2024-07-15 04:08:10 +02:00
|
|
|
private async void OnInputClicked()
|
2024-07-13 04:51:36 +02:00
|
|
|
{
|
2024-07-15 04:08:10 +02:00
|
|
|
hasInteracted = true;
|
|
|
|
await AutoTypingTask;
|
|
|
|
nav.NavigateTo("openbirch");
|
2024-07-13 04:51:36 +02:00
|
|
|
}
|
|
|
|
|
2024-07-14 02:13:46 +02:00
|
|
|
async void OnKeyDown(KeyboardEventArgs args)
|
|
|
|
{
|
|
|
|
if (args.Key == "Enter")
|
|
|
|
{
|
|
|
|
await Task.Delay(100);
|
2024-07-15 04:08:10 +02:00
|
|
|
sendCommand(inputField);
|
2024-07-14 02:13:46 +02:00
|
|
|
StateHasChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-15 04:08:10 +02:00
|
|
|
private async void sendCommand(string command)
|
2024-07-14 02:13:46 +02:00
|
|
|
{
|
2024-07-15 04:08:10 +02:00
|
|
|
inputField = "";
|
|
|
|
await console.pushCommand(command);
|
2024-07-14 02:13:46 +02:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
2024-07-15 04:08:10 +02:00
|
|
|
int typingDelay = 200;
|
|
|
|
|
|
|
|
private async Task StartAutoTyping()
|
2024-07-13 04:51:36 +02:00
|
|
|
{
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
2024-07-14 02:13:46 +02:00
|
|
|
foreach (string example in exampleInputs)
|
2024-07-13 04:51:36 +02:00
|
|
|
{
|
2024-07-14 02:13:46 +02:00
|
|
|
foreach (char letter in example)
|
|
|
|
{
|
|
|
|
inputField += letter;
|
|
|
|
await InvokeAsync(StateHasChanged); // Trigger UI update
|
|
|
|
await Task.Delay(200); // Non-blocking delay
|
|
|
|
|
2024-07-15 04:08:10 +02:00
|
|
|
// Makes it check if user inputted while waiting
|
|
|
|
const int waitTime = 10;
|
|
|
|
int waitedTime = 0;
|
|
|
|
while (waitedTime < typingDelay)
|
|
|
|
{
|
|
|
|
await Task.Delay(waitTime);
|
|
|
|
waitedTime += waitTime;
|
|
|
|
if (!hasInteracted) goto earlyExit;
|
|
|
|
}
|
2024-07-13 04:51:36 +02:00
|
|
|
|
2024-07-14 02:13:46 +02:00
|
|
|
inputField = ""; // Clear input and let user input
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
return;
|
2024-07-15 04:08:10 +02:00
|
|
|
|
|
|
|
earlyExit:;
|
2024-07-14 02:13:46 +02:00
|
|
|
}
|
2024-07-13 04:51:36 +02:00
|
|
|
|
2024-07-15 04:08:10 +02:00
|
|
|
sendCommand(inputField);
|
2024-07-14 02:13:46 +02:00
|
|
|
await Task.Delay(500);
|
2024-07-13 04:51:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|