📜  告诉函数如何在终端的光标位置打印行 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:53.027000             🧑  作者: Mango

代码示例1
print_in_top_right () {
  local columns=$(tput cols)           # get the terminal width
  local text=${1:0:$columns}           # truncate the text to fit on a line if needed
  tput sc                              # Save the Cursor position
  tput cup 0 $((columns - ${#text}))   # move the CUrsor Position to the top line, with just enough space for $text on the right
  printf %s "$text"
  tput rc                              # Restore the Cursor position saved by sc
}