如何从 C 终端中删除 ^\ SIGQUIT 字符
所以我试图重现 bash,当我在 bash 中按 control + \ 时,它什么也不做。所以我试图重现这种行为,这是我的代码。
# include <signal.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <stdlib.h>
# include <unistd.h>
void sig_handler(int sig)
{
write(2, "\b \b", 2);
}
int main(void)
{
signal(SIGQUIT, sig_handler);
while (1)
{
char *line = readline("test> ");
if (!line)
break;
free(line);
}
return (0);
}
当我按 control + \ 时,它第一次起作用,但当我再次按它时,它开始显示 ^ 字符,那么我该怎么做呢?顺便说一句,我在 macOS 上。
要编译此代码,请运行 gcc main.c -lreadline
So I'm trying to reproduce bash, and when I press control + \ in bash it does nothing. So I'm trying to reproduce that behavior this is my code.
# include <signal.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <stdlib.h>
# include <unistd.h>
void sig_handler(int sig)
{
write(2, "\b \b", 2);
}
int main(void)
{
signal(SIGQUIT, sig_handler);
while (1)
{
char *line = readline("test> ");
if (!line)
break;
free(line);
}
return (0);
}
When I press control + \ , it works the first time but then when I press it again it starts showing the ^ character, so how am I supposed to do this? I'm on macOS btw.
to compile this code run gcc main.c -lreadline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论