NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: curses(3) handling of UTF-8 in various programs



Hello Cág, Brett and netbsd-users@!
(I'll reply to both emails here)

Cág writes:
> [...]
> I don't understand whether it's a curses(3) thing or a program bug, but
> linking against ncursesw makes noice display the name correctly.
> [...]

At least regarding the noice problem, that's just a kludge but a
possible patch that workaround the problem is attached in this email
(it can be used as a LOCALPATCHES for sysutils/noice).
Most printw() calls in noice seems easy to be changed to addstr() ones
and with them the single bytes are output as-is (IIUC!).

Brett Lymn writes:
> [...]
> More than likely an application bug but one that is hidden by the
> behaviour of ncursss.  It is hard to say without looking at the code but
> it could be something in the terminal initialisation or environment that
> is changing what is on the screen... The complicating factor in some
> situations is the differences in the interpretation done by the terminal
> doing the display (though, in this case I don't think this applies).
> [...]

The following code should be enough to reproduce what happens in
noice via argv[]:

   #include <locale.h>
   #include <curses.h>
   
   int
   main(int argc, char *argv[])
   {
           int i;
   
           setlocale(LC_ALL, "");
   
           initscr();
           for (i = 1; i < argc; i++)
                   printw("%s\n", argv[i]);
           getch();
           endwin();
   
           return 0;
   }
$NetBSD$

Directly use addstr() instead of printw() in order to output every
bytes without any transformation (and hence also correctly displaying
Unicode characters).

--- noice.c.orig	2018-08-10 18:55:47.299592935 +0200
+++ noice.c	2018-08-10 19:01:15.778111428 +0200
@@ -293,7 +293,8 @@
 printmsg(char *msg)
 {
 	move(LINES - 1, 0);
-	printw("%s\n", msg);
+	addstr(msg);
+	addstr("\n");
 }
 
 /* Display warning as a message */
@@ -324,7 +325,7 @@
 printprompt(char *str)
 {
 	clearprompt();
-	printw(str);
+	addstr(str);
 }
 
 /* Returns SEL_* if key is bound and 0 otherwise.
@@ -428,10 +429,16 @@
 	if (strlen(name) > maxlen)
 		name[maxlen] = '\0';
 
-	if (cm == 0)
-		printw("%s%s\n", active ? CURSR : EMPTY, name);
-	else
-		printw("%s%s%c\n", active ? CURSR : EMPTY, name, cm);
+	if (cm == 0) {
+		addstr(active ? CURSR : EMPTY );
+		addstr(name);
+		addstr("\n");
+	} else {
+		addstr(active ? CURSR : EMPTY);
+		addstr(name);
+		addch(cm);
+		addstr("\n");
+	}
 }
 
 int


Home | Main Index | Thread Index | Old Index