diff --git a/.sconsign.dblite b/.sconsign.dblite index 2489454..f5f9f97 100644 Binary files a/.sconsign.dblite and b/.sconsign.dblite differ diff --git a/src/config.h b/src/config.h index b771f41..4c645ad 100644 --- a/src/config.h +++ b/src/config.h @@ -2,5 +2,6 @@ #define _CONFIG_H_ #define TABSIZE 4 // Tab size as used in render +#define MAX_LINE 1024 // maximum line length on screen #endif \ No newline at end of file diff --git a/src/fbuffer.c b/src/fbuffer.c index daa7910..dd62454 100644 --- a/src/fbuffer.c +++ b/src/fbuffer.c @@ -3,6 +3,7 @@ #include #include #include +#include void bufInit (FileBuffer *b) { @@ -172,11 +173,27 @@ void updateRender (Row *rw) { /* count the special characters * spaces, utf-8 continuation chars */ - static int tabs, i, off, cc, ut; - for (i = 0, tabs = 0, cc = 0, ut = 0; i < rw->size; i++) { + static int tabs, i, off/*, utf_width, utf_chars*/; + //static wchar_t wc_tmp; + //static char *mb_p; + + tabs = 0; + //utf_width = 0; + //utf_chars = 0; + + for (i = 0; i < rw->size; i++) { if (rw->chars[i] == '\t') tabs++; - else if (isCont(rw->chars[i])) cc++; - else if (isUtf(rw->chars[i])) ut++; + + /*else if (isStart(rw->chars[i])) { + utf_chars++; + wc_tmp = 0; + mb_p = &rw->chars[i]; + //int utf_len = mblen(mb_p, rw->size - i); + + mbtowc(&wc_tmp, mb_p, rw->size - i); + utf_width += wcwidth(wc_tmp); + //utf_len += utf_chars; + } */ } rw->render = NULL; free(rw->render); @@ -200,6 +217,6 @@ void updateRender (Row *rw) } } rw->render[off] = '\0'; - rw->r_size = off - cc; - rw->utf = cc + ut; -} + rw->r_size = off; + //rw->utf = utf_width - utf_chars; +} \ No newline at end of file diff --git a/src/fbuffer.h b/src/fbuffer.h index 8ad3053..77fe96c 100644 --- a/src/fbuffer.h +++ b/src/fbuffer.h @@ -1,6 +1,8 @@ #ifndef _FBUFFER_H_ #define _FBUFFER_H_ - +#ifndef _XOPEN_SOURCE + #define _XOPEN_SOURCE /* See feature_test_macros(7) */ +#endif /* Row structure, defines actual and * render chars, actual and render size * and difference between render and diff --git a/src/fbuffer.o b/src/fbuffer.o index f4d81d8..276aa59 100644 Binary files a/src/fbuffer.o and b/src/fbuffer.o differ diff --git a/src/ste.c b/src/ste.c index a1bc626..f5dfbfd 100644 --- a/src/ste.c +++ b/src/ste.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "fbuffer.h" #include "config.h" @@ -14,6 +15,7 @@ #define CTRL(k) ((k) & 0x1f) // Control mask modifier #define STAT_SIZE 128 #define CBUF_SIZE 2048 +#define MAX_LINE 1024 #define MODE_MASK 0x1 #define COMMAND_MASK 0x06 @@ -103,6 +105,10 @@ static void sbMove (CharBuffer *buf, int x); /* --------------------------------- main ------------------------------------ */ int main (int argc, char *argv[]) { + /* Init locales */ + setlocale(LC_ALL, ""); + setlocale(LC_CTYPE, ""); + /* Initialize the first row */ bufInit(&rows); @@ -210,9 +216,6 @@ int main (int argc, char *argv[]) void termInit (void) { - /* Init locales */ - setlocale(LC_ALL, ""); - /* Init the screen and refresh */ initscr(); refresh(); @@ -324,9 +327,17 @@ void drawLines (void) /* Draw the line matcing render memory */ if (&rows.rw[ln] == NULL) termDie("drawlines NULL"); if (rows.rw[ln].r_size > t.cur.off_x) { + start = t.cur.off_x; - while (isCont(rows.rw[ln].render[start])) start++; - addnstr(&rows.rw[ln].render[start], (t.dim.x + 1) + (rows.rw[ln].utf >> 2)); + while (isCont(rows.rw[ln].render[start])) start++; + + static wchar_t converted_line[MAX_LINE]; + static int x = 0; + for (x = 0; x < MAX_LINE; x++) converted_line[x] = 0; + mbstowcs(converted_line, &rows.rw[ln].render[start], MAX_LINE); + addnwstr(converted_line, t.dim.x + 1); + + //addnstr(&rows.rw[ln].render[start], (t.dim.x + 1) + rows.rw[ln].utf); } } lnMove(i + 1, 0); @@ -354,9 +365,9 @@ void drawBar (char *s) for (i = len; i <= t.dim.x + t.pad; i++) mvaddch(t.dim.y, i, ' '); - static char m[40]; - sprintf(m, "x: %d y: %d Zoom: %c", t.cur.x, t.cur.y, whatsThat()); - mvaddstr(t.dim.y, t.dim.x + t.pad - strlen(m), m); + static char right_message[40]; + sprintf(right_message, "x: %d y: %d Zoom: %c", t.cur.x, t.cur.y, whatsThat()); + mvaddstr(t.dim.y, t.dim.x + t.pad - strlen(right_message), right_message); /* Return to normal contrast mode */ attroff(COLOR_PAIR(2)); diff --git a/src/ste.o b/src/ste.o index a37910b..4ed4075 100644 Binary files a/src/ste.o and b/src/ste.o differ