zsh's configure will happily build without a terminal library -- the probe is AC_SEARCH_LIBS, which is soft -- and produce a shell whose cursor cannot move and whose arrow keys do nothing. ZLE is the reason to want zsh, so this comes first. MIT, so it combines with Apache-2.0 without conditions. Built static, widec (which is what zsh looks for first, and the console's UTF-8 decoder can already take), and --disable-database --with-fallbacks so seven terminal descriptions are compiled into the library. SchOS has no business shipping /usr/share/terminfo, and with the fallbacks the .a is self-contained: verified that no terminfo path strings survive in the binary. Nothing reaches sysroot/ -- a static library is not a file the OS ships -- so `install` means into $(PREFIX). port.mk gains NCURSES beside MUSL for the same reason MUSL is there. tinfotest.c is the acceptance test, and asks the question the build cannot: not "did it link" but "does terminfo work on a SchOS console". It reports TIOCGWINSZ, initialises from the compiled-in fallback, and names every capability ZLE binds. Anything MISSING there is a missing feature in the shell later. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
121 lines
4.1 KiB
C
121 lines
4.1 KiB
C
/* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* 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 <curses.h>
|
|
#include <term.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
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;
|
|
}
|