Ejemplo n.º 1
0
        static void Mouse()
        {
            NCurses.NoDelay(Screen, true);
            NCurses.NoEcho();

            NCurses.MoveAddString(0, 0, "Click a button or press any key to exit.");
            NCurses.MoveAddString(2, 0, "[X]  [Y]");

            // some terminals require this to differentiate mouse "keys" from random keyboard input
            NCurses.Keypad(Screen, true);

            // not reporting mouse movement?
            // https://stackoverflow.com/questions/52047158/report-mouse-position-for-ncurses-on-windows/52053196
            // https://stackoverflow.com/questions/7462850/mouse-movement-events-in-ncurses

            var eventsToReport =
                CursesMouseEvent.BUTTON1_CLICKED |
                CursesMouseEvent.BUTTON2_CLICKED |
                CursesMouseEvent.REPORT_MOUSE_POSITION;

            var availableMouseEvents = NCurses.MouseMask(eventsToReport, out uint oldMask);

            bool exit   = false;
            bool update = true;

            while (!exit)
            {
                switch (NCurses.GetChar())
                {
                case CursesKey.MOUSE:
                    try
                    {
                        NCurses.GetMouse(out MouseEvent mouse);
                        NCurses.MoveAddString(3, 0, $"{mouse.x.ToString("000")}  {mouse.y.ToString("000")}");
                        update = true;
                    }
                    catch (DotnetCursesException)
                    {
                        // no events in the queue
                    }
                    break;

                case -1:
                    // no input received
                    break;

                default:
                    exit = true;
                    break;
                }

                if (update)
                {
                    NCurses.Move(NCurses.Lines - 1, NCurses.Columns - 1);
                    NCurses.Refresh();
                    update = false;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Picks a routine out of the possible candidates
        /// </summary>
        /// <returns>The Routine we're running in this test</returns>
        private static IRoutine PickRoutine()
        {
            IRoutine?chosenRoutine = null;

            do
            {
                int y = 0;

                // Clear current data from console
                NCurses.Erase();

                // Display selection menu for routines
                NCurses.MoveAddString(y, 0, "Pick your routine by using its corresponding number:");
                y += 1;

                List <IRoutine> routines = GetRoutines();
                foreach (var(routine, index) in routines.Select((routine, index) => (routine, index)))
                {
                    NCurses.MoveAddString(y, 0, index + ") " + routine.Name);
                    y += 1;
                }

                // Move cursor to new line
                NCurses.Move(y, 0);

                // Render menu to screen
                NCurses.Refresh();

                // Read user input and parse into index
                int key = NCurses.GetChar();
                try
                {
                    // Convert the character code we get to string, then from that to the integer that was typed.
                    string number = ((char)key).ToString();
                    int    index  = int.Parse(number);
                    chosenRoutine = routines[index];
                }
                catch // Invalid selection: Display retry message to user.
                {
                    // Clear old menu
                    NCurses.Erase();

                    // Print retry message
                    NCurses.MoveAddString(0, 0,
                                          "Invalid selection.  Please select from the available options.  Press [Enter] to continue.");

                    // Display to screen and wait for user to acknowledge
                    NCurses.Refresh();
                    NCurses.GetChar();
                }
            } while (chosenRoutine == null);

            return(chosenRoutine);
        }
Ejemplo n.º 3
0
 private void Move(int x, int y)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         NCurses.Move(y, x);
     }
     else
     {
         Console.SetCursorPosition(x, y);
     }
 }
Ejemplo n.º 4
0
        private static void DrawMap()
        {
            // Clear current data from console
            NCurses.Erase();

            // Calculate available console space.
            NCurses.GetMaxYX(_window, out int height, out int width);

            // Resize viewport as needed to match console size
            _mapView.ResizeViewport(width, height);

            // Change each character of the console as appropriate
            foreach (var pos in _mapView.CurrentViewport.Positions())
            {
                NCurses.Move(pos.Y, pos.X);
                NCurses.InsertChar(_mapView.CurrentViewport[pos]);
            }

            // Render data to screen
            NCurses.Refresh();

            // Reset dirty flag because we just drew
            _dirty = false;
        }
Ejemplo n.º 5
0
 private static void MyRefresh()
 {
     NCurses.Nap(FRAMERATE);
     NCurses.Move(NCurses.Lines - 1, NCurses.Columns - 1);
     NCurses.Refresh();
 }