@page "/"
@inject OpenBirchConsole console
@inject IJSRuntime jsRuntime
@inject NavigationManager nav
Home
What is this?
This is an open-source solution for your academic math software.
Why did we make this?
Because linux bad and can't run .exe, and other programs are expendsive.
@code {
public string inputField = "";
public bool hasInteracted = false; // Has the user interacted with the input field?
private Task? AutoTypingTask;
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);
}
protected override async Task OnInitializedAsync()
{
if (!GlobalVariables.HasAutoTypingEd)
AutoTypingTask = StartAutoTyping();
GlobalVariables.HasAutoTypingEd = true;
}
private async void OnInputClicked()
{
hasInteracted = true;
if (AutoTypingTask != null)
await AutoTypingTask;
nav.NavigateTo("openbirch");
}
async void OnKeyDown(KeyboardEventArgs args)
{
if (args.Key == "Enter")
{
await Task.Delay(100);
sendCommand(inputField);
StateHasChanged();
}
}
private async void sendCommand(string command)
{
inputField = "";
await console.pushCommand(command);
await InvokeAsync(StateHasChanged);
}
const int typingDelay = 200;
private async Task StartAutoTyping()
{
await Task.Delay(1000);
foreach (string example in exampleInputs)
{
foreach (char letter in example)
{
inputField += letter;
await InvokeAsync(StateHasChanged); // Trigger UI update
await Task.Delay(200); // Non-blocking delay
// 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;
}
inputField = ""; // Clear input and let user input
await InvokeAsync(StateHasChanged);
return;
earlyExit:;
}
sendCommand(inputField);
await Task.Delay(500);
}
}
}