用诅咒清除包裹线
当我在 bash 中运行以下代码时,在不太宽的终端(当前我的终端是 97 列宽)中,我没有看到预期的行为,
# foo.sh
tput sc # save cursor
for i in $(seq 10); do
printf "%s" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
tput rc # restore cursor
tput ed # clear to end of screen
done
echo "foo"
但是,如果我将字符串更改为比终端的宽度短,这样它就不会换行,然后它就可以正常工作,并且curses会清除该行,以便只有最后的“foo”显示在屏幕上。
# bar.sh
tput sc # save cursor
for i in $(seq 10); do
printf "%s" "aaaaaaaaaaaaa"
tput rc # restore cursor
tput ed # clear to end of screen
done
echo "foo"
所以我的问题是:在存在换行的情况下如何清除屏幕从光标到底部,以及......这里发生了什么?
When I run the following code in bash, in a terminal that's not too wide (currently my terminal is 97 columns wide), I don't see the expected behavior
# foo.sh
tput sc # save cursor
for i in $(seq 10); do
printf "%s" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
tput rc # restore cursor
tput ed # clear to end of screen
done
echo "foo"
The lines don't actually get cleared:
However, if I change the string to be shorter than the width of the terminal, so that it doesn't wrap, then it works fine and curses clears the line so that only the final "foo" shows up on the screen.
# bar.sh
tput sc # save cursor
for i in $(seq 10); do
printf "%s" "aaaaaaaaaaaaa"
tput rc # restore cursor
tput ed # clear to end of screen
done
echo "foo"
So my question is: How do I clear the screen from the cursor down to the bottom in the presence of line wrapping, and... what's going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论