using Microsoft.JSInterop; namespace OpenBirchWebsite.Services { public class OpenBirchConsole(IJSRuntime js) : IDisposable { public List history = new(); private readonly IJSRuntime js = js; public static event Action> OnLinesChanged; public Task pushCommand(string command) { history.Add(new ConsoleLine() { source = ConsoleSource.User, text = command }); return ExecuteCommand(command); } private async Task ExecuteCommand(string command) { string result = await js.InvokeAsync("runEval", command); history.Add(new ConsoleLine() { source = ConsoleSource.OpenBirch, text = result }); OnLinesChanged?.Invoke(history); } public void Dispose() { // The following prevents derived types that introduce a // finalizer from needing to re-implement IDisposable. GC.SuppressFinalize(this); } } public struct ConsoleLine { public ConsoleSource source; public string text; } public enum ConsoleSource { User, // From the user OpenBirch, // Guess } }