mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-20 07:24:41 +02:00
Fix utf8 decode
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
// Macros {{{
|
// Macros {{{
|
||||||
|
|
||||||
#define SET_STATE(x) \
|
#define SET_STATE(x) \
|
||||||
self->vte_state = VTE_##x; self->utf8.state = UTF8_ACCEPT; self->utf8.prev = UTF8_ACCEPT;
|
self->vte_state = VTE_##x; zero_at_ptr(&self->utf8);
|
||||||
|
|
||||||
#define DIGIT \
|
#define DIGIT \
|
||||||
'0': \
|
'0': \
|
||||||
@@ -101,8 +101,7 @@ _report_params(PyObject *dump_callback, id_type window_id, const char *name, int
|
|||||||
#define REPORT_VA_COMMAND(...) Py_XDECREF(PyObject_CallFunction(self->dump_callback, __VA_ARGS__)); PyErr_Clear();
|
#define REPORT_VA_COMMAND(...) Py_XDECREF(PyObject_CallFunction(self->dump_callback, __VA_ARGS__)); PyErr_Clear();
|
||||||
|
|
||||||
#define REPORT_DRAW(ch) \
|
#define REPORT_DRAW(ch) \
|
||||||
printf("ch: %x\n", ch); \
|
Py_XDECREF(PyObject_CallFunction(self->dump_callback, "KsC", self->window_id, "draw", ch)); PyErr_Clear();
|
||||||
Py_XDECREF(PyObject_CallFunction(self->dump_callback, "KsC", self->window_id, "draw", (int)ch)); PyErr_Clear();
|
|
||||||
|
|
||||||
#define REPORT_PARAMS(name, params, num, is_group, region) _report_params(self->dump_callback, self->window_id, name, params, num_params, is_group, region)
|
#define REPORT_PARAMS(name, params, num, is_group, region) _report_params(self->dump_callback, self->window_id, name, params, num_params, is_group, region)
|
||||||
|
|
||||||
@@ -192,7 +191,7 @@ typedef struct ParsedCSI {
|
|||||||
typedef struct PS {
|
typedef struct PS {
|
||||||
id_type window_id;
|
id_type window_id;
|
||||||
|
|
||||||
struct { UTF8State prev, state; } utf8;
|
struct { UTF8State prev, state; uint32_t codep; } utf8;
|
||||||
VTEState vte_state;
|
VTEState vte_state;
|
||||||
ParsedCSI csi;
|
ParsedCSI csi;
|
||||||
|
|
||||||
@@ -208,14 +207,11 @@ typedef struct PS {
|
|||||||
Screen *screen;
|
Screen *screen;
|
||||||
monotonic_t now, new_input_at;
|
monotonic_t now, new_input_at;
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
uint8_t buf[BUF_SZ + 8];
|
|
||||||
|
|
||||||
struct {
|
// The buffer
|
||||||
size_t consumed, pos, sz;
|
struct { size_t consumed, pos, sz; } read;
|
||||||
} read;
|
struct { size_t offset, sz; } write;
|
||||||
struct {
|
uint8_t buf[BUF_SZ];
|
||||||
size_t offset, sz;
|
|
||||||
} write;
|
|
||||||
} PS;
|
} PS;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -229,20 +225,21 @@ reset_csi(ParsedCSI *csi) {
|
|||||||
// Normal mode {{{
|
// Normal mode {{{
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_byte(PS *self, uint8_t b) {
|
draw_byte(PS *self, const uint8_t b) {
|
||||||
uint32_t ch;
|
switch (decode_utf8(&self->utf8.state, &self->utf8.codep, b)) {
|
||||||
switch (decode_utf8(&self->utf8.state, &ch, b)) {
|
|
||||||
case UTF8_ACCEPT:
|
case UTF8_ACCEPT:
|
||||||
REPORT_DRAW(ch);
|
REPORT_DRAW(self->utf8.codep);
|
||||||
screen_draw(self->screen, ch, true);
|
screen_draw(self->screen, self->utf8.codep, true);
|
||||||
break;
|
break;
|
||||||
case UTF8_REJECT: {
|
case UTF8_REJECT: {
|
||||||
bool prev_was_accept = self->utf8.prev == UTF8_ACCEPT;
|
bool prev_was_accept = self->utf8.prev == UTF8_ACCEPT;
|
||||||
self->utf8.state = UTF8_ACCEPT; self->utf8.prev = UTF8_ACCEPT;
|
zero_at_ptr(&self->utf8);
|
||||||
ch = 0xfffd; // unicode replacement char
|
REPORT_DRAW(0xfffd);
|
||||||
REPORT_DRAW(ch);
|
screen_draw(self->screen, 0xfffd, true);
|
||||||
screen_draw(self->screen, ch, true);
|
if (!prev_was_accept) {
|
||||||
if (!prev_was_accept) draw_byte(self, b);
|
draw_byte(self, b);
|
||||||
|
return; // so that prev is correct
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
self->utf8.prev = self->utf8.state;
|
self->utf8.prev = self->utf8.state;
|
||||||
@@ -1640,9 +1637,7 @@ free_vt_parser(Parser* self) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
reset(PS *self) {
|
reset(PS *self) {
|
||||||
self->vte_state = VTE_NORMAL;
|
SET_STATE(NORMAL);
|
||||||
self->utf8.state = UTF8_ACCEPT;
|
|
||||||
self->utf8.prev = UTF8_ACCEPT;
|
|
||||||
reset_csi(&self->csi);
|
reset_csi(&self->csi);
|
||||||
|
|
||||||
zero_at_ptr(&self->pending_mode);
|
zero_at_ptr(&self->pending_mode);
|
||||||
|
|||||||
Reference in New Issue
Block a user