mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-18 06:46:23 -04:00
Initial handling of multi byte characters
Use mblen() to calculate the byte count for each character.
This commit is contained in:
parent
e062ff7b97
commit
9f9949aeec
2 changed files with 24 additions and 12 deletions
34
main.c
34
main.c
|
|
@ -5,7 +5,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
@ -31,7 +31,7 @@ struct wayland {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cell {
|
struct cell {
|
||||||
char c;
|
char c[5];
|
||||||
bool dirty;
|
bool dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -122,8 +122,8 @@ grid_render(struct context *c)
|
||||||
int num_glyphs = 0;
|
int num_glyphs = 0;
|
||||||
|
|
||||||
cairo_status_t status = cairo_scaled_font_text_to_glyphs(
|
cairo_status_t status = cairo_scaled_font_text_to_glyphs(
|
||||||
c->font, x_ofs, y_ofs, &cell->c, 1, &glyphs, &num_glyphs,
|
c->font, x_ofs, y_ofs, cell->c, strlen(cell->c),
|
||||||
NULL, NULL, NULL);
|
&glyphs, &num_glyphs, NULL, NULL, NULL);
|
||||||
|
|
||||||
//assert(status == CAIRO_STATUS_SUCCESS);
|
//assert(status == CAIRO_STATUS_SUCCESS);
|
||||||
if (status != CAIRO_STATUS_SUCCESS) {
|
if (status != CAIRO_STATUS_SUCCESS) {
|
||||||
|
|
@ -349,6 +349,8 @@ main(int argc, const char *const *argv)
|
||||||
{
|
{
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
|
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
struct context c = {
|
struct context c = {
|
||||||
.quit = false,
|
.quit = false,
|
||||||
.ptmx = posix_openpt(O_RDWR | O_NOCTTY),
|
.ptmx = posix_openpt(O_RDWR | O_NOCTTY),
|
||||||
|
|
@ -471,38 +473,48 @@ main(int argc, const char *const *argv)
|
||||||
//LOG_DBG("%.*s", (int)count, data);
|
//LOG_DBG("%.*s", (int)count, data);
|
||||||
|
|
||||||
int cursor = c.grid.cursor;
|
int cursor = c.grid.cursor;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count;) {
|
||||||
switch (data[i]) {
|
switch (data[i]) {
|
||||||
case '\r':
|
case '\r':
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
cursor = cursor / c.grid.cols * c.grid.cols;
|
cursor = cursor / c.grid.cols * c.grid.cols;
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
c.grid.dirty = true;
|
i++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
cursor += c.grid.cols;
|
cursor += c.grid.cols;
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
c.grid.dirty = true;
|
i++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\t':
|
case '\t':
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
cursor = (cursor + 8) / 8 * 8;
|
cursor = (cursor + 8) / 8 * 8;
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
c.grid.dirty = true;
|
i++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
|
/* TODO: mbrlen() + error handling */
|
||||||
|
int clen = mblen(&data[i], count - i);
|
||||||
|
assert(clen >= 0);
|
||||||
|
assert(i + clen <= count);
|
||||||
|
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
c.grid.cells[cursor++].c = data[i];
|
memcpy(c.grid.cells[cursor].c, &data[i], clen);
|
||||||
|
c.grid.cells[cursor].c[clen] = '\0';
|
||||||
|
|
||||||
|
cursor++;
|
||||||
c.grid.cells[cursor].dirty = true;
|
c.grid.cells[cursor].dirty = true;
|
||||||
c.grid.dirty = true;
|
i += clen;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.grid.dirty = true;
|
||||||
c.grid.cursor = cursor;
|
c.grid.cursor = cursor;
|
||||||
|
|
||||||
if (!c.frame_is_scheduled)
|
if (!c.frame_is_scheduled)
|
||||||
|
|
|
||||||
2
slave.c
2
slave.c
|
|
@ -61,7 +61,7 @@ slave_spawn(int ptmx)
|
||||||
write(STDOUT_FILENO, "yeehaa", 6);
|
write(STDOUT_FILENO, "yeehaa", 6);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
write(STDOUT_FILENO, "\rXXX", 4);
|
write(STDOUT_FILENO, "\råäö", strlen("\råäö"));
|
||||||
|
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue