Why is typing so strange in terminals

keyboardterminal

When typing in a terminal, why is it that text does not behave the way it would in any other text environment, like in any text editor or browser? Things like highlighting text while moving the cursor using typical key bindings (Meta+Shift+Arrow Key) and simply just deleting the current highlighted text by pressing backspace are not possible.

Is this behavior necessary for a terminal to stay compatible or caused by some restriction that I am not thinking of? Sorry if this is a dumb question. Thank you.

Best Answer

The terminal does not behave the way that you expect because it is made to emulate the behavior of a DEC VT100 terminal. Computer terminals — such as the VT100 — did not have a mouse, so any actions that is triggered by the mouse is bolted on as an afterthought. Most terminal emulators default to a set of keybindings that are similar to those of Emacs (a text editor), but this layer (provided by GNU Readline) does not provide mechanisms for selecting text and whatever else you are describing.

It is up to the terminal emulator (for example, Terminal.app or iTerm2) to define what events are triggered upon mouse clicks and text selection. For example, hitting Option ⌥, followed by a mouse click somewhere in your current prompt will place your cursor at that position. If you select a piece of text and hit backspace Delete ⌦, only a single character at your current cursor position will be deleted because the terminal that is being emulated does not have the notion of text selection by itself.