From 7bc749362181dd7dec52eae85a0b138847dd188a Mon Sep 17 00:00:00 2001 From: Mark Paronyan Date: Mon, 28 Sep 2026 19:54:33 +0000 Subject: [PATCH] fix(vt): reply to primary device attributes query --- test/test-vt.c | 26 ++++++++++++++++++++++++++ vt.c | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/test/test-vt.c b/test/test-vt.c index 897b9f1..c3ce128 100644 --- a/test/test-vt.c +++ b/test/test-vt.c @@ -1,5 +1,6 @@ /* Unit tests for the terminal emulator's color handling. */ #include +#include #include "../vt.c" static int failures; @@ -112,6 +113,30 @@ static void test_term(const char *name, int red, int palette196, int rgb123, int fclose(in); } +static void test_device_attributes(void) +{ + term = "DA"; + const char *queries[] = { "\033[c", "\033[0c", "\033[>c", "\033[=c" }; + const char *replies[] = { "\033[?6c", "\033[?6c", "", "" }; + for (size_t i = 0; i < LENGTH(queries); i++) { + int fds[2]; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) + abort(); + Vt *t = vt_create(5, 10, 0); + t->pty = fds[0]; + if (write(fds[1], queries[i], strlen(queries[i])) != (ssize_t)strlen(queries[i])) + abort(); + vt_process(t); + fcntl(fds[1], F_SETFL, O_NONBLOCK); + char buf[16] = ""; + ssize_t len = read(fds[1], buf, sizeof buf - 1); + buf[len > 0 ? len : 0] = '\0'; + CHECK(!strcmp(buf, replies[i])); + close(fds[1]); + vt_destroy(t); + } +} + int main(void) { setlocale(LC_CTYPE, "C.UTF-8"); @@ -131,6 +156,7 @@ int main(void) bool direct = pclose(tic) == 0; setenv("TERMINFO", dir, 1); + test_device_attributes(); test_term("xterm", COLOR_RED, COLOR_RED, COLOR_BLACK, COLOR_BLACK); test_term("xterm-256color", 196, 196, 16, 16); if (direct) diff --git a/vt.c b/vt.c index f34313f..8a6b074 100644 --- a/vt.c +++ b/vt.c @@ -1102,6 +1102,10 @@ static void interpret_csi(Vt *t) if (param_count == 1 && csiparam[0] == 6) send_curs(t); break; + case 'c': + if (t->ebuf[1] != '>' && t->ebuf[1] != '=' && (param_count == 0 || csiparam[0] == 0)) + vt_write(t, "\e[?6c", 5); + break; default: break; }