working render of unicode characters
everything is to document and I left a lot of garbage comments :p
This commit is contained in:
parent
74fa0c7582
commit
fac8e0d96a
BIN
.sconsign.dblite
BIN
.sconsign.dblite
Binary file not shown.
@ -2,5 +2,6 @@
|
|||||||
#define _CONFIG_H_
|
#define _CONFIG_H_
|
||||||
|
|
||||||
#define TABSIZE 4 // Tab size as used in render
|
#define TABSIZE 4 // Tab size as used in render
|
||||||
|
#define MAX_LINE 1024 // maximum line length on screen
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -3,6 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
void bufInit (FileBuffer *b)
|
void bufInit (FileBuffer *b)
|
||||||
{
|
{
|
||||||
@ -172,11 +173,27 @@ void updateRender (Row *rw)
|
|||||||
{
|
{
|
||||||
/* count the special characters
|
/* count the special characters
|
||||||
* spaces, utf-8 continuation chars */
|
* spaces, utf-8 continuation chars */
|
||||||
static int tabs, i, off, cc, ut;
|
static int tabs, i, off/*, utf_width, utf_chars*/;
|
||||||
for (i = 0, tabs = 0, cc = 0, ut = 0; i < rw->size; i++) {
|
//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++;
|
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;
|
rw->render = NULL;
|
||||||
free(rw->render);
|
free(rw->render);
|
||||||
@ -200,6 +217,6 @@ void updateRender (Row *rw)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rw->render[off] = '\0';
|
rw->render[off] = '\0';
|
||||||
rw->r_size = off - cc;
|
rw->r_size = off;
|
||||||
rw->utf = cc + ut;
|
//rw->utf = utf_width - utf_chars;
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef _FBUFFER_H_
|
#ifndef _FBUFFER_H_
|
||||||
#define _FBUFFER_H_
|
#define _FBUFFER_H_
|
||||||
|
#ifndef _XOPEN_SOURCE
|
||||||
|
#define _XOPEN_SOURCE /* See feature_test_macros(7) */
|
||||||
|
#endif
|
||||||
/* Row structure, defines actual and
|
/* Row structure, defines actual and
|
||||||
* render chars, actual and render size
|
* render chars, actual and render size
|
||||||
* and difference between render and
|
* and difference between render and
|
||||||
|
BIN
src/fbuffer.o
BIN
src/fbuffer.o
Binary file not shown.
27
src/ste.c
27
src/ste.c
@ -6,6 +6,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
#include "fbuffer.h"
|
#include "fbuffer.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -14,6 +15,7 @@
|
|||||||
#define CTRL(k) ((k) & 0x1f) // Control mask modifier
|
#define CTRL(k) ((k) & 0x1f) // Control mask modifier
|
||||||
#define STAT_SIZE 128
|
#define STAT_SIZE 128
|
||||||
#define CBUF_SIZE 2048
|
#define CBUF_SIZE 2048
|
||||||
|
#define MAX_LINE 1024
|
||||||
|
|
||||||
#define MODE_MASK 0x1
|
#define MODE_MASK 0x1
|
||||||
#define COMMAND_MASK 0x06
|
#define COMMAND_MASK 0x06
|
||||||
@ -103,6 +105,10 @@ static void sbMove (CharBuffer *buf, int x);
|
|||||||
/* --------------------------------- main ------------------------------------ */
|
/* --------------------------------- main ------------------------------------ */
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
/* Init locales */
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
setlocale(LC_CTYPE, "");
|
||||||
|
|
||||||
/* Initialize the first row */
|
/* Initialize the first row */
|
||||||
bufInit(&rows);
|
bufInit(&rows);
|
||||||
|
|
||||||
@ -210,9 +216,6 @@ int main (int argc, char *argv[])
|
|||||||
|
|
||||||
void termInit (void)
|
void termInit (void)
|
||||||
{
|
{
|
||||||
/* Init locales */
|
|
||||||
setlocale(LC_ALL, "");
|
|
||||||
|
|
||||||
/* Init the screen and refresh */
|
/* Init the screen and refresh */
|
||||||
initscr();
|
initscr();
|
||||||
refresh();
|
refresh();
|
||||||
@ -324,9 +327,17 @@ void drawLines (void)
|
|||||||
/* Draw the line matcing render memory */
|
/* Draw the line matcing render memory */
|
||||||
if (&rows.rw[ln] == NULL) termDie("drawlines NULL");
|
if (&rows.rw[ln] == NULL) termDie("drawlines NULL");
|
||||||
if (rows.rw[ln].r_size > t.cur.off_x) {
|
if (rows.rw[ln].r_size > t.cur.off_x) {
|
||||||
|
|
||||||
start = t.cur.off_x;
|
start = t.cur.off_x;
|
||||||
while (isCont(rows.rw[ln].render[start])) start++;
|
while (isCont(rows.rw[ln].render[start])) start++;
|
||||||
addnstr(&rows.rw[ln].render[start], (t.dim.x + 1) + (rows.rw[ln].utf >> 2));
|
|
||||||
|
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);
|
lnMove(i + 1, 0);
|
||||||
@ -354,9 +365,9 @@ void drawBar (char *s)
|
|||||||
for (i = len; i <= t.dim.x + t.pad; i++)
|
for (i = len; i <= t.dim.x + t.pad; i++)
|
||||||
mvaddch(t.dim.y, i, ' ');
|
mvaddch(t.dim.y, i, ' ');
|
||||||
|
|
||||||
static char m[40];
|
static char right_message[40];
|
||||||
sprintf(m, "x: %d y: %d Zoom: %c", t.cur.x, t.cur.y, whatsThat());
|
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(m), m);
|
mvaddstr(t.dim.y, t.dim.x + t.pad - strlen(right_message), right_message);
|
||||||
|
|
||||||
/* Return to normal contrast mode */
|
/* Return to normal contrast mode */
|
||||||
attroff(COLOR_PAIR(2));
|
attroff(COLOR_PAIR(2));
|
||||||
|
Loading…
Reference in New Issue
Block a user