Back to Terminal

Understanding Console Host Settings

doc/ConsoleHostSettings.md

1.25.1171.06.4 KB
Original Source

Understanding Console Host Settings

Settings in the Windows Console Host can be a bit tricky to understand. This is mostly because the settings system evolved over the course of decades. Before we dig into the details of how settings are persisted, it's probably worth taking a quick look at what these settings are.

Settings Description

NameTypeDescription
FontSizeCoordinate (REG_DWORD)Size of font in pixels
FontFamilyREG_DWORDGDI Font family
ScreenBufferSizeCoordinate (REG_DWORD)Size of the screen buffer in WxH characters**
CursorSizeREG_DWORDCursor height as percentage of a single character
WindowSizeCoordinate (REG_DWORD)Initial size of the window in WxH characters**
WindowPositionCoordinate (REG_DWORD)Initial position of the window in WxH pixels (if not set, use auto-positioning)
WindowAlphaREG_DWORDOpacity of the window (valid range: 0x4D-0xFF)
ScreenColorsREG_DWORDDefault foreground and background colors
PopupColorsREG_DWORDFG and BG colors used when displaying a popup window (e.g. when F2 is pressed in CMD.exe)
QuickEditREG_DWORDWhether QuickEdit is on by default or not
FaceNameREG_SZName of font to use (or "DefaultTTFont", which defaults to whichever font is deemed most appropriate for your codepage)
FontWeightREG_DWORDGDI font weight
InsertModeREG_DWORDWhether Insert mode is on by default or not
HistoryBufferSizeREG_DWORDNumber of history entries to retain
NumberOfHistoryBuffersREG_DWORDNumber of history buffers to retain
HistoryNoDupREG_DWORDWhether to retain duplicate history entries or not
ColorTable%%REG_DWORDFor each of the 16 colors in the palette, the RGB value of the color to use
ExtendedEditKeyREG_DWORDWhether to allow the use of extended edit keys or not
WordDelimitersREG_SZA list of characters that are considered as delimiting words (e.g. `' .-/=
TrimLeadingZerosREG_DWORDWhether to remove zeroes from the beginning of a selected string on copy (e.g. 00000001 becomes 1)
EnableColorSelectionREG_DWORDWhether to allow selection colorization or not
ScrollScaleREG_DWORDHow many lines to scroll when using `SHIFT
CodePageREG_DWORDThe default codepage to use
ForceV2REG_DWORDWhether to use the improved version of the Windows Console Host
LineSelection*REG_DWORDWhether to use wrapped text selection
FilterOnPaste*REG_DWORDWhether to replace characters on paste (e.g. Word "smart quotes" are replaced with regular quotes)
LineWrap*REG_DWORDWhether to have the Windows Console Host break long lines into multiple rows
CtrlKeyShortcutsDisabled*REG_DWORDDisables new control key shortcuts
AllowAltF4Close*REG_DWORDAllows the user to disable the Alt-F4 hotkey
VirtualTerminalLevel*REG_DWORDThe level of VT support provided by the Windows Console Host

*: Only applies to the improved version of the Windows Console Host

**: WxH stands for Width by Height, it's the fact that things like a Window size store the Width and Height values in the high and low word in the registry's double word values.

The Settings Hierarchy

Settings are persisted to a variety of locations depending on how they are modified and how the Windows Console Host was invoked:

  • Hardcoded settings in conhostv2.dll
  • User's configured defaults (stored as values in HKCU\Console)
  • Per-console-application storage (stored as subkeys of HKCU\Console). Subkey names:
    • Console application path (with \ replaced with _)
    • Console title
  • Windows shortcut (.lnk) files

To modify the defaults, invoke the Defaults titlebar menu option on a Windows Console Host window. Any changes made in the resulting dialog will be persisted to the registry location mentioned above.

To modify settings specific to the current application, invoke the Properties titlebar menu option on a Windows Console Host window. If the application was launched directly (e.g. via the Windows run dialog), changes made in the dialog will be persisted in the per-application storage location mentioned above. If the application was launched via a Windows shortcut file, changes made in the settings dialog will be persisted directly into the .lnk file. For console applications with a shortcut, you can also right-click on the shortcut file and choose Properties to access the settings dialog.

When console applications are launched, the Windows Console Host determines which settings to use by overlaying settings from the above locations.

  1. Initialize settings based on hard-coded defaults
  2. Overlay settings specified by the user's configured defaults
  3. Overlay application-specific settings from either the registry or the shortcut file, depending on how the application was launched

Note that the registry settings are "sparse" settings repositories, meaning that if a setting isn't present, then whatever value that is already in use remains unchanged. This allows users to have some settings shared amongst all console applications and other settings be specific. Shortcut files, however, store each setting regardless of whether it was a default setting or not.

Known Issues

  • Modifications to system-created Start Menu and Win-X menu console applications are not kept during upgrade.

Adding settings

Adding a setting involves a bunch of steps - see AddASetting.md.