Hello!
I'm trying to get ncurses working in a new platform (Nintendo DS using
[BlocksDS](https://blocksds.skylyrac.net/)). I've created a terminal emulator
that supports 16-color, 256-color and direct color commands (foreground and
background), as well as a few other commands like "bold", "move cursor" and
"clear screen". Basically, I'm cherry-picking terminfo configuration settings
from other terminals to create my own configuration based on what I actually
support, and I'm trying to understand every setting I use. So far I've managed
to get 16 and 256 color modes working, as well as moving the cursor around and
clearing the screen. However, I have two issues that I've spent a few days
debugging with no success. I've even added printf logs in ncurses in many
places (the trace system doesn't work for some reason) but ncurses has so many
build options and code paths that it's hard to know what actually gets used
(printf-debugging has helped to get color working, though).
----------------
1) 16 color mode doesn't work properly
The 8 color palette is shifted in a way that bits 0 and 2 are swapped when my
terminal receives the commands. This is the regular list of defines:
#define COLOR_BLACK 0
#define COLOR_RED 1
#define COLOR_GREEN 2
#define COLOR_YELLOW 3
#define COLOR_BLUE 4
#define COLOR_MAGENTA 5
#define COLOR_CYAN 6
#define COLOR_WHITE 7
and this is what I need to get it working properly:
#define COLOR_BLACK 0
#define COLOR_RED 4
#define COLOR_GREEN 2
#define COLOR_YELLOW 6
#define COLOR_BLUE 1
#define COLOR_MAGENTA 5
#define COLOR_CYAN 3
#define COLOR_WHITE 7
I've double-checked the definitions used by my terminal and they match the
right set of definitions (the first one). This issue doesn't happen with the
256-color palette for some reason. Any color over 16 is displayed correctly.
2) getch() only works for blocking input.
If I use `timeout(-1)` I can see calls to `read()`. They block as expected and
I can see that the value is received by ncurses. However, if I use `timeout(0)`
I never see any syscall being used. Maybe I'm looking at the wrong place, but
the same code works on PC, so I assume it's something to do with my port. I do
support setting non-blocking mode for `stdin` with `ioctl(FIONBIO)` and
`fcntl(F_SETFL, O_NONBLOCK)`, and I also support querying the amount of
characters available to read from `stdin` with `ioctl(FIONREAD)`, but I don't
know if this is even used by ncurses.
How does ncurses get new characters for non-blocking input?
----------------
This is my build configuration:
./configure \
--with-normal \
--without-shared --without-progs --without-manpages --without-tests \
--target=arm --host=arm --build=amd64 \
--disable-database --disable-db-install \
--disable-gnat-projects --disable-home-terminfo \
--enable-termcap \
--disable-widec \
--prefix=$PWD/mybuild \
--with-trace \
--enable-getcap \
--disable-sigwinch \
--enable-ext-colors --enable-rgb-color \
--enable-ext-mouse \
CFLAGS="-mthumb -mcpu=arm946e-s+nofp -O2 -ffunction-sections -fdata-sections
-I$BLOCKSDS/libs/libnds/include" \
BUILD_CC=gcc \
CC=arm-none-eabi-gcc \
cf_cv_have_tcgetattr=yes \
ac_cv_func_gettimeofday=yes \
ac_cv_type_sigset_t=no
And this is my list of environment variables (defined as an array of `char *`
in my source code):
{
"TERM=libnds",
"COLUMNS=42", // 6x8
"LINES=24", // 6x8
// https://man.cat-v.org/unix_10th/5/termcap
// https://www.man7.org/linux/man-pages/man5/terminfo.5.html
"TERMCAP=DS|libnds|libnds console:" // Terminal name
"co#42:li#24:" // Number of columns and lines (6x8 font)
"am:" // The cursor wraps when it reaches the rightmost column
"bs:" // Backspace is supported
"cm=\E[%d;%dH:" // Pattern to set cursor position
"NP:" // Pad character does not exist
"AX:" // Asserts that the terminal interprets SGR 39 and SGR 49
"op=\E[39;49m:"
"E3=\E[2J:" // How to clear the terminal's scrollback buffer.
"U8:" // Use UTF-8
//"Co#8:pa#64" // 8 colors, 64 pairs
//"Sf=\E[3%dm:" // Set foreground color
//"Sb=\E[4%dm:" // Set background color
"Co#256:pa#1000:" // 256 colors, 1000 pairs
"Sf=\E[38;5;%dm:"
"Sb=\E[48;5;%dm:"
// This doesn't seem to work (TODO: test again)
"md=\E[0;1m:" // Set bold mode
"me=\E[0m:", // Turn off all attributes
};
Thanks!
Antonio