liveBook · Manning

Raw mode

As explained in Python Concurrency with asyncio

Raw mode is a terminal input mode in which keystrokes are delivered directly to an application without terminal buffering, preprocessing, or echoing.

Raw mode sends every keystroke directly to the application instead of letting the terminal buffer, preprocess, or echo input. The application gains fine-grained output control, but must implement input handling itself. section 8.4.1

Using raw or cbreak-style input requires several application changes:

  • Read one character at a time with read(1), store characters in an internal buffer, and echo them explicitly. section 8.4.1
  • Handle editing such as backspace, then coordinate cursor movement and redraw output so asynchronous messages do not overwrite the input line. section 8.4.1
  • Choose cbreak mode when control keys such as CTRL-C should remain interpreted by the terminal. section 8.4.1

Interactive asynchronous console

A delay console enters cbreak mode, reads input character by character, stores messages in a bounded deque, and redraws asynchronous output above the persistent input line. The same design supports an asynchronous command-line SQL client.

How Python Concurrency with asyncio covers it

How deep it goes
Explains buffering, echoing, character reads, editing, cursor control, and redraw coordination without terminal internals.
Examples
Uses a delay console and an asynchronous command-line SQL client with character input and message redrawing.
What you can do after
Apply it via Python's tty module, character reads, explicit echoing, and coordinated terminal redraws.
How it connects
Contrasts cooked mode and cbreak mode, and connects terminal input with coroutines, standard output, and race conditions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.