Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Keyboard & key mapping

When a key is pressed, it reaches your views as a key-down event; text widgets turn that keystroke into an editing command through a keymap. This page covers both halves: the key model your Views see, and the configurable Keymap that drives the editor and input line.

The key model

A keystroke is a physical Key plus a separate KeyModifiers channel, bundled into a KeyEvent. There are no modifier-combined variants: keys and modifiers are always separate. Ctrl+C is Key::Char('c') with ctrl set; Shift+Tab is Key::Tab with shift; Alt+F3 is Key::F(3) with alt. The enum holds only base keys: characters, function keys, and the navigation/editing keys (Enter, Tab, arrows, Home, PageUp, Insert, Delete, …). The three logical modifiers shift, ctrl, and alt collapse the platform's left/right distinctions (mirroring the C++ kb*Shift masks).

Two helpers bridge the old DOS conventions into this model:

  • ctrl_to_arrow maps the WordStar Ctrl-letter diamond (Ctrl+S/D/E/X and friends) to the equivalent arrow and navigation keys, clearing all modifiers on a match and passing everything else through unchanged. It is a faithful port of ctrlToArrow.
  • hot_key extracts the ~-delimited accelerator character from a label (uppercased), so a button or menu item knows which Alt+ chord activates it.

The keymap

tvision-rs extension: not in Turbo Vision. See Extensions beyond Turbo Vision.

Text input does not hard-wire keys to editing actions. Instead a Keymap maps a chord to a Command by name, in the same data-driven shape as a VS Code keybindings file. A chord is one keystroke, or two for a prefix sequence in the classic Ctrl-K/Ctrl-Q editor style. You describe chords as strings: space-separated strokes, each a +-joined list of modifiers ending in a key name.

#![allow(unused)]
fn main() {
use tvision_rs as tv;
let mut km = tv::keymap::Keymap::new();
km.bind("ctrl+s", tv::Command::CHAR_LEFT)        // single stroke
  .bind("ctrl+k ctrl+c", tv::Command::COPY)      // two-stroke prefix chord
  .bind("shift+insert", tv::Command::PASTE);     // shift kept where it matters
km.unbind("ctrl+s");
}

Keystrokes are normalized before lookup so the presets stay small and the historic behaviours survive. Alphabetic characters lowercase and drop shift (ctrl+q a equals ctrl+q A), and the cursor-pad keys drop shift too, since Shift+Left is a selection modifier handled inside the widget and has no binding of its own. Keys where shift carries meaning, such as Shift+Insert for paste, keep it.

Resolving a stroke (optionally combined with a pending prefix) yields a Resolve: a fully matched Command, a Prefix signal meaning "this begins a two-stroke chord, hold the next key", or None so the caller treats the key as insertable text or lets it bubble.

Presets and the global keymap

Three ready-made keymaps ship as constructors:

PresetConstructorFeel
WordStarKeymap::word_star()the classic editor diamond + Ctrl-K/Ctrl-Q blocks
CUA / OfficeKeymap::cua()modern Ctrl+C/X/V/Z muscle memory
EmacsKeymap::emacs()readline/Cocoa bindings (Ctrl+A/E/K/Y)

There is one process-global keymap, the default for all text input; it starts as word_star(). Swap it once at startup with set_global, and the editor and every input field follow:

#![allow(unused)]
fn main() {
use tvision_rs as tv;
tv::keymap::set_global(tv::keymap::Keymap::cua());
}

Widgets consult it via resolve_global. You rarely call that yourself; a custom text view calls it to join the same binding scheme.

Where to go next

  • Commands & events: what those resolved Commands do once a view consumes them.
  • Text editing: the Memo, Editor and input-line widgets the keymap drives.
  • Events → enum + match: the design behind the decomposed Key/KeyModifiers model, for Turbo Vision veterans.