prompt: insert a burst of bytes in one go instead of characterwise
There is no need to count characters, so just insert the whole batch of bytes at once.
Этот коммит содержится в:
родитель
75f4309c1f
Коммит
68ca1732b8
19
src/prompt.c
19
src/prompt.c
@ -176,24 +176,17 @@ int do_statusbar_input(bool *finished)
|
|||||||
/* Insert the given short burst of bytes into the anwer. */
|
/* Insert the given short burst of bytes into the anwer. */
|
||||||
void inject_into_answer(char *burst, size_t count)
|
void inject_into_answer(char *burst, size_t count)
|
||||||
{
|
{
|
||||||
size_t charlen, index = 0;
|
/* First encode any embedded NUL byte as 0x0A. */
|
||||||
|
for (size_t index = 0; index < count; index++)
|
||||||
while (index < count) {
|
|
||||||
/* Encode any NUL byte as 0x0A. */
|
|
||||||
if (burst[index] == '\0')
|
if (burst[index] == '\0')
|
||||||
burst[index] = '\n';
|
burst[index] = '\n';
|
||||||
|
|
||||||
charlen = char_length(burst + index);
|
answer = charealloc(answer, strlen(answer) + count + 1);
|
||||||
|
memmove(answer + typing_x + count, answer + typing_x,
|
||||||
/* Insert the typed character into the existing answer string. */
|
|
||||||
answer = charealloc(answer, strlen(answer) + charlen + 1);
|
|
||||||
memmove(answer + typing_x + charlen, answer + typing_x,
|
|
||||||
strlen(answer) - typing_x + 1);
|
strlen(answer) - typing_x + 1);
|
||||||
strncpy(answer + typing_x, burst + index, charlen);
|
strncpy(answer + typing_x, burst , count);
|
||||||
|
|
||||||
typing_x += charlen;
|
typing_x += count;
|
||||||
index += charlen;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move to the beginning of the answer. */
|
/* Move to the beginning of the answer. */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user