public static void Main(string[] args) { Curses Curses = new Curses(); Curses.Print(10, 10, "Hello, curses!"); Curses.Refresh(); char c = Curses.GetChar(); Curses = null; }
void ProcessInput(Action <KeyEvent> keyHandler, Action <KeyEvent> keyDownHandler, Action <KeyEvent> keyUpHandler, Action <MouseEvent> mouseHandler) { int wch; var code = Curses.get_wch(out wch); if (code == Curses.ERR) { return; } keyModifiers = new KeyModifiers(); Key k = Key.Null; if (code == Curses.KEY_CODE_YES) { if (wch == Curses.KeyResize) { if (Curses.CheckWinChange()) { TerminalResized?.Invoke(); return; } } if (wch == Curses.KeyMouse) { Curses.getmouse(out Curses.MouseEvent ev); //System.Diagnostics.Debug.WriteLine ($"ButtonState: {ev.ButtonState}; ID: {ev.ID}; X: {ev.X}; Y: {ev.Y}; Z: {ev.Z}"); mouseHandler(ToDriverMouse(ev)); return; } k = MapCursesKey(wch); if (wch >= 277 && wch <= 288) // Shift+(F1 - F12) { wch -= 12; k = Key.ShiftMask | MapCursesKey(wch); } else if (wch >= 289 && wch <= 300) // Ctrl+(F1 - F12) { wch -= 24; k = Key.CtrlMask | MapCursesKey(wch); } else if (wch >= 301 && wch <= 312) // Ctrl+Shift+(F1 - F12) { wch -= 36; k = Key.CtrlMask | Key.ShiftMask | MapCursesKey(wch); } else if (wch >= 313 && wch <= 324) // Alt+(F1 - F12) { wch -= 48; k = Key.AltMask | MapCursesKey(wch); } else if (wch >= 325 && wch <= 327) // Shift+Alt+(F1 - F3) { wch -= 60; k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch); } keyDownHandler(new KeyEvent(k, MapKeyModifiers(k))); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); keyUpHandler(new KeyEvent(k, MapKeyModifiers(k))); return; } // Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter as well as Alt-Fkey if (wch == 27) { Curses.timeout(200); code = Curses.get_wch(out int wch2); if (code == Curses.KEY_CODE_YES) { k = Key.AltMask | MapCursesKey(wch); } if (code == 0) { KeyEvent key; // The ESC-number handling, debatable. // Simulates the AltMask itself by pressing Alt + Space. if (wch2 == (int)Key.Space) { k = Key.AltMask; } else if (wch2 - (int)Key.Space >= (uint)Key.A && wch2 - (int)Key.Space <= (uint)Key.Z) { k = (Key)((uint)Key.AltMask + (wch2 - (int)Key.Space)); } else if (wch2 >= (uint)Key.A - 64 && wch2 <= (uint)Key.Z - 64) { k = (Key)((uint)(Key.AltMask | Key.CtrlMask) + (wch2 + 64)); } else if (wch2 >= (uint)Key.D0 && wch2 <= (uint)Key.D9) { k = (Key)((uint)Key.AltMask + (uint)Key.D0 + (wch2 - (uint)Key.D0)); } else if (wch2 == 27) { k = (Key)wch2; } else if (wch2 == Curses.KEY_CODE_SEQ) { int [] c = null; while (code == 0) { code = Curses.get_wch(out wch2); if (wch2 > 0) { Array.Resize(ref c, c == null ? 1 : c.Length + 1); c [c.Length - 1] = wch2; } } if (c [0] == 49 && c [1] == 59 && c [2] == 55 && c [3] >= 80 && c [3] <= 83) // Ctrl+Alt+(F1 - F4) { wch2 = c [3] + 185; k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 49 && c [2] == 59 && c [3] == 55 && c [4] == 126 && c [1] >= 53 && c [1] <= 57) // Ctrl+Alt+(F5 - F8) { wch2 = c [1] == 53 ? c [1] + 216 : c [1] + 215; k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 50 && c [2] == 59 && c [3] == 55 && c [4] == 126 && c [1] >= 48 && c [1] <= 52) // Ctrl+Alt+(F9 - F12) { wch2 = c [1] < 51 ? c [1] + 225 : c [1] + 224; k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 49 && c [1] == 59 && c [2] == 56 && c [3] >= 80 && c [3] <= 83) // Ctrl+Shift+Alt+(F1 - F4) { wch2 = c [3] + 185; k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 49 && c [2] == 59 && c [3] == 56 && c [4] == 126 && c [1] >= 53 && c [1] <= 57) // Ctrl+Shift+Alt+(F5 - F8) { wch2 = c [1] == 53 ? c [1] + 216 : c [1] + 215; k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 50 && c [2] == 59 && c [3] == 56 && c [4] == 126 && c [1] >= 48 && c [1] <= 52) // Ctrl+Shift+Alt+(F9 - F12) { wch2 = c [1] < 51 ? c [1] + 225 : c [1] + 224; k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 49 && c [1] == 59 && c [2] == 52 && c [3] == 83) // Shift+Alt+(F4) { wch2 = 268; k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 49 && c [2] == 59 && c [3] == 52 && c [4] == 126 && c [1] >= 53 && c [1] <= 57) // Shift+Alt+(F5 - F8) { wch2 = c [1] < 55 ? c [1] + 216 : c [1] + 215; k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 50 && c [2] == 59 && c [3] == 52 && c [4] == 126 && c [1] >= 48 && c [1] <= 52) // Shift+Alt+(F9 - F12) { wch2 = c [1] < 51 ? c [1] + 225 : c [1] + 224; k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); } else if (c [0] == 54 && c [1] == 59 && c [2] == 56 && c [3] == 126) // Shift+Ctrl+Alt+KeyNPage { k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.PageDown; } else if (c [0] == 53 && c [1] == 59 && c [2] == 56 && c [3] == 126) // Shift+Ctrl+Alt+KeyPPage { k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.PageUp; } else if (c [0] == 49 && c [1] == 59 && c [2] == 56 && c [3] == 72) // Shift+Ctrl+Alt+KeyHome { k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.Home; } else if (c [0] == 49 && c [1] == 59 && c [2] == 56 && c [3] == 70) // Shift+Ctrl+Alt+KeyEnd { k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.End; } else { k = MapCursesKey(wch2); } } else { // Unfortunately there are no way to differentiate Ctrl+Alt+alfa and Ctrl+Shift+Alt+alfa. if (((Key)wch2 & Key.CtrlMask) != 0) { keyModifiers.Ctrl = true; } if (wch2 == 0) { k = Key.CtrlMask | Key.AltMask | Key.Space; } else if (wch >= (uint)Key.A && wch <= (uint)Key.Z) { keyModifiers.Shift = true; keyModifiers.Alt = true; } else if (wch2 < 256) { k = (Key)wch2; keyModifiers.Alt = true; } else { k = (Key)((uint)(Key.AltMask | Key.CtrlMask) + wch2); } } key = new KeyEvent(k, MapKeyModifiers(k)); keyDownHandler(key); keyHandler(key); } else { k = Key.Esc; keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } } else if (wch == Curses.KeyTab) { k = MapCursesKey(wch); keyDownHandler(new KeyEvent(k, MapKeyModifiers(k))); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } else { // Unfortunately there are no way to differentiate Ctrl+alfa and Ctrl+Shift+alfa. k = (Key)wch; if (wch == 0) { k = Key.CtrlMask | Key.Space; } else if (wch >= (uint)Key.A - 64 && wch <= (uint)Key.Z - 64) { if ((Key)(wch + 64) != Key.J) { k = Key.CtrlMask | (Key)(wch + 64); } } else if (wch >= (uint)Key.A && wch <= (uint)Key.Z) { keyModifiers.Shift = true; } keyDownHandler(new KeyEvent(k, MapKeyModifiers(k))); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); keyUpHandler(new KeyEvent(k, MapKeyModifiers(k))); } // Cause OnKeyUp and OnKeyPressed. Note that the special handling for ESC above // will not impact KeyUp. // This is causing ESC firing even if another keystroke was handled. //if (wch == Curses.KeyTab) { // keyUpHandler (new KeyEvent (MapCursesKey (wch), keyModifiers)); //} else { // keyUpHandler (new KeyEvent ((Key)wch, keyModifiers)); //} }
public override void SetAttribute(Attribute c) { currentAttribute = c.Value; Curses.attrset(currentAttribute); }
public override void SetAttribute(Attribute c) => Curses.attrset(c.value);
public override void End() => Curses.endwin();
void ProcessInput(Action <KeyEvent> keyHandler, Action <KeyEvent> keyDownHandler, Action <KeyEvent> keyUpHandler, Action <MouseEvent> mouseHandler) { int wch; var code = Curses.get_wch(out wch); if (code == Curses.ERR) { return; } keyModifiers = new KeyModifiers(); Key k; if (code == Curses.KEY_CODE_YES) { if (wch == Curses.KeyResize) { if (Curses.CheckWinChange()) { TerminalResized?.Invoke(); return; } } if (wch == Curses.KeyMouse) { Curses.getmouse(out Curses.MouseEvent ev); //System.Diagnostics.Debug.WriteLine ($"ButtonState: {ev.ButtonState}; ID: {ev.ID}; X: {ev.X}; Y: {ev.Y}; Z: {ev.Z}"); mouseHandler(ToDriverMouse(ev)); return; } keyHandler(new KeyEvent(MapCursesKey(wch), keyModifiers)); keyUpHandler(new KeyEvent(MapCursesKey(wch), keyModifiers)); return; } // Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter as well as Alt-Fkey if (wch == 27) { Curses.timeout(200); code = Curses.get_wch(out int wch2); if (code == Curses.KEY_CODE_YES) { k = Key.AltMask | MapCursesKey(wch); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } if (code == 0) { KeyEvent key; // The ESC-number handling, debatable. // Simulates the AltMask itself by pressing Alt + Space. if (wch2 == (int)Key.Space) { k = Key.AltMask; key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 - (int)Key.Space >= 'A' && wch2 - (int)Key.Space <= 'Z') { k = (Key)((uint)Key.AltMask + (wch2 - (int)Key.Space)); key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 >= '1' && wch <= '9') { k = (Key)((int)Key.F1 + (wch2 - '0' - 1)); key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 == '0') { k = Key.F10; key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 == 27) { k = (Key)wch2; key = new KeyEvent(k, MapKeyModifiers(k)); } else { k = Key.AltMask | (Key)wch2; key = new KeyEvent(k, MapKeyModifiers(k)); } keyHandler(key); } else { k = Key.Esc; keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } } else if (wch == Curses.KeyTab) { k = MapCursesKey(wch); keyDownHandler(new KeyEvent(k, MapKeyModifiers(k))); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } else { k = (Key)wch; keyDownHandler(new KeyEvent(k, MapKeyModifiers(k))); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } // Cause OnKeyUp and OnKeyPressed. Note that the special handling for ESC above // will not impact KeyUp. // This is causing ESC firing even if another keystroke was handled. //if (wch == Curses.KeyTab) { // keyUpHandler (new KeyEvent (MapCursesKey (wch), keyModifiers)); //} else { // keyUpHandler (new KeyEvent ((Key)wch, keyModifiers)); //} }
public override void UpdateCursor() => Curses.refresh();
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(); try{ CursesDefaultEscDelay = Curses.get_escdelay(); Curses.set_escdelay(10); } catch (Exception e) { Console.WriteLine("Curses failed to get esc delay, the exception is: " + e); } 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; Lozenge = '\u25CA'; 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; Checked = '\u221a'; UnChecked = ' '; Selected = '\u25cf'; UnSelected = '\u25cc'; RightArrow = Curses.ACS_RARROW; LeftArrow = Curses.ACS_LARROW; UpArrow = Curses.ACS_UARROW; DownArrow = Curses.ACS_DARROW; LeftDefaultIndicator = '\u25e6'; RightDefaultIndicator = '\u25e6'; LeftBracket = '['; RightBracket = ']'; OnMeterSegment = '\u258c'; OffMeterSegement = ' '; 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; } }
public override void CookMouse() { mouseGrabbed = false; Curses.mouseinterval(lastMouseInterval); }
void ProcessInput(Action <KeyEvent> keyHandler, Action <MouseEvent> mouseHandler) { int wch; var code = Curses.get_wch(out wch); if (code == Curses.ERR) { return; } if (code == Curses.KEY_CODE_YES) { if (wch == Curses.KeyResize) { if (Curses.CheckWinChange()) { terminalResized(); return; } } if (wch == Curses.KeyMouse) { Curses.MouseEvent ev; Curses.getmouse(out ev); mouseHandler(ToDriverMouse(ev)); return; } keyHandler(new KeyEvent(MapCursesKey(wch))); return; } // Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter as well as Alt-Fkey if (wch == 27) { Curses.timeout(200); code = Curses.get_wch(out wch); if (code == Curses.KEY_CODE_YES) { keyHandler(new KeyEvent(Key.AltMask | MapCursesKey(wch))); } if (code == 0) { KeyEvent key; // The ESC-number handling, debatable. if (wch >= '1' && wch <= '9') { key = new KeyEvent((Key)((int)Key.F1 + (wch - '0' - 1))); } else if (wch == '0') { key = new KeyEvent(Key.F10); } else if (wch == 27) { key = new KeyEvent((Key)wch); } else { key = new KeyEvent(Key.AltMask | (Key)wch); } keyHandler(key); } else { keyHandler(new KeyEvent(Key.Esc)); } } else { keyHandler(new KeyEvent((Key)wch)); } }
private static void GetColor() { uint bold = (rng.Next(2) > 0) ? Attrs.BOLD : Attrs.NORMAL; Stdscr.Attr = Curses.COLOR_PAIR((short)rng.Next(8)) | bold; }
private static void MyRefresh() { Curses.NapMs(DELAYSIZE); Stdscr.Move(Curses.Lines - 1, Curses.Cols - 1); Stdscr.Refresh(); }
void GoTop() { SetTopByte(first_file_byte); Redraw(); Curses.refresh(); }
void DrawView() { int col = 0; bool skip_until_newline = false; Curses.attrset(Container.ContainerColorNormal); Move(y + 1, x); SetPosition(top_byte); for (int row = 0; row < h;) { int c = GetChar(); switch (c) { /* End of file */ case -1: ClearToEnd(col, row); row = h; continue; case 10: ClearToEnd(col); col = 0; row++; skip_until_newline = false; Move(y + row, x + col); continue; case 9: for (int nc = (col / 8 + 1) * 8; col < nc; col++) { Curses.addch(' '); } continue; case 13: continue; } // Control chars or unicode > 0xffff if (c < 32 || c > 0xffff) { c = '.'; } if (skip_until_newline) { continue; } Curses.addch((char)c); col++; if (col > w) { if (Wrap) { col = 0; row++; } else { skip_until_newline = 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); } 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; } }
public override void Refresh() => Curses.refresh();
void ProcessInput(Action <KeyEvent> keyHandler, Action <KeyEvent> keyDownHandler, Action <KeyEvent> keyUpHandler, Action <MouseEvent> mouseHandler) { int wch; var code = Curses.get_wch(out wch); if (code == Curses.ERR) { return; } keyModifiers = new KeyModifiers(); Key k; if (code == Curses.KEY_CODE_YES) { if (wch == Curses.KeyResize) { if (Curses.CheckWinChange()) { TerminalResized?.Invoke(); return; } } if (wch == Curses.KeyMouse) { Curses.MouseEvent ev; Curses.getmouse(out ev); mouseHandler(ToDriverMouse(ev)); return; } keyHandler(new KeyEvent(MapCursesKey(wch), keyModifiers)); keyUpHandler(new KeyEvent(MapCursesKey(wch), keyModifiers)); return; } // Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter as well as Alt-Fkey if (wch == 27) { Curses.timeout(10); code = Curses.get_wch(out int wch2); if (code == Curses.KEY_CODE_YES) { k = Key.AltMask | MapCursesKey(wch); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } if (code == 0) { KeyEvent key; // The ESC-number handling, debatable. // Simulates the AltMask itself by pressing Alt + Space. if (wch2 == (int)Key.Space) { k = Key.AltMask; key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 - (int)Key.Space >= 'A' && wch2 - (int)Key.Space <= 'Z') { k = (Key)((uint)Key.AltMask + (wch2 - (int)Key.Space)); key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 >= '1' && wch <= '9') { k = (Key)((int)Key.F1 + (wch2 - '0' - 1)); key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 == '0') { k = Key.F10; key = new KeyEvent(k, MapKeyModifiers(k)); } else if (wch2 == 27) { k = (Key)wch2; key = new KeyEvent(k, MapKeyModifiers(k)); } else { k = Key.AltMask | (Key)wch2; key = new KeyEvent(k, MapKeyModifiers(k)); } keyHandler(key); } else { k = Key.Esc; keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } } else if (wch == Curses.KeyTab) { k = MapCursesKey(wch); keyDownHandler(new KeyEvent(k, MapKeyModifiers(k))); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } else { k = (Key)wch; // In linux terminals, ControlH and ctrl+backspace send the same keycode if (k == Key.ControlH) { if (keyModifiers == null) { keyModifiers = new KeyModifiers(); } keyModifiers.Ctrl = true; k = Key.Backspace; } keyDownHandler(new KeyEvent(k, MapKeyModifiers(k))); keyHandler(new KeyEvent(k, MapKeyModifiers(k))); } // Cause OnKeyUp and OnKeyPressed. Note that the special handling for ESC above // will not impact KeyUp. // This is causing ESC firing even if another keystroke was handled. //if (wch == Curses.KeyTab) { // keyUpHandler (new KeyEvent (MapCursesKey (wch), keyModifiers)); //} else { // keyUpHandler (new KeyEvent ((Key)wch, keyModifiers)); //} }