/* SPDX-License-Identifier: GPL-2.0-or-later * * ncurses acceptance test for SchOS. * * The question this answers is not "did the library compile" -- that much the * build already proved -- but "does terminfo work on a SchOS console". Those * are different questions, because ncurses can link, initialise, and then * return null for every capability it is asked for, at which point a line * editor draws nothing and blames itself. * * So: initialise against the compiled-in fallback, then ask for exactly the * capabilities zsh's ZLE needs, and print what came back. Anything reported * MISSING here will be a missing feature in the shell later. */ #include #include #include #include #include #include #include static int failures; /* Capability present and non-empty, or a named failure. The distinction * matters: tigetstr returns (char *)-1 for "no such capability in this * terminal's description" and NULL for "not in the database at all", and * only the second means the port is broken. */ static void cap(const char *name, const char *what) { char *v = tigetstr((char *)name); if (v == (char *)-1) { printf(" %-8s %-22s ABSENT (not in this terminal type)\n", name, what); } else if (v == NULL) { printf(" %-8s %-22s MISSING\n", name, what); failures++; } else { printf(" %-8s %-22s ok (%d bytes)\n", name, what, (int)strlen(v)); } } int main(void) { struct winsize ws; const char *term = getenv("TERM"); int err = 0; printf("ncurses %s on SchOS\n\n", curses_version()); /* The kernel's idea of the screen, which is what everything lays out * against. A hardcoded 80x24 here used to be a kernel bug; print the * numbers so a regression is visible rather than merely wrong. */ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0) printf("TIOCGWINSZ %d cols x %d rows (%dx%d px)\n", ws.ws_col, ws.ws_row, ws.ws_xpixel, ws.ws_ypixel); else { printf("TIOCGWINSZ FAILED\n"); failures++; } if (!term) { printf("TERM unset -- falling back to \"linux\"\n"); term = "linux"; } else { printf("TERM %s\n", term); } /* The whole point of --disable-database: this must succeed with no * /usr/share/terminfo anywhere on the system. */ if (setupterm((char *)term, STDOUT_FILENO, &err) != OK) { printf("\nsetupterm failed (err=%d) -- no compiled-in fallback for " "\"%s\"\n", err, term); return 1; } printf("setupterm ok, from compiled-in fallback (no terminfo files)\n"); printf(" %s\n\n", longname()); printf("capabilities a line editor needs:\n"); cap("cup", "absolute cursor move"); cap("cuu1", "cursor up"); cap("cud1", "cursor down"); cap("cub1", "cursor left"); cap("cuf1", "cursor right"); cap("el", "erase to end of line"); cap("ed", "erase to end of screen"); cap("clear", "clear screen"); cap("bold", "bold"); cap("sgr0", "reset attributes"); cap("setaf", "set foreground colour"); printf("\nkeys ZLE binds:\n"); cap("kcuu1", "up arrow"); cap("kcud1", "down arrow"); cap("kcub1", "left arrow"); cap("kcuf1", "right arrow"); cap("khome", "home"); cap("kend", "end"); cap("kdch1", "delete"); printf("\nnumbers:\n"); printf(" colors %d\n", tigetnum((char *)"colors")); printf(" cols %d\n", tigetnum((char *)"cols")); printf(" lines %d\n", tigetnum((char *)"lines")); /* Finally, actually drive the terminal. Everything above only read the * description; this proves the escape sequences reach the console and * that its ANSI parser accepts what ncurses emits. */ printf("\noutput test: "); fflush(stdout); char *bold = tigetstr((char *)"bold"), *sgr0 = tigetstr((char *)"sgr0"); if (bold && bold != (char *)-1 && sgr0 && sgr0 != (char *)-1) { putp(bold); printf("this should be bold"); putp(sgr0); fflush(stdout); } printf("\n\n%s\n", failures ? "FAIL" : "PASS"); return failures ? 1 : 0; }