Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/test-vt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Unit tests for the terminal emulator's color handling. */
#include <locale.h>
#include <sys/socket.h>
#include "../vt.c"

static int failures;
Expand Down Expand Up @@ -122,6 +123,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[?1;2c", "\033[?1;2c", "", "" };
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");
Expand All @@ -148,6 +173,7 @@ int main(void)
bool bundled = system(cmd) == 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) {
Expand Down
4 changes: 2 additions & 2 deletions vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,8 @@ static void interpret_csi(Vt *t)
send_curs(t);
break;
case 'c': /* primary device attributes, answer as a VT100 with advanced video */
if (t->ebuf[1] != '>' && (param_count == 0 || csiparam[0] == 0))
vt_write(t, "\033[?1;2c", 7);
if (t->ebuf[1] != '>' && t->ebuf[1] != '=' && (param_count == 0 || csiparam[0] == 0))
vt_write(t, "[?1;2c", 7);
break;
default:
break;
Expand Down
Loading