Обработчик libreadline SIGINT не очищает буфер

Имея небольшую программу ниже, я ожидаю следующее:

>> forget_me!^C
>> next
next
>>

Но это действительно так:

>> forget_me!^C
>> next
forget_me!next
>>

Не должен ли обработчик SIGINT по умолчанию очистить буфер, как описано здесь http://sunsite.ualberta.ca/Documentation/Gnu/readline-4.1/html_node/readline_40.html#SEC40 (Rl_free_line_state)?

Как мне достичь желаемого результата?

#include <cstdlib>
#include <csignal>
#include <iostream>
#include <readline/readline.h>
#include <readline/history.h>

const std::string prompt{">> "};

void new_line_handler(int i) { std::cout << "\n" << prompt; }

int main() {
struct sigaction action = {};
action.sa_handler = new_line_handler;
sigaction(SIGINT, &action, nullptr);

char *input;
while (true) {
input = readline(prompt.c_str());
if (!input)
break;
add_history(input);
std::cout << input << "\n";
free(input);
}
return 0;
}

1

Решение

Задача ещё не решена.

Другие решения


По вопросам рекламы [email protected]