diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ad10db9..3ec5ccb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -301,6 +301,9 @@ (https://codeberg.org/dnkl/foot/issues/395). * Completions for Bash shell (https://codeberg.org/dnkl/foot/issues/10). +* Implement `XTVERSION` (`CSI > 0q`). Foot will reply with + `DCS>|foot(..)ST` + (https://codeberg.org/dnkl/foot/issues/359). ### Changed diff --git a/csi.c b/csi.c index 2d497636..fcc2800f 100644 --- a/csi.c +++ b/csi.c @@ -1565,6 +1565,22 @@ csi_dispatch(struct terminal *term, uint8_t final) } break; /* final == 'm' */ + case 'q': { + /* XTVERSION */ + if (vt_param_get(term, 0, 0) != 0) { + UNHANDLED(); + break; + } + + char reply[64]; + size_t n = xsnprintf( + reply, sizeof(reply), "\033P>|foot(%u.%u.%u%s%s)\033\\", + FOOT_MAJOR, FOOT_MINOR, FOOT_PATCH, + FOOT_EXTRA[0] != '\0' ? "-" : "", FOOT_EXTRA); + term_to_slave(term, reply, n); + break; + } + default: UNHANDLED(); break; diff --git a/doc/foot-ctlseqs.7.scd b/doc/foot-ctlseqs.7.scd index 6862b45c..22cfc447 100644 --- a/doc/foot-ctlseqs.7.scd +++ b/doc/foot-ctlseqs.7.scd @@ -549,6 +549,11 @@ manipulation sequences. The generic format is: : XTSMGRAPHICS : xterm : Set or request sixel attributes. +| \\E > _Ps_ q +: XTVERSION +: xterm +: _Ps_=0 -> report terminal name and version, in the form + *\\EP>|foot(version)\\E\\*. # OSC diff --git a/generate-version.sh b/generate-version.sh index cfb85059..b539ce42 100755 --- a/generate-version.sh +++ b/generate-version.sh @@ -22,14 +22,16 @@ else new_version="${default_version}" fi -major=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1/') -minor=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\2/') -patch=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\3/') +major=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9]+-g[a-z0-9]+) .*)?/\1/') +minor=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9]+-g[a-z0-9]+) .*)?/\2/') +patch=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9]+-g[a-z0-9]+) .*)?/\3/') +extra=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9]+-g[a-z0-9]+) .*)?/\5/') new_version="#define FOOT_VERSION \"${new_version}\" #define FOOT_MAJOR ${major} #define FOOT_MINOR ${minor} -#define FOOT_PATCH ${patch}" +#define FOOT_PATCH ${patch} +#define FOOT_EXTRA \"${extra}\"" if [ -f "${out_file}" ]; then old_version=$(cat "${out_file}")