Example #1
0
        public override void Init(Action terminalResized)
        {
            if (window != null)
            {
                return;
            }

            try {
                window = Curses.initscr();
            } catch (Exception e) {
                Console.WriteLine("Curses failed to initialize, the exception is: " + e);
            }
            Curses.raw();
            Curses.noecho();

            Curses.Window.Standard.keypad(true);
            reportableMouseEvents = Curses.mousemask(Curses.Event.AllEvents | Curses.Event.ReportMousePosition, out oldMouseEvents);
            TerminalResized       = terminalResized;
            if (reportableMouseEvents.HasFlag(Curses.Event.ReportMousePosition))
            {
                StartReportingMouseMoves();
            }

            HLine     = Curses.ACS_HLINE;
            VLine     = Curses.ACS_VLINE;
            Stipple   = Curses.ACS_CKBOARD;
            Diamond   = Curses.ACS_DIAMOND;
            ULCorner  = Curses.ACS_ULCORNER;
            LLCorner  = Curses.ACS_LLCORNER;
            URCorner  = Curses.ACS_URCORNER;
            LRCorner  = Curses.ACS_LRCORNER;
            LeftTee   = Curses.ACS_LTEE;
            RightTee  = Curses.ACS_RTEE;
            TopTee    = Curses.ACS_TTEE;
            BottomTee = Curses.ACS_BTEE;

            Colors.Base   = new ColorScheme();
            Colors.Dialog = new ColorScheme();
            Colors.Menu   = new ColorScheme();
            Colors.Error  = new ColorScheme();
            Clip          = new Rect(0, 0, Cols, Rows);
            if (Curses.HasColors)
            {
                Curses.StartColor();
                Curses.UseDefaultColors();

                Colors.Base.Normal    = MakeColor(Curses.COLOR_WHITE, Curses.COLOR_BLUE);
                Colors.Base.Focus     = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                Colors.Base.HotNormal = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_BLUE);
                Colors.Base.HotFocus  = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_CYAN);

                // Focused,
                //    Selected, Hot: Yellow on Black
                //    Selected, text: white on black
                //    Unselected, hot: yellow on cyan
                //    unselected, text: same as unfocused
                Colors.Menu.HotFocus  = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_BLACK);
                Colors.Menu.Focus     = Curses.A_BOLD | MakeColor(Curses.COLOR_WHITE, Curses.COLOR_BLACK);
                Colors.Menu.HotNormal = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
                Colors.Menu.Normal    = Curses.A_BOLD | MakeColor(Curses.COLOR_WHITE, Curses.COLOR_CYAN);
                Colors.Menu.Disabled  = MakeColor(Curses.COLOR_WHITE, Curses.COLOR_CYAN);

                Colors.Dialog.Normal    = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_WHITE);
                Colors.Dialog.Focus     = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                Colors.Dialog.HotNormal = MakeColor(Curses.COLOR_BLUE, Curses.COLOR_WHITE);
                Colors.Dialog.HotFocus  = MakeColor(Curses.COLOR_BLUE, Curses.COLOR_CYAN);

                Colors.Error.Normal    = Curses.A_BOLD | MakeColor(Curses.COLOR_WHITE, Curses.COLOR_RED);
                Colors.Error.Focus     = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_WHITE);
                Colors.Error.HotNormal = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_RED);
                Colors.Error.HotFocus  = Colors.Error.HotNormal;
            }
            else
            {
                Colors.Base.Normal      = Curses.A_NORMAL;
                Colors.Base.Focus       = Curses.A_REVERSE;
                Colors.Base.HotNormal   = Curses.A_BOLD;
                Colors.Base.HotFocus    = Curses.A_BOLD | Curses.A_REVERSE;
                Colors.Menu.Normal      = Curses.A_REVERSE;
                Colors.Menu.Focus       = Curses.A_NORMAL;
                Colors.Menu.HotNormal   = Curses.A_BOLD;
                Colors.Menu.HotFocus    = Curses.A_NORMAL;
                Colors.Dialog.Normal    = Curses.A_REVERSE;
                Colors.Dialog.Focus     = Curses.A_NORMAL;
                Colors.Dialog.HotNormal = Curses.A_BOLD;
                Colors.Dialog.HotFocus  = Curses.A_NORMAL;
                Colors.Error.Normal     = Curses.A_BOLD;
                Colors.Error.Focus      = Curses.A_BOLD | Curses.A_REVERSE;
                Colors.Error.HotNormal  = Curses.A_BOLD | Curses.A_REVERSE;
                Colors.Error.HotFocus   = Curses.A_REVERSE;
            }
            Colors.TopLevel = new ColorScheme();

            Colors.TopLevel.Normal    = MakeColor(Curses.COLOR_GREEN, Curses.COLOR_BLACK);
            Colors.TopLevel.Focus     = MakeColor(Curses.COLOR_WHITE, Curses.COLOR_CYAN);
            Colors.TopLevel.HotNormal = MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_BLACK);
            Colors.TopLevel.HotFocus  = MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
        }
Example #2
0
        public override void Init(Action terminalResized)
        {
            if (window != null)
            {
                return;
            }

            try {
                window = Curses.initscr();
            } catch (Exception e) {
                Console.WriteLine("Curses failed to initialize, the exception is: " + e);
            }

            //
            // We are setting Invisible as default so we could ignore XTerm DECSUSR setting
            //
            switch (Curses.curs_set(0))
            {
            case 0:
                currentCursorVisibility = initialCursorVisibility = CursorVisibility.Invisible;
                break;

            case 1:
                currentCursorVisibility = initialCursorVisibility = CursorVisibility.Underline;
                Curses.curs_set(1);
                break;

            case 2:
                currentCursorVisibility = initialCursorVisibility = CursorVisibility.Box;
                Curses.curs_set(2);
                break;

            default:
                currentCursorVisibility = initialCursorVisibility = null;
                break;
            }

            Curses.raw();
            Curses.noecho();

            Curses.Window.Standard.keypad(true);
            reportableMouseEvents = Curses.mousemask(Curses.Event.AllEvents | Curses.Event.ReportMousePosition, out oldMouseEvents);
            TerminalResized       = terminalResized;
            if (reportableMouseEvents.HasFlag(Curses.Event.ReportMousePosition))
            {
                StartReportingMouseMoves();
            }

            //HLine = Curses.ACS_HLINE;
            //VLine = Curses.ACS_VLINE;
            //Stipple = Curses.ACS_CKBOARD;
            //Diamond = Curses.ACS_DIAMOND;
            //ULCorner = Curses.ACS_ULCORNER;
            //LLCorner = Curses.ACS_LLCORNER;
            //URCorner = Curses.ACS_URCORNER;
            //LRCorner = Curses.ACS_LRCORNER;
            //LeftTee = Curses.ACS_LTEE;
            //RightTee = Curses.ACS_RTEE;
            //TopTee = Curses.ACS_TTEE;
            //BottomTee = Curses.ACS_BTEE;
            //RightArrow = Curses.ACS_RARROW;
            //LeftArrow = Curses.ACS_LARROW;
            //UpArrow = Curses.ACS_UARROW;
            //DownArrow = Curses.ACS_DARROW;

            Colors.TopLevel = new ColorScheme();
            Colors.Base     = new ColorScheme();
            Colors.Dialog   = new ColorScheme();
            Colors.Menu     = new ColorScheme();
            Colors.Error    = new ColorScheme();
            Clip            = new Rect(0, 0, Cols, Rows);
            if (Curses.HasColors)
            {
                Curses.StartColor();
                Curses.UseDefaultColors();

                Colors.TopLevel.Normal    = MakeColor(Curses.COLOR_GREEN, Curses.COLOR_BLACK);
                Colors.TopLevel.Focus     = MakeColor(Curses.COLOR_WHITE, Curses.COLOR_CYAN);
                Colors.TopLevel.HotNormal = MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_BLACK);
                Colors.TopLevel.HotFocus  = MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_CYAN);

                Colors.Base.Normal    = MakeColor(Curses.COLOR_WHITE, Curses.COLOR_BLUE);
                Colors.Base.Focus     = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                Colors.Base.HotNormal = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_BLUE);
                Colors.Base.HotFocus  = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_CYAN);

                // Focused,
                //    Selected, Hot: Yellow on Black
                //    Selected, text: white on black
                //    Unselected, hot: yellow on cyan
                //    unselected, text: same as unfocused
                Colors.Menu.HotFocus  = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_BLACK);
                Colors.Menu.Focus     = Curses.A_BOLD | MakeColor(Curses.COLOR_WHITE, Curses.COLOR_BLACK);
                Colors.Menu.HotNormal = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
                Colors.Menu.Normal    = Curses.A_BOLD | MakeColor(Curses.COLOR_WHITE, Curses.COLOR_CYAN);
                Colors.Menu.Disabled  = MakeColor(Curses.COLOR_WHITE, Curses.COLOR_CYAN);

                Colors.Dialog.Normal    = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_WHITE);
                Colors.Dialog.Focus     = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                Colors.Dialog.HotNormal = MakeColor(Curses.COLOR_BLUE, Curses.COLOR_WHITE);
                Colors.Dialog.HotFocus  = MakeColor(Curses.COLOR_BLUE, Curses.COLOR_CYAN);

                Colors.Error.Normal    = Curses.A_BOLD | MakeColor(Curses.COLOR_WHITE, Curses.COLOR_RED);
                Colors.Error.Focus     = MakeColor(Curses.COLOR_BLACK, Curses.COLOR_WHITE);
                Colors.Error.HotNormal = Curses.A_BOLD | MakeColor(Curses.COLOR_YELLOW, Curses.COLOR_RED);
                Colors.Error.HotFocus  = Colors.Error.HotNormal;
            }
            else
            {
                Colors.TopLevel.Normal    = Curses.COLOR_GREEN;
                Colors.TopLevel.Focus     = Curses.COLOR_WHITE;
                Colors.TopLevel.HotNormal = Curses.COLOR_YELLOW;
                Colors.TopLevel.HotFocus  = Curses.COLOR_YELLOW;
                Colors.Base.Normal        = Curses.A_NORMAL;
                Colors.Base.Focus         = Curses.A_REVERSE;
                Colors.Base.HotNormal     = Curses.A_BOLD;
                Colors.Base.HotFocus      = Curses.A_BOLD | Curses.A_REVERSE;
                Colors.Menu.Normal        = Curses.A_REVERSE;
                Colors.Menu.Focus         = Curses.A_NORMAL;
                Colors.Menu.HotNormal     = Curses.A_BOLD;
                Colors.Menu.HotFocus      = Curses.A_NORMAL;
                Colors.Dialog.Normal      = Curses.A_REVERSE;
                Colors.Dialog.Focus       = Curses.A_NORMAL;
                Colors.Dialog.HotNormal   = Curses.A_BOLD;
                Colors.Dialog.HotFocus    = Curses.A_NORMAL;
                Colors.Error.Normal       = Curses.A_BOLD;
                Colors.Error.Focus        = Curses.A_BOLD | Curses.A_REVERSE;
                Colors.Error.HotNormal    = Curses.A_BOLD | Curses.A_REVERSE;
                Colors.Error.HotFocus     = Curses.A_REVERSE;
            }
        }
Example #3
0
        /// <summary>
        ///    Initializes the runtime.   The boolean flag
        ///   indicates whether we are forcing color to be off.
        /// </summary>
        public static void Init(bool disable_color = false)
        {
            if (inited)
            {
                return;
            }
            inited = true;

            empty_container = new Container(0, 0, Terminal.Cols, Terminal.Lines);

            try {
                main_window = Curses.InitScr();
            } catch (Exception e) {
                Console.WriteLine("Curses failed to initialize, the exception is: " + e);
                throw new Exception("Terminal.Init failed");
            }
            Curses.RawMode = true;
            Curses.Echo    = false;
            //Curses.nonl ();
            Stdscr.Keypad = true;
            //			MainScreen.stdscr.Keypad = true;

                        #if BREAK_UTF8_RENDERING
            Curses.Event old = 0;
            MouseEventsAvailable = Curses.console_sharp_mouse_mask(
                Curses.Event.Button1Clicked | Curses.Event.Button1DoubleClicked, out old);
                        #endif

            UsingColor = false;
            if (!disable_color)
            {
                UsingColor = Curses.HasColors;
            }

            Curses.StartColor();
            Curses.UseDefaultColors();
            if (UsingColor)
            {
                ColorNormal    = MakeColor(Colors.WHITE, Colors.BLUE);
                ColorFocus     = MakeColor(Colors.BLACK, Colors.CYAN);
                ColorHotNormal = Attrs.BOLD | MakeColor(Colors.YELLOW, Colors.BLUE);
                ColorHotFocus  = Attrs.BOLD | MakeColor(Colors.YELLOW, Colors.CYAN);

                ColorMenu            = Attrs.BOLD | MakeColor(Colors.WHITE, Colors.CYAN);
                ColorMenuHot         = Attrs.BOLD | MakeColor(Colors.YELLOW, Colors.CYAN);
                ColorMenuSelected    = Attrs.BOLD | MakeColor(Colors.WHITE, Colors.BLACK);
                ColorMenuHotSelected = Attrs.BOLD | MakeColor(Colors.YELLOW, Colors.BLACK);

                ColorMarked         = ColorHotNormal;
                ColorMarkedSelected = ColorHotFocus;

                ColorDialogNormal    = MakeColor(Colors.BLACK, Colors.WHITE);
                ColorDialogFocus     = MakeColor(Colors.BLACK, Colors.CYAN);
                ColorDialogHotNormal = MakeColor(Colors.BLUE, Colors.WHITE);
                ColorDialogHotFocus  = MakeColor(Colors.BLUE, Colors.CYAN);

                ColorError         = Attrs.BOLD | MakeColor(Colors.WHITE, Colors.RED);
                ColorErrorFocus    = MakeColor(Colors.BLACK, Colors.WHITE);
                ColorErrorHot      = Attrs.BOLD | MakeColor(Colors.YELLOW, Colors.RED);
                ColorErrorHotFocus = ColorErrorHot;
            }
            else
            {
                ColorNormal    = Attrs.NORMAL;
                ColorFocus     = Attrs.REVERSE;
                ColorHotNormal = Attrs.BOLD;
                ColorHotFocus  = Attrs.REVERSE | Attrs.BOLD;

                ColorMenu            = Attrs.REVERSE;
                ColorMenuHot         = Attrs.NORMAL;
                ColorMenuSelected    = Attrs.BOLD;
                ColorMenuHotSelected = Attrs.NORMAL;

                ColorMarked         = Attrs.BOLD;
                ColorMarkedSelected = Attrs.REVERSE | Attrs.BOLD;

                ColorDialogNormal    = Attrs.REVERSE;
                ColorDialogFocus     = Attrs.NORMAL;
                ColorDialogHotNormal = Attrs.BOLD;
                ColorDialogHotFocus  = Attrs.NORMAL;

                ColorError = Attrs.BOLD;
            }
            ColorBasic = MakeColor(-1, -1);
            mainloop   = new Looper();
            mainloop.AddWatch(0, Looper.Condition.PollIn, x => {
                Container top = toplevels.Count > 0 ? toplevels [toplevels.Count - 1] : null;
                if (top != null)
                {
                    ProcessChar(top);
                }

                return(true);
            });
        }
Example #4
0
        private static void Main2()
        {
            rng = new Random();
            if (Curses.HasColors)
            {
                Curses.StartColor();
                short bg = Colors.BLACK;
                try
                {
                    Curses.UseDefaultColors();
                    bg = -1;
                }
                catch (CursesException) { }
                Curses.InitPair(1, Colors.BLUE, bg);
                Curses.InitPair(2, Colors.CYAN, bg);
            }
            Curses.Newlines         = true;
            Curses.Echo             = false;
            Curses.CursorVisibility = 0;
            Stdscr.ReadTimeout      = 0;
            Stdscr.Keypad           = true;

            int r = Curses.Lines - 4, c = Curses.Cols - 4;

            int[] xpos = new int[5];
            int[] ypos = new int[5];
            for (int j = 0; j < 5; ++j)
            {
                xpos[j] = rng.Next(c) + 2;
                ypos[j] = rng.Next(r) + 2;
            }

            for (int j = 0; ;)
            {
                int x = rng.Next(c) + 2;
                int y = rng.Next(r) + 2;

                Stdscr.Add(y, x, '.');

                Stdscr.Add(ypos[j], xpos[j], 'o');

                j = NextJ(j);
                Stdscr.Add(ypos[j], xpos[j], 'O');

                j = NextJ(j);
                Stdscr.Add(ypos[j] - 1, xpos[j], '-');
                Stdscr.Add(ypos[j], xpos[j] - 1, "|.|");
                Stdscr.Add(ypos[j] + 1, xpos[j], '-');

                j = NextJ(j);
                Stdscr.Add(ypos[j] - 2, xpos[j], '-');
                Stdscr.Add(ypos[j] - 1, xpos[j] - 1, "/ \\");
                Stdscr.Add(ypos[j], xpos[j] - 2, "| O |");
                Stdscr.Add(ypos[j] + 1, xpos[j] - 1, "\\ /");
                Stdscr.Add(ypos[j] + 2, xpos[j], '-');

                j = NextJ(j);
                Stdscr.Add(ypos[j] - 2, xpos[j], ' ');
                Stdscr.Add(ypos[j] - 1, xpos[j] - 1, "   ");
                Stdscr.Add(ypos[j], xpos[j] - 2, "     ");
                Stdscr.Add(ypos[j] + 1, xpos[j] - 1, "   ");
                Stdscr.Add(ypos[j] + 2, xpos[j], ' ');

                xpos[j] = x;
                ypos[j] = y;

                switch (Stdscr.GetChar())
                {
                case 'q':
                case 'Q':
                    Curses.CursorVisibility = 1;
                    return;

                case 's':
                    Stdscr.Blocking = true;
                    break;

                case ' ':
                    Stdscr.Blocking = false;
                    break;

                default: break;
                }
                Curses.NapMs(50);
            }
        }