degesch: have just one input buffer
This commit is contained in:
parent
d8299a1231
commit
d14bc2df53
25
degesch.c
25
degesch.c
|
@ -1367,12 +1367,8 @@ struct app_context
|
||||||
size_t nick_palette_len; ///< Number of entries in nick_palette
|
size_t nick_palette_len; ///< Number of entries in nick_palette
|
||||||
|
|
||||||
bool awaiting_mirc_escape; ///< Awaiting a mIRC attribute escape
|
bool awaiting_mirc_escape; ///< Awaiting a mIRC attribute escape
|
||||||
// TODO: try to get rid of this in favor of "paste_buffer" -> "input_buffer"
|
|
||||||
char char_buf[MB_LEN_MAX + 1]; ///< Buffered multibyte char
|
|
||||||
size_t char_buf_len; ///< How much of an MB char is buffered
|
|
||||||
|
|
||||||
bool in_bracketed_paste; ///< User is pasting some content
|
bool in_bracketed_paste; ///< User is pasting some content
|
||||||
struct str paste_buffer; ///< Buffered pasted content
|
struct str input_buffer; ///< Buffered pasted content
|
||||||
|
|
||||||
bool running_backlog_helper; ///< Running a backlog helper
|
bool running_backlog_helper; ///< Running a backlog helper
|
||||||
}
|
}
|
||||||
|
@ -1437,7 +1433,7 @@ app_context_init (struct app_context *self)
|
||||||
free (encoding);
|
free (encoding);
|
||||||
|
|
||||||
input_init (&self->input);
|
input_init (&self->input);
|
||||||
str_init (&self->paste_buffer);
|
str_init (&self->input_buffer);
|
||||||
|
|
||||||
self->nick_palette =
|
self->nick_palette =
|
||||||
filter_color_cube_for_acceptable_nick_colors (&self->nick_palette_len);
|
filter_color_cube_for_acceptable_nick_colors (&self->nick_palette_len);
|
||||||
|
@ -1471,7 +1467,7 @@ app_context_free (struct app_context *self)
|
||||||
iconv_close (self->term_to_utf8);
|
iconv_close (self->term_to_utf8);
|
||||||
|
|
||||||
input_free (&self->input);
|
input_free (&self->input);
|
||||||
str_free (&self->paste_buffer);
|
str_free (&self->input_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void refresh_prompt (struct app_context *ctx);
|
static void refresh_prompt (struct app_context *ctx);
|
||||||
|
@ -9060,7 +9056,6 @@ static void
|
||||||
await_mirc_escape (struct app_context *ctx)
|
await_mirc_escape (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
ctx->awaiting_mirc_escape = true;
|
ctx->awaiting_mirc_escape = true;
|
||||||
ctx->char_buf_len = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -9887,13 +9882,16 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
|
||||||
{
|
{
|
||||||
// There's no other way with libedit, as both el_getc() in a function
|
// There's no other way with libedit, as both el_getc() in a function
|
||||||
// handler and CC_ARGHACK would block execution
|
// handler and CC_ARGHACK would block execution
|
||||||
if (read (fd->fd, ctx->char_buf + ctx->char_buf_len, 1) != 1)
|
struct str *buf = &ctx->input_buffer;
|
||||||
|
str_ensure_space (buf, 1);
|
||||||
|
if (read (fd->fd, buf->str + buf->len, 1) != 1)
|
||||||
goto error;
|
goto error;
|
||||||
|
buf->str[++buf->len] = '\0';
|
||||||
|
|
||||||
mbstate_t state;
|
mbstate_t state;
|
||||||
memset (&state, 0, sizeof state);
|
memset (&state, 0, sizeof state);
|
||||||
|
|
||||||
size_t len = mbrlen (ctx->char_buf, ++ctx->char_buf_len, &state);
|
size_t len = mbrlen (buf->str, buf->len, &state);
|
||||||
|
|
||||||
// Illegal sequence
|
// Illegal sequence
|
||||||
if (len == (size_t) -1)
|
if (len == (size_t) -1)
|
||||||
|
@ -9903,9 +9901,9 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
|
||||||
if (len == (size_t) -2)
|
if (len == (size_t) -2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ctx->char_buf_len != 1)
|
if (buf->len != 1)
|
||||||
goto error;
|
goto error;
|
||||||
switch (ctx->char_buf[0])
|
switch (buf->str[0])
|
||||||
{
|
{
|
||||||
case 'b': input_insert (&ctx->input, "\x02"); break;
|
case 'b': input_insert (&ctx->input, "\x02"); break;
|
||||||
case 'c': input_insert (&ctx->input, "\x03"); break;
|
case 'c': input_insert (&ctx->input, "\x03"); break;
|
||||||
|
@ -9924,6 +9922,7 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
|
||||||
error:
|
error:
|
||||||
input_ding (&ctx->input);
|
input_ding (&ctx->input);
|
||||||
done:
|
done:
|
||||||
|
str_reset (buf);
|
||||||
ctx->awaiting_mirc_escape = false;
|
ctx->awaiting_mirc_escape = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9932,7 +9931,7 @@ done:
|
||||||
static void
|
static void
|
||||||
process_bracketed_paste (const struct pollfd *fd, struct app_context *ctx)
|
process_bracketed_paste (const struct pollfd *fd, struct app_context *ctx)
|
||||||
{
|
{
|
||||||
struct str *buf = &ctx->paste_buffer;
|
struct str *buf = &ctx->input_buffer;
|
||||||
str_ensure_space (buf, 1);
|
str_ensure_space (buf, 1);
|
||||||
if (read (fd->fd, buf->str + buf->len, 1) != 1)
|
if (read (fd->fd, buf->str + buf->len, 1) != 1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Reference in New Issue