Terminal input and output modes

Prior to Windows 10 the console supported only Microsoft’s proprietary WinAPI with a rich set of functions. But this console API is not compatible with Unix terminals utilizing ANSI sequences to modify terminal from console application and passing keyboard and mouse input from terminal to console.

ConEmu supports both modes almost transparently. The console application could utilize both WinAPI to control terminal and emit ANSI sequences to do some extra things. At the same time are supported cygwin applications, which don’t use WinAPI and were created to use POSIX console emulation.

Terminal input mode

In Windows console applications are able to read inputs from terminal in form of rich INPUT_RECORD structure. Each keypress is encoded wVirtualKeyCode + dwControlKeyState fields and could have UnicodeChar.

But Unix terminals operate with text streams only and all special keys (functional and navigational keys). For example when the F12 key is pressed the console application receives a sequence ESC [ 2 4 ~.

ConEmu could be switched between Windows and Unix (XTerm) modes in several ways. XTerm is activated when:

XTerm mode is changed back to Windows when:

App Keys mode (DECCKM)

One special note for XTerm mode.

Navigational keys could be encoded in two ways. For example when the Left arrow key is pressed the console application receives either ESC O D or ESC [ D sequences depending of DECCKM mode on/off. Console application enables/disables DECCKM emitting ANSI sequences ESC [ ? 1 h or ESC [ ? 1 l.

Unfortunately in some cases ConEmu does not receive the appropriate sequences and could not change DECCKM mode. In that case user can change ‘App Keys’ mode in the StatusBar or apply some default via -new_console switch.

Terminal output mode

ConEmu processes ANSI sequences in both modes if requirements are fulfilled.

But for XTerm mode there are some differences in processing output. Most vivid difference is cursor movement when last cell in a row is written. With default Windows behavior the cursor is moved immediately to the next row, which in turn scrolls console content upwards if cursor was at the bottom of the working area. But in XTerm emulation the cursor stays after the last character in a row and moved to the next row only after next character is written to output. This trick is used in Unit tools to display status line or keys bar panel, which is usually at the bottom of the terminal’s visible area.

Usually the XTerm output mode is enabled with XTerm input automatically. But in some cases application could rely on the XTerm output rules but read input via WinApi using INPUT_RECORD.

The XTerm output mode is enabled when:

ConEmu switches back to Windows mode when:

Terminal modes in Status Bar

StatusBar column ‘Terminal modes’ shows current option and Left Mouse Button click shows popup menu where you may change options if ConEmu could not change them automatically.

Terminal Modes in Status Bar

Terminal modes in the Settings/Info page

Settings/Info page also show current terminal options as well as console input/output modes, coordinates and sizes of the console, running processes and more.

-new_console switch

You may change Task startup mode with -new_console switch. Just add to your Task command:

  • -new_console:p5 to enable ‘XTerm’ with ‘AppKeys’;
  • -new_console:p1 to enable ‘XTerm’ without ‘AppKeys’.
Download    Donate