예제 #1
0
        private static bool InitializeNCurses(ref IntPtr screen, short[] colorMap, Byte width, Byte height)
        {
            screen = NCurses.InitScreen();

            if (NCurses.HasColors() == false)
            {
                Console.WriteLine("Your terminal doesn't support colored output.");
                NCurses.EndWin();
                return(false);
            }

            if ((NCurses.Columns < width - 1) || (NCurses.Lines < height - 1))
            {
                Console.WriteLine($"Your terminal must be {width}x{height}. You have {NCurses.Columns}x{NCurses.Lines}");
                NCurses.EndWin();
                return(false);
            }

            NCurses.NoDelay(screen, true);
            NCurses.NoEcho();
            NCurses.AttributeSet(CursesAttribute.NORMAL);
            NCurses.StartColor();
            NCurses.InitPair(colorMap[0], CursesColor.BLACK, CursesColor.BLACK);
            NCurses.InitPair(colorMap[1], CursesColor.WHITE, CursesColor.WHITE);

            return(true);
        }
예제 #2
0
        static void Main(string[] args)
        {
            short[]        colorMap = new short[] { 1, 2 };
            IntPtr         screen   = default;
            NCursesDisplay display  = null;
            IChip8Device   device   = null;

            Func <bool>[] initializers =
            {
                () => InitializeNCurses(ref screen,        colorMap,        DefaultWidth, DefaultHeight),
                () => InitializeDisplayBuffer(ref display, screen,          colorMap),
                () => BuildDevice(ref device,              display.Buffer),
                () => LoadProgram(device,                  "program")
            };

            try
            {
                if (initializers.All(p => p()))
                {
                    Run(device, display);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Caught an exception: {e.Message}");
            }

            NCurses.EndWin();
        }
예제 #3
0
 static void Main(string[] args)
 {
     Screen = NCurses.InitScreen();
     try
     {
         Mouse();
     }
     finally
     {
         NCurses.EndWin();
     }
 }
예제 #4
0
        /// <summary>
        /// Start listening for keypresses.
        /// </summary>
        public static void Run()
        {
            while (!_exit)
            {
                if (_dirty)
                {
                    DrawMap();
                }

                InterpretKeyPress();
            }

            NCurses.EndWin();
        }