Terminal.Gui: Application views do not refresh when the cursor is moved.

Describe the bug Application views do not refresh when the cursor is moved. Affected versions are all above 1.9.0

Screenshots bug

To Reproduce

using Terminal.Gui;

namespace Test
{
    public class Program
    {
        static readonly List<string> GlobalList = new() { "1" };
        static readonly ListView GlobalListView = new() { Width = Dim.Fill(), Height = Dim.Fill() };
        static object? _token = null;

        static void Main()
        {

            Application.Init();

            var startButton = new Button("Start");
            var stopButton = new Button("Stop") { Y = 1 };
            var container = new View() { X = Pos.Center(), Y = Pos.Center(), Width = 8, Height = 8, ColorScheme = Colors.Error };
            
            startButton.Clicked += Start;
            stopButton.Clicked += Stop;

            GlobalListView.SetSource(GlobalList);
            container.Add(GlobalListView);

            Application.Top.Add(container);
            Application.Top.Add(startButton, stopButton);
            Application.Run();

            return;
        }

        private static void Start()
        {
            _token = Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), Add);
        }

        private static void Stop()
        {
            Application.MainLoop.RemoveTimeout(_token);
        }

        private static bool Add(MainLoop mainLoop)
        {
            GlobalList.Add(new Random().Next(100).ToString());
            GlobalListView.MoveDown();
            
            return true;
        }
    }
}


Expected behavior Application views should refresh

Desktop MacOS Ventura

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 31

Commits related to this issue

Most upvoted comments

The bug is still not fixed completly.

No issue with resizing before.

And only pollTimeout = 0 will help when you exit the cursor from terminal. The app will continue to refresh the views.

I will also try to reproduce it on Intel Ventura, currently im on Silicon.

After running with #2848, I see no more problem present. Good job @BDisp

Commenting Curses.timeout (10) in ProcessInput will help but will not solve the problem completely.

This is necessary for waiting a while after a Esc key is detected to check if it was pressed alone or if it’s part of a escape sequence, like Key.Home or mouse event, etc.

Well, I think the culprit is the poll method waiting infinitely if pollTimeout=-1 until some action is detected. I did the fix in the #2848. I also did some change to your code: Avoid initialize a view twice because if you use Debug.Assert with Responder.Instances to validate all instances it will fail. So, only declare the fields or initialize with all properties or initialize only with new(); and setting the properties in the Main().

        static Label CounterLabel;
        static Label BlinkingLabel; 

You don’t need to use the return; in a void Main. Instead replace it with Application.Shutdown();

Also for accurating that the timeout action is running on the UI thread, change the Add method to call the Application.MainLoop.Invoke:

	private static bool Add(MainLoop mainLoop)
	{
		Application.MainLoop.Invoke(() => {
			GlobalList.Add(new Random().Next(100).ToString());
			GlobalListView.MoveDown();
		});

		return true;
	}

I appreciate you can run to check if the issue still persist or not. If it’s fix I’ll also do a commit to the v2 as well. Thanks.

Yes, the report list refreshes with no pauses

@BDisp I see a steady stream of ReportMousePosition events getting reported when I move in the same way.