diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dc70f92..ea392a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ ## Unreleased ### Added + +* Section to [README.md](README.md) describing how to programmatically + identify foot. + + ### Changed * Primary DA to no longer indicate support for _Selective Erase_, diff --git a/README.md b/README.md index 7aa29df4..de0f5b7a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ The fast, lightweight and minimalistic Wayland terminal emulator. 1. [Backspace](#backspace) 1. [DPI and font size](#dpi-and-font-size) 1. [Supported OSCs](#supported-oscs) +1. [Programmatically checking if running in foot](#programmatically-checking-if-running-in-foot) 1. [Requirements](#requirements) 1. [Running](#running) 1. [Building](#building) @@ -301,6 +302,39 @@ with the terminal emulator itself. Foot implements the following OSCs: * `OSC 555` - flash screen (**foot specific**) +## Programmatically checking if running in foot + +Foot does **not** set any environment variables that can be used to +identify foot (reading `TERM` is not reliable since the user may have +chosen to use a different terminfo). + +You can instead use the escape sequences to read the _Secondary_ and +_Tertiary Device Attributes_ (secondary/tertiary DA, for short). + +The tertiary DA response is always `\EP!|464f4f54\E\\`. The `\EP!|` is +the standard tertiary DA response prefix, `DCS ! |`. The trailing +`\E\\` is of course the standard string terminator, `ST`. + +In the response above, the interresting part is `464f4f54`; this is +the string _FOOT_ in hex. + +The secondary DA response is `\E[>1;XXYYZZ;0c`, where XXYYZZ is foot's +major, minor and patch version numbers, in decimal, using two digits +for each number. For example, foot-1.4.2 would respond with +`\E[>1;010402;0c`. + +**Note**: not all terminal emulators implement tertiary DA. Most +implement secondary DA, but not all. All _should_ however implement +_Primary DA_. + +Thus, a safe way to query the terminal is to request the tertiary, +secondary and primary DA all at once, in that order. All terminals +should ignore escape sequences they do not recognize. You will have to +parse the response (which in foot will consist of all three DA +responses, all at once) to determine which requests the terminal +emulator actually responded to. + + ## Requirements ### Running