public override bool ProcessKey (int key) { var result = true; switch (key) { case (int) '>' + Curses.KeyAlt: MoveBottom (); break; case (int) '<' + Curses.KeyAlt: MoveTop (); break; case Keys.UP: case 16: // Control-p result = MoveUp (); break; case Keys.DOWN: case 14: // Control-n result = MoveDown (); break; case 22: // Control-v case Keys.NPAGE: PageDown (); break; case (int) '\n': Action (); break; case Keys.PPAGE: case (int)'v' + Curses.KeyAlt: PageUp (); break; case Keys.INSERTKEY: //Curses.KeyInsertChar: case 20: // Control-t if (listing [selected].Name == "..") return true; listing [selected].Marked = !listing [selected].Marked; if (listing [selected].Marked) marked++; else marked--; MoveDown (); break; default: result = false; break; } if (result) Stdscr.Refresh (); return result; }
void SetWrap(bool wrap) { if (view.Wrap) { view.Wrap = false; bar_labels [1] = "Wrap"; } else { view.Wrap = true; bar_labels [1] = "Unwrap"; } Stdscr.Refresh(); }
void GoBottom() { long last = source.Length; SetPosition(last); var newtop = Scan(last > 0 ? last - 1 : 0, -h + 1); if (newtop == -1) { return; } SetTopByte(newtop); Redraw(); Stdscr.Refresh(); }
private void Run() { Initialize(); while (true) { Stdscr.Erase(); for (int i = 0; i < lines.Length; ++i) { if (offsets[i] <= 0) { lines[i] = null; offsets[i] = 0; } if (lines[i] == null) { lines[i] = TEXT_LINES[rng.Next(TEXT_LINES.Length)]; offsets[i] = colcount + lines[i].Length; } int of = colcount - offsets[i]; string str = lines[i]; if (of < 0) { int ln = Math.Min(str.Length + of, colcount); str = str.Substring(-of, ln); of = 0; } else { int ln = Math.Min(Math.Min(offsets[i], str.Length), colcount); str = str.Substring(0, ln); } Stdscr.Add(i, of, str); offsets[i]--; } Stdscr.Refresh(); switch (Stdscr.GetChar()) { case 'q': case 'Q': Curses.CursorVisibility = 1; return; default: break; } Curses.NapMs(100); } }
/// <summary> /// Forces a repaint of the screen. /// </summary> /// <remarks> /// </remarks> public static void Refresh() { Container last = null; main_window.Redraw(); foreach (Container c in toplevels) { c.Redraw(); last = c; } Stdscr.Refresh(); if (last != null) { last.PositionCursor(); } }
// Invoke this method instead of Redraw+refresh, as this takes care of updating while // scrolling fast. void UpdateView() { if (Terminal.MainLoop.EventsPending()) { if (dirty < 10 && (DateTime.UtcNow - dirtystart) < TimeSpan.FromMilliseconds(500)) { Log("Skipped update, dirty={0} time={1}", dirty, DateTime.UtcNow - dirtystart); return; } } // to test the dirty system: // System.Threading.Thread.Sleep (500); Redraw(); Stdscr.Refresh(); dirty = 0; }
public static void Main(string[] args) { // C style from http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html // initscr(); /* Start curses mode */ // printw("Hello World !!!"); /* Print Hello World */ // refresh(); /* Print it on to the real screen */ // getch(); /* Wait for user input */ // endwin(); /* End curses mode */ Curses.InitScr(); Stdscr.Add("Hello World !!!"); Stdscr.Refresh(); Stdscr.GetChar(); Curses.Beep(); Curses.EndWin(); }
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(); }
/// <summary> /// Starts running a new container or dialog box. /// </summary> /// <remarks> /// Use this method if you want to start the dialog, but /// you want to control the main loop execution manually /// by calling the RunLoop method (for example, to start /// the dialog, but continuing to process events). /// /// Use the returned value as the argument to RunLoop /// and later to the End method to remove the container /// from the screen. /// </remarks> static public RunState Begin(Container container) { if (container == null) { throw new ArgumentNullException("container"); } var rs = new RunState(container); Init(); Stdscr.ReadTimeout = -1; toplevels.Add(container); container.Prepare(); container.SizeChanged(); container.FocusFirst(); Redraw(container); container.PositionCursor(); Stdscr.Refresh(); return(rs); }
private static void MyRefresh() { Curses.NapMs(DELAYSIZE); Stdscr.Move(Curses.Lines - 1, Curses.Cols - 1); Stdscr.Refresh(); }
static void ProcessChar(Container container) { int ch = Stdscr.GetChar(); if ((ch == -1) || (ch == Keys.RESET)) { // TODO: Fixme // if (Curses.CheckWinChange ()){ // EmptyContainer.Clear (); // foreach (Container c in toplevels) // c.SizeChanged (); // Refresh (); // } return; } // Control-c, quit the current operation. if (ch == Keys.CTRLC || ch == Keys.ESC) { container.Running = false; return; } if (ch == Keys.MOUSE) { MouseEvent ev = Curses.GetMouse(); container.ProcessMouse(ev); return; } if (ch == Keys.ESC) { Stdscr.ReadTimeout = 100; int k = Stdscr.GetChar(); if (k != Curses.ERR && k != Keys.ESC) { ch = Curses.KeyAlt | k; } Stdscr.ReadTimeout = -1; } if (container.ProcessHotKey(ch)) { return; } if (container.ProcessKey(ch)) { return; } if (container.ProcessColdKey(ch)) { return; } // Control-z, suspend execution, then repaint. if (ch == Keys.CTRLZ) { Curses.SendSignalToStop(); // TODO: Fixme ;-) This is broken on return container.Redraw(); Stdscr.Refresh(); return; } // // Focus handling // if (ch == 9 || ch == Keys.DOWN || ch == Keys.RIGHT) { if (!container.FocusNext()) { container.FocusNext(); } Stdscr.Refresh(); } else if (ch == Keys.UP || ch == Keys.LEFT) { if (!container.FocusPrev()) { container.FocusPrev(); } Stdscr.Refresh(); } }
static void Redraw(Container container) { container.Redraw(); Stdscr.Refresh(); }
void GoTop() { SetTopByte(first_file_byte); Redraw(); Stdscr.Refresh(); }