mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Allow UTF-8 characters of width 0 to be stored, it is useful to be able
to put padding cells in as width 0.
This commit is contained in:
parent
f5366ff828
commit
2a4d4bda2b
4
grid.c
4
grid.c
@ -76,7 +76,7 @@ grid_need_extended_cell(const struct grid_cell_entry *gce,
|
|||||||
return (1);
|
return (1);
|
||||||
if (gc->attr > 0xff)
|
if (gc->attr > 0xff)
|
||||||
return (1);
|
return (1);
|
||||||
if (gc->data.size > 1 || gc->data.width > 1)
|
if (gc->data.size != 1 || gc->data.width != 1)
|
||||||
return (1);
|
return (1);
|
||||||
if ((gc->fg & COLOUR_FLAG_RGB) || (gc->bg & COLOUR_FLAG_RGB))
|
if ((gc->fg & COLOUR_FLAG_RGB) || (gc->bg & COLOUR_FLAG_RGB))
|
||||||
return (1);
|
return (1);
|
||||||
@ -570,7 +570,7 @@ grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc,
|
|||||||
gce = &gl->celldata[px + i];
|
gce = &gl->celldata[px + i];
|
||||||
if (grid_need_extended_cell(gce, gc)) {
|
if (grid_need_extended_cell(gce, gc)) {
|
||||||
gee = grid_extended_cell(gl, gce, gc);
|
gee = grid_extended_cell(gl, gce, gc);
|
||||||
gee->data = utf8_build_one(s[i], 1);
|
gee->data = utf8_build_one(s[i]);
|
||||||
} else
|
} else
|
||||||
grid_store_cell(gce, gc, s[i]);
|
grid_store_cell(gce, gc, s[i]);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ static const struct grid_cell *screen_write_combine(struct screen_write_ctx *,
|
|||||||
const struct utf8_data *, u_int *);
|
const struct utf8_data *, u_int *);
|
||||||
|
|
||||||
static const struct grid_cell screen_write_pad_cell = {
|
static const struct grid_cell screen_write_pad_cell = {
|
||||||
{ { ' ' }, 0, 1, 1 }, 0, GRID_FLAG_PADDING, 8, 8, 0
|
{ { 0 }, 0, 0, 0 }, 0, GRID_FLAG_PADDING, 8, 8, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
struct screen_write_collect_item {
|
struct screen_write_collect_item {
|
||||||
|
2
tmux.h
2
tmux.h
@ -2902,7 +2902,7 @@ u_int session_group_attached_count(struct session_group *);
|
|||||||
void session_renumber_windows(struct session *);
|
void session_renumber_windows(struct session *);
|
||||||
|
|
||||||
/* utf8.c */
|
/* utf8.c */
|
||||||
utf8_char utf8_build_one(char, u_int);
|
utf8_char utf8_build_one(u_char);
|
||||||
enum utf8_state utf8_from_data(const struct utf8_data *, utf8_char *);
|
enum utf8_state utf8_from_data(const struct utf8_data *, utf8_char *);
|
||||||
void utf8_to_data(utf8_char, struct utf8_data *);
|
void utf8_to_data(utf8_char, struct utf8_data *);
|
||||||
void utf8_set(struct utf8_data *, u_char);
|
void utf8_set(struct utf8_data *, u_char);
|
||||||
|
54
utf8.c
54
utf8.c
@ -56,19 +56,26 @@ union utf8_map {
|
|||||||
utf8_char uc;
|
utf8_char uc;
|
||||||
struct {
|
struct {
|
||||||
u_char flags;
|
u_char flags;
|
||||||
#define UTF8_FLAG_SIZE 0x1f
|
|
||||||
#define UTF8_FLAG_WIDTH2 0x20
|
|
||||||
|
|
||||||
u_char data[3];
|
u_char data[3];
|
||||||
};
|
};
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
|
#define UTF8_GET_SIZE(flags) ((flags) & 0x1f)
|
||||||
|
#define UTF8_GET_WIDTH(flags) (((flags) >> 5) - 1)
|
||||||
|
|
||||||
|
#define UTF8_SET_SIZE(size) (size)
|
||||||
|
#define UTF8_SET_WIDTH(width) ((width + 1) << 5)
|
||||||
|
|
||||||
|
static const union utf8_map utf8_space0 = {
|
||||||
|
.flags = UTF8_SET_WIDTH(0)|UTF8_SET_SIZE(0),
|
||||||
|
.data = ""
|
||||||
|
};
|
||||||
static const union utf8_map utf8_space1 = {
|
static const union utf8_map utf8_space1 = {
|
||||||
.flags = 1,
|
.flags = UTF8_SET_WIDTH(1)|UTF8_SET_SIZE(1),
|
||||||
.data = " "
|
.data = " "
|
||||||
};
|
};
|
||||||
static const union utf8_map utf8_space2 = {
|
static const union utf8_map utf8_space2 = {
|
||||||
.flags = UTF8_FLAG_WIDTH2|2,
|
.flags = UTF8_SET_WIDTH(2)|UTF8_SET_SIZE(2),
|
||||||
.data = " "
|
.data = " "
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -135,24 +142,12 @@ utf8_from_data(const struct utf8_data *ud, utf8_char *uc)
|
|||||||
union utf8_map m = { .uc = 0 };
|
union utf8_map m = { .uc = 0 };
|
||||||
u_int offset;
|
u_int offset;
|
||||||
|
|
||||||
if (ud->width == 0)
|
if (ud->width > 2)
|
||||||
goto fail;
|
|
||||||
if (ud->width != 1 && ud->width != 2)
|
|
||||||
fatalx("invalid UTF-8 width");
|
fatalx("invalid UTF-8 width");
|
||||||
if (ud->size == 0)
|
|
||||||
fatalx("invalid UTF-8 size");
|
|
||||||
|
|
||||||
if (ud->size > UTF8_FLAG_SIZE)
|
if (ud->size > UTF8_SIZE)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (ud->size == 1) {
|
m.flags = UTF8_SET_SIZE(ud->size)|UTF8_SET_WIDTH(ud->width);
|
||||||
*uc = utf8_build_one(ud->data[0], 1);
|
|
||||||
return (UTF8_DONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
m.flags = ud->size;
|
|
||||||
if (ud->width == 2)
|
|
||||||
m.flags |= UTF8_FLAG_WIDTH2;
|
|
||||||
|
|
||||||
if (ud->size <= 3)
|
if (ud->size <= 3)
|
||||||
memcpy(m.data, ud->data, ud->size);
|
memcpy(m.data, ud->data, ud->size);
|
||||||
else {
|
else {
|
||||||
@ -166,7 +161,9 @@ utf8_from_data(const struct utf8_data *ud, utf8_char *uc)
|
|||||||
return (UTF8_DONE);
|
return (UTF8_DONE);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (ud->width == 1)
|
if (ud->width == 0)
|
||||||
|
*uc = htonl(utf8_space0.uc);
|
||||||
|
else if (ud->width == 1)
|
||||||
*uc = htonl(utf8_space1.uc);
|
*uc = htonl(utf8_space1.uc);
|
||||||
else
|
else
|
||||||
*uc = htonl(utf8_space2.uc);
|
*uc = htonl(utf8_space2.uc);
|
||||||
@ -182,11 +179,8 @@ utf8_to_data(utf8_char uc, struct utf8_data *ud)
|
|||||||
u_int offset;
|
u_int offset;
|
||||||
|
|
||||||
memset(ud, 0, sizeof *ud);
|
memset(ud, 0, sizeof *ud);
|
||||||
ud->size = ud->have = (m.flags & UTF8_FLAG_SIZE);
|
ud->size = ud->have = UTF8_GET_SIZE(m.flags);
|
||||||
if (m.flags & UTF8_FLAG_WIDTH2)
|
ud->width = UTF8_GET_WIDTH(m.flags);
|
||||||
ud->width = 2;
|
|
||||||
else
|
|
||||||
ud->width = 1;
|
|
||||||
|
|
||||||
if (ud->size <= 3) {
|
if (ud->size <= 3) {
|
||||||
memcpy(ud->data, m.data, ud->size);
|
memcpy(ud->data, m.data, ud->size);
|
||||||
@ -204,12 +198,12 @@ utf8_to_data(utf8_char uc, struct utf8_data *ud)
|
|||||||
|
|
||||||
/* Get UTF-8 character from a single ASCII character. */
|
/* Get UTF-8 character from a single ASCII character. */
|
||||||
u_int
|
u_int
|
||||||
utf8_build_one(char c, u_int width)
|
utf8_build_one(u_char ch)
|
||||||
{
|
{
|
||||||
union utf8_map m = { .flags = 1, .data[0] = c };
|
union utf8_map m;
|
||||||
|
|
||||||
if (width == 2)
|
m.flags = UTF8_SET_SIZE(1)|UTF8_SET_WIDTH(1);
|
||||||
m.flags |= UTF8_FLAG_WIDTH2;
|
m.data[0] = ch;
|
||||||
return (htonl(m.uc));
|
return (htonl(m.uc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user