Replies: 1 comment
-
Here is an example of listening to an API and updating a TextView with the results. If you are doing high volume of events or anything complicated I would suggest creating your own View rather than TextView which is more designed as a text editor than a pure display. using delme4;
using Terminal.Gui;
Application.Init();
var tv = new TextView
{
Width = Dim.Fill(),
Height = Dim.Fill()
};
// Create an imaginary API
var a = new FakeApi();
// When an event on the API is sent to us
a.SomeEvent += (e) =>
{
// Switch to main UI thread
Application.MainLoop.Invoke(() =>
{
// and update the text box
tv.Text += e + '\n';
});
};
// Start the fake API in background thread
Task.Run(a.Run);
try
{
var w = new Window();
w.Add(tv);
Application.Run(w);
}
finally
{
Application.Shutdown();
}
class FakeApi
{
public event Action<string> SomeEvent;
public void Run()
{
while(true)
{
Task.Delay(1000).Wait();
SomeEvent.Invoke("flibble");
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I can listen to the API events using a busy loop in a non-gui app with handlers using Console.Writeline.
However when inside a Terminal.Gui.Window nothing happens. Is there an example of listening to outside events I can follow?
Thank you ahead of time.
Beta Was this translation helpful? Give feedback.
All reactions