GNU Readline: how to clear the input line?

前端 未结 6 1394
你的背包
你的背包 2021-01-05 14:35

I use GNU Readline in the \"select\" fashion, by registering a callback function like so:

rl_callback_handler_install(\"\", on_readline_input);
6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 15:12

    One thing you can do is to use \r to jump to the beginning of the line for the server output. Then you can use field width specifiers to right pad the output to the rest of the line. This will, in effect, overwrite whatever the user had already entered.

    fprintf (stdout, "\r%-20s\n", "SERVER OUTPUT");
    

    You may want to fflush(stdout) to ensure that the buffers are in a consistent state before you do that.

提交回复
热议问题