/// <summary> /// Initializes a new instance of the <see cref="TerminalKeyInfo"/> class. /// </summary> /// <param name="keyChar"> /// The Unicode character associated with this instance. /// </param> /// <param name="key"> /// The terminal key represented by this instance. /// </param> /// <param name="shift"> /// Indicates whether the shift key was pressed. /// </param> /// <param name="alt"> /// Indicates whether the alt key was pressed. /// </param> /// <param name="control"> /// Indicates whether the control key was pressed. /// </param> public TerminalKeyInfo( char keyChar, TerminalKey key, bool shift, bool alt, bool control) { if (!TerminalKeyInfo.CachedKeys.Contains(key)) { throw new ArgumentException("Unrecognized key.", nameof(key)); } this.Key = key; this.KeyChar = keyChar; this.Modifiers = default; if (shift) { this.Modifiers |= TerminalModifiers.Shift; } if (alt) { this.Modifiers |= TerminalModifiers.Alt; } if (control) { this.Modifiers |= TerminalModifiers.Control; } }
public void ControlKeyPressed(TerminalKey key, TerminalKeyModifiers state) { switch (key) { case TerminalKey.Up: ResetColumn(); NavigationUpInHistory(); break; case TerminalKey.Down: ResetColumn(); NavigationDownInHistory(); break; case TerminalKey.End: MoveToEnd(); ResetHistoryNavigation(); break; case TerminalKey.Home: MoveToBegining(); ResetHistoryNavigation(); break; case TerminalKey.Left: MoveLeft(); ResetHistoryNavigation(); break; case TerminalKey.Right: MoveRight(); ResetHistoryNavigation(); break; case TerminalKey.Insert: ResetHistoryNavigation(); break; case TerminalKey.Delete: DeletePressed(); ResetHistoryNavigation(); break; default: ResetHistoryNavigation(); break; } }
public bool SendKey(TerminalKey key) { if (key == TerminalKey.CtrlG) { if (DoneEvent != null) DoneEvent(this, new DoneEventArgs(null)); return true; } if (key == TerminalKey.Enter) { if (DoneEvent != null) DoneEvent(this, new DoneEventArgs(Entry.Text)); return true; } return Entry.SendKey(key); }
public DismissEventArgs(TerminalKey k) { Key = k; }
public bool SendKey(TerminalKey key) { if (DismissEvent != null) DismissEvent(this, new DismissEventArgs(key)); return true; }
static void SendKey(TerminalKey k) { if (k == TerminalKey.CtrlL) Terminal.Clear(); if (k == TerminalKey.Resize) { int w, h; Terminal.GetSize(out h, out w); foreach (IWidget layer in widgets) layer.SetSize(h, w, 0, 0); Terminal.Clear(); } if (widgets.Count > 0) widgets[widgets.Count - 1].SendKey(k); }
public bool SendKey(TerminalKey key) { switch (key) { case ((TerminalKey)'\\'): config.HalfWidth = !config.HalfWidth; stableReflow(); return true; case TerminalKey.Home: case ((TerminalKey)'<'): cursor = 0; fixScroll(); return true; case TerminalKey.End: case ((TerminalKey)'>'): cursor = pasteBoard.LineCount - 1; fixScroll(); return true; case TerminalKey.Up: case ((TerminalKey)'k'): if (cursor > 0) { cursor--; fixScroll(); } return true; case TerminalKey.Down: case ((TerminalKey)'j'): if (cursor + 1 < pasteBoard.LineCount) { cursor++; fixScroll(); } return true; case TerminalKey.Left: gotoPrevLink(); return true; case TerminalKey.Right: gotoNextLink(); return true; case TerminalKey.PageUp: case TerminalKey.CtrlP: if (cursor > height) { cursor -= height; scroll -= height; } else { cursor = 0; } fixScroll(); return true; case TerminalKey.PageDown: case TerminalKey.CtrlN: if (cursor + height < pasteBoard.LineCount) { cursor += height; scroll += height; } else { cursor = pasteBoard.LineCount - 1; } fixScroll(); return true; case ((TerminalKey)'/'): searchQuery.Entry.Reset(); searchQuery.Entry.History = config.SearchHistory.ToArray(); if (searchQuery.Run() != null) { config.SearchHistory.Add(searchQuery.Entry.Text); searchForward(); } return true; case ((TerminalKey)'?'): searchQuery.Entry.Reset(); if (searchQuery.Run() != null) { config.SearchHistory.Add(searchQuery.Entry.Text); searchBack(); } return true; case ((TerminalKey)'n'): searchForward(); return true; case ((TerminalKey)'p'): searchBack(); return true; } return false; }
public void ControlKeyPressed( TerminalKey key, TerminalKeyModifiers state ) { switch( key ) { case TerminalKey.Up: ResetColumn(); NavigationUpInHistory(); break; case TerminalKey.Down: ResetColumn(); NavigationDownInHistory(); break; case TerminalKey.End: MoveToEnd(); ResetHistoryNavigation(); break; case TerminalKey.Home: MoveToBegining(); ResetHistoryNavigation(); break; case TerminalKey.Left: MoveLeft(); ResetHistoryNavigation(); break; case TerminalKey.Right: MoveRight(); ResetHistoryNavigation(); break; case TerminalKey.Insert: ResetHistoryNavigation(); break; case TerminalKey.Delete: DeletePressed(); ResetHistoryNavigation(); break; default: ResetHistoryNavigation(); break; } }
public bool SendKey(TerminalKey key) { if (key != TerminalKey.Tab) { completionList = null; completionIndex = -1; } switch (key) { case TerminalKey.Tab: if (completionList == null) { completionList = completer(buffer.ToString()); completionIndex = -1; } if ((completionList != null) && (completionList.Length > 0)) { completionIndex = (completionIndex + 1) % completionList.Length; buffer.Clear(); buffer.Append(completionList[completionIndex]); cursor = buffer.Length; fixScroll(); } return true; case TerminalKey.Up: if ((historyList != null) && historyList.Length > 0) { if (historyIndex >= 0) historyIndex--; else historyIndex = historyList.Length - 1; buffer.Clear(); if (historyIndex >= 0) buffer.Append(historyList[historyIndex]); cursor = buffer.Length; fixScroll(); } return true; case TerminalKey.Down: if ((historyList != null) && historyList.Length > 0) { if (historyIndex >= 0) historyIndex++; if (historyIndex >= historyList.Length) historyIndex = -1; buffer.Clear(); if (historyIndex >= 0) buffer.Append(historyList[historyIndex]); cursor = buffer.Length; fixScroll(); } return true; case TerminalKey.Left: if (cursor > 0) { cursor--; fixScroll(); } return true; case TerminalKey.Right: if (cursor < buffer.Length) { cursor++; fixScroll(); } return true; case TerminalKey.CtrlH: case TerminalKey.Backspace: case TerminalKey.Delete: if (cursor > 0) { buffer.Remove(cursor - 1, 1); cursor--; fixScroll(); } return true; case TerminalKey.CtrlD: if (cursor < buffer.Length) buffer.Remove(cursor, 1); return true; case TerminalKey.Home: case TerminalKey.CtrlA: cursor = 0; fixScroll(); return true; case TerminalKey.End: case TerminalKey.CtrlE: cursor = buffer.Length; fixScroll(); return true; case TerminalKey.CtrlK: Clipboard.Content = buffer.ToString(cursor, buffer.Length - cursor); buffer.Remove(cursor, buffer.Length - cursor); return true; case TerminalKey.CtrlU: Clipboard.Content = buffer.ToString(0, cursor); buffer.Remove(0, cursor); cursor = 0; fixScroll(); return true; case TerminalKey.CtrlY: if (Clipboard.Content != null) { string text = Clipboard.Content; buffer.Insert(cursor, text); cursor += text.Length; fixScroll(); } return true; default: if ((int)key >= 32 && (int)key < 127) { char ch = (char)key; buffer.Insert(cursor, ch); cursor++; fixScroll(); return true; } break; } return false; }
public bool SendKey(TerminalKey key) { Save(); switch (key) { case TerminalKey.Enter: followLink(); return true; case TerminalKey.Backspace: case TerminalKey.Delete: case TerminalKey.CtrlH: GoBack(); return true; case TerminalKey.CtrlF: GoForward(); return true; case ((TerminalKey)'#'): if (currentBook.BookText != null) { string link = docView.ActiveLink; if (link != null) StatusMessage.Say(link); } return true; case ((TerminalKey)'h'): OpenBook(BookInfo.GetHelp()); return true; case ((TerminalKey)'t'): PreNavigate(history); openToc(-1); return true; case ((TerminalKey)'T'): PreNavigate(history); openToc(0); return true; case ((TerminalKey)'b'): if ((currentBook != null) && (docView.Document != currentBook.BookText)) { int pos; docView.Document = currentBook.BookText; if ((currentBook.Filename != null) && config.Bookmarks.TryGetValue(currentBook.Filename, out pos)) docView.WordPos = pos; } return true; case ((TerminalKey)'o'): openQuery.Entry.Reset(); openQuery.Entry.History = config.Bookmarks.ToKeysArray(); for (;;) { if (openQuery.Run() == null) break; if (TryOpenFile(openQuery.Entry.Text)) break; } return true; } return docView.SendKey(key); }