public static void Main(string[] args) { Console.WindowWidth = 100; Curses.InitScr(); Curses.StartColor(); Curses.InitPair(1, Colors.WHITE, Colors.BLACK); mainDisplay = new Window(Console.WindowHeight, Console.WindowWidth, 0, 0); mainDisplay.EnableScroll = true; Window commandInput = new Window(1, Console.WindowWidth, Console.WindowHeight - 1, 0); commandInput.Color = 1; mainDisplay.Color = 1; mCore.Init(EventHandler); CommandHandler.Initialize(); while (true) { commandInput.Clear(); commandInput.Add(">"); String command = commandInput.GetString(); CommandHandler.HandleCommand(command); commandInput.Refresh(); } }
private static void Main2() { Stdscr.Blocking = false; Curses.Echo = false; if (Curses.HasColors) { Curses.StartColor(); for (short i = 1; i < 8; ++i) { Curses.InitPair(i, color_table[i], Colors.BLACK); } } rng = new Random(); int flag = 0; while (Stdscr.GetChar() == -1) { int start, end, row, diff, direction; do { start = rng.Next(Curses.Cols - 3); end = rng.Next(Curses.Cols - 3); start = (start < 2) ? 2 : start; end = (end < 2) ? 2 : end; direction = (start > end) ? -1 : 1; diff = Math.Abs(start - end); } while (diff < 2 || diff >= Curses.Lines - 2); Stdscr.Attr = Attrs.NORMAL; for (row = 1; row < diff; ++row) { Stdscr.Add(Curses.Lines - row, row * direction + start, (direction < 0) ? "\\" : "/"); if (flag++ > 0) { MyRefresh(); Stdscr.Erase(); flag = 0; } } if (flag++ > 0) { MyRefresh(); flag = 0; } Explode(Curses.Lines - row, diff * direction + start); Stdscr.Erase(); MyRefresh(); } }
static void Main(string[] args) { // Init Curses Curses.InitScr(); Stdscr.Blocking = false; Curses.Echo = false; Keyboard.Init(); Stdscr.Keypad = true; if (Curses.HasColors) { Curses.StartColor(); for (short i = 1; i < 8; ++i) { Curses.InitPair(i, color_table[i], Colors.BLACK); } } // Init world. StateMachine.Switch(new IntroState()); bool running = true; Stopwatch time = new Stopwatch(); time.Start(); long spillover = 0; while (running) { if (time.ElapsedMilliseconds + spillover > 100) { Keyboard.UpdateKeys(); if (Keyboard.KeyDown(27)) { running = false; } StateMachine.Update(100); Keyboard.Reset(); // Game render StateMachine.Draw(); Stdscr.Move(Curses.Lines - 1, Curses.Cols - 1); Stdscr.Refresh(); spillover = (time.ElapsedMilliseconds + spillover) - 100; time.Restart(); } } // Game end! Curses.EndWin(); }
public ConsoleWindow(TwitterConnection twitterConnection) { Curses.InitScr(); Curses.CBreakMode = true; Curses.Echo = false; Curses.StdScr.Keypad = true; Curses.StartColor(); Curses.InitPair(1, Colors.WHITE, Colors.RED); Curses.InitPair(2, Colors.RED, Colors.WHITE); this.tweets = twitterConnection.Tweets; this.twitterConnection = twitterConnection; this.visibleTimelineBuffer = new string[Curses.Lines - STATUS_HEIGHT - 1]; this.TweetText = ""; this.topTweet = this.tweets.Count - 1; this.updateVisibleTimeline(this.topTweet); this.refreshTimeline(); this.refreshTweetWindow(); }
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); }
/// <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); }); }
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; } }
static void Main(string[] args) { Curses.Init(); if (Curses.HasColor()) { Curses.StartColor(); int bg = Colors.BLACK; if (Curses.SetDefaultColor()) { bg = -1; } Curses.InitPair(1, Colors.BLUE, bg); Curses.InitPair(2, Colors.CYAN, bg); } int maxy = Curses.Lines; Curses.Cursor = false; Curses.Blocking = false; Curses.Echo = false; Curses.Keypad = true; int start, end, row, diff, flag, direction; short i; Curses.Init(); int[] color_table = { Colors.RED, Colors.BLUE, Colors.GREEN, Colors.CYAN, Colors.RED, Colors.MAGENTA, Colors.YELLOW, Colors.WHITE }; for (i = 0; i < 8; i++) { Curses.InitPair(i + 1, color_table[i], Colors.BLACK); } flag = 0; while (Curses.GetCh().IsEof()) /* loop until a key is hit */ { do { start = rand.Next(Curses.Cols - 3); end = rand.Next(Curses.Cols - 3); start = (start < 2) ? 2 : start; end = (end < 2) ? 2 : end; direction = (start > end) ? -1 : 1; diff = Math.Abs(start - end); } while (diff < 2 || diff >= Curses.Lines - 2); for (row = 0; row < diff; row++) { Curses.Add(Curses.Lines - row, row * direction + start, (direction < 0) ? "\\" : "/"); if (flag++ > 0) { myrefresh(); Curses.Erase(); flag = 0; } } if (flag++ > 0) { myrefresh(); flag = 0; } explode(Curses.Lines - row, diff * direction + start); Curses.Erase(); myrefresh(); } Curses.Exit(); }
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); } }