dotnet-curses icon indicating copy to clipboard operation
dotnet-curses copied to clipboard

GetMouse does not work for reporting mouse position

Open ppebb opened this issue 9 months ago • 0 comments

This functionality works fine in C, but when using dotnet curses you do not get the proper position of the mouse, it is all 0, 0. If you check the actual return value of GetMouse it is -1.

Both this and this (if you add a printf for the escape code) give the correct position.

public class Program
{
        [DllImport("libc", SetLastError = true, CharSet = CharSet.Unicode)]
        private static extern void setlocale(int category, string locale);

        private const int LC_ALL = 6;

        public static void Main()
        {
                setlocale(LC_ALL, "");
                nint std = NCurses.InitScreen();
                NCurses.CBreak();
                NCurses.NoEcho();
                NCurses.SetCursor(0);
                NCurses.HalfDelay(1);
                NCurses.Keypad(std, true);
                NCurses.MouseMask(CursesMouseEvent.ALL_MOUSE_EVENTS | CursesMouseEvent.REPORT_MOUSE_POSITION, out _);
                Console.WriteLine("\x1b[?1003h");

                while (true)
                {
                        string ret;
                        int c;
                        try
                        {
                                c = NCurses.WindowGetChar(std);
                        }
                        catch
                        {
                                continue;
                        }

                        if (c == '\r' || c == '\n')
                                break;

                        if (c == -1)
                                ret = "nothing happened";
                        else if (c == CursesKey.MOUSE)
                        {
                                try
                                {
                                        NCurses.GetMouse(out MouseEvent e);
                                        ret = $"mouse event {e.x} {e.y} {e.bstate}";
                                }
                                catch
                                {
                                        ret = "bad mouse event";
                                }
                        }
                        else
                                ret = $"key {c} pressed";

                        NCurses.Move(0, 0);
                        NCurses.InsertLine();
                        NCurses.AddString(ret);
                        NCurses.ClearToEndOfLine();
                        NCurses.Move(0, 0);
                }

                NCurses.EndWin();
        }
}

ppebb avatar Apr 30 '24 11:04 ppebb