【发布时间】:2014-04-02 22:24:18
【问题描述】:
在 Lua 中,我尝试使用 shell 命令 'tput cup foo bar' 移动光标,并使用 'io.write('foo')' 在该位置写入字符串。
os.execute('tput clear') --clear terminal
os.execute('tput cup 2 9') --move cursor to line 2, col 9
io.write('A') --write 'A' at the cursor position
os.execute('tput cup 8 2') --move cursor to line 8, col 2
io.write('B') --write 'B' at the cursor position
但是,由于某种原因,它会在第二个光标位置(第 2 列,第 8 行)打印两个字符。
但是,当我使用 print() 而不是 io.write() 时,它会在正确的位置打印两个字符。出于明显的原因,我不想使用 print(),那么如何使用 io.write() 将两个字符串写入正确的位置?
【问题讨论】:
-
写完后可能需要致电
io.flush()。 -
我试过了,所以只有第一个字符串出现('A')。
标签: linux bash terminal lua text-cursor