[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[giFTcurs-commits] giFTcurs/src ui_draw.c
From: |
Göran Weinholt |
Subject: |
[giFTcurs-commits] giFTcurs/src ui_draw.c |
Date: |
Mon, 13 Oct 2003 12:22:11 -0400 |
CVSROOT: /cvsroot/giftcurs
Module name: giFTcurs
Branch:
Changes by: Göran Weinholt <address@hidden> 03/10/13 12:22:11
Modified files:
src : ui_draw.c
Log message:
Some cleanups for better utf-8 support.
Patches:
Index: giFTcurs/src/ui_draw.c
diff -u giFTcurs/src/ui_draw.c:1.107 giFTcurs/src/ui_draw.c:1.108
--- giFTcurs/src/ui_draw.c:1.107 Mon Sep 15 17:28:19 2003
+++ giFTcurs/src/ui_draw.c Mon Oct 13 12:22:10 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: ui_draw.c,v 1.107 2003/09/15 21:28:19 saturn Exp $
+ * $Id: ui_draw.c,v 1.108 2003/10/13 16:22:10 weinholt Exp $
*/
#include "giftcurs.h"
@@ -130,6 +130,13 @@
move(y, x);
attrset(selection_color(selected, COLOR_STANDARD));
+ if (utf8) {
+ char *end;
+
+ if (!g_utf8_validate(str, -1, &end))
+ *end = '\0';
+ }
+
for (u = str; *u && printed < w; u++) {
if (*u == '\v') {
u++;
@@ -150,12 +157,19 @@
if ((unsigned char) *u < 32 || ((unsigned char) *u >= 0x7f &&
(unsigned char) *u < 0xa0))
addch(' ');
else {
- int bytes = 1;
-
- /* Print UTF8 continuation bytes as part of the same
character. */
- while (UTF8_CBYTE(*(u + bytes)))
- bytes++, u++;
- addnstr(u - bytes + 1, bytes);
+ if (utf8) {
+ /* We do that which must be done for utf8. The
string must
+ be valid utf8. */
+ gunichar c = g_utf8_get_char(u);
+ gchar *nextc = g_utf8_next_char(u);
+
+ if (g_unichar_iswide(c))
+ printed++; /* two chars wide */
+ addnstr(u, nextc - u);
+ u = nextc - 1;
+ } else {
+ addnstr(u, 1);
+ }
}
printed++;
}
@@ -238,9 +252,9 @@
#endif
)
{
- int len = vstrlen(str);
+ int len = vstrlen(str) + 4;
- x -= (len + 4) / 2;
+ x -= len / 2;
move(y, x);
attrset(attr);
@@ -254,26 +268,37 @@
#endif
}
-/* FIXME: this function uses max_x and may output less chars than fit. */
void show_status(const char *status)
{
/* This leaks on exit. */
static char *current_msg = NULL;
- int y, x;
+
+ /* The number of bytes we can use to display max_x chars. */
+ int width = max_x - 1;
+ int oy, ox, y = max_y - 1 - show_buttonbar;
if (status) {
g_free(current_msg);
current_msg = g_strdup(status);
+
} else if (!current_msg) {
return;
}
- getyx(stdscr, y, x);
+ if (utf8) {
+ char *p = current_msg;
+ int len = 0;
+
+ for (; *p && len < max_x - 1; p = g_utf8_next_char(p))
+ len += g_unichar_iswide(g_utf8_get_char(p)) ? 2 : 1;
+ width = p - current_msg;
+ }
+
+ getyx(stdscr, oy, ox);
attrset(COLOR_PAIR(COLOR_STAT_DATA));
- move(max_y - 1 - show_buttonbar, 0);
- addnstr(current_msg, max_x - 1);
- hline(' ', max_x);
- move(y, x);
+ mvhline(y, 0, ' ', max_x);
+ mvaddnstr(y, 0, current_msg, width);
+ move(oy, ox);
}
/* Clear the screen - but avoid the statusline */
@@ -282,7 +307,7 @@
erase();
}
-/* Visual strlen() */
+/* Visual strlen(). Doesn't handle two chars wide chars yet. */
glong vstrlen(const char *str)
{
if (!utf8)
- [giFTcurs-commits] giFTcurs/src ui_draw.c,
Göran Weinholt <=