c - 是否可以从输出行的中间删除一个字符而不删除它后面的字符?
问题描述
我做了一个小代码示例来向您展示我想要做什么:
#include <unistd.h>
#include <ncurses.h>
#include <stdlib.h>
#include <term.h>
int ft_putchar(int ch)
{
char c = (char)ch;
return (write(1, &c, 1));
}
int main(void)
{
tgetent(getenv("SHELL"), NULL);
char * le = tgetstr("le", NULL); // get the termcap for cursor left
write(1, "Hello world!", 12);
tputs(le, 1, &ft_putchar); // move the cursor to the left
write(1, "\b", 1); // erase character
return (0);
}
所以:如你所见,我正在写“Hello World!” 然后我想要做的是在这个例子中擦除'd'而不删除'!',问题是当我将光标向左移动然后打印'\ b'时,它会删除当前字符但也所有后面的字符,所以最终输出是Hello worl
而不是Hello worl!
,所以我的问题是:我可以避免这种情况发生还是每次擦除中间的字符后都需要重写结尾?(PS:我知道该tgetent
功能不受保护,但仅用于示例)
解决方案
推荐阅读
- javascript - 为什么在 setInterval 内更新的打字稿类的字段在该类的其他方法中未定义?
- python - Python:如何让这个函数同时运行多次
- php - 如何解析这个 XML 数据..?
- typescript - TS2322:“T”可以用与“SuperClass”无关的任意类型实例化
- ruby-on-rails - Rails 返回 HTML,即使设置了 `application/json` 和 `.json` 添加到资源
- reactjs - cypress 文件夹外的 mocha、chai 和 cy 的打字稿自动完成
- node.js - 快速响应 URL
- python - 硒和美汤一起使用
- python - 为什么 fast_than_requests 返回 null 而不设置错误?
- javascript - 正则表达式试图匹配没有加号