索引 (IND)

將游標下移一個儲存格,必要時捲動。

  1. 0x1B
    ESC
  2. 0x44
    D

此序列總是取消待處理的換行狀態。

若游標恰好位於下邊界,且處於或位於 左邊界 與 右邊界 之內,則 向上捲動 一行。 若捲動區域是整個終端機畫面,且終端機處於 主畫面,這可能產生回滾緩衝區。更多細節請參閱 捲動 文件。

若游標位於捲動區域之外,或不在捲動區域的下邊界上,則以 n = 1 執行 游標下移 操作。

此序列僅在游標恰好位於下邊界且處於剩餘捲動區域之內時才會捲動。若游標位於捲動區域之外且處於終端機底列,則游標不移動。

驗證

IND V-1:無捲動區域,畫面頂部

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "A"
printf "\033D" # index
printf "X"
|A_________|
|_Xc_______|

IND V-2:主畫面底部

lines=$(tput lines)
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[${lines};1H" # move to bottom-left
printf "A"
printf "\033D" # index
printf "X"
|A_________|
|_Xc_______|

IND V-3:捲動區域內部

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[1;3r" # scroll region
printf "A"
printf "\033D" # index
printf "X"
|A_________|
|_Xc_______|

IND V-4:捲動區域底部

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[1;3r" # scroll region
printf "\033[4;1H" # below scroll region
printf "B"
printf "\033[3;1H" # move to last row of region
printf "A"
printf "\033D" # index
printf "X"
|__________|
|A_________|
|_Xc_______|
|B_________|

IND V-5:帶捲動區域的主畫面底部

lines=$(tput lines)
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[1;3r" # scroll region
printf "\033[3;1H" # move to last row of region
printf "A"
printf "\033[${lines};1H" # move to bottom-left
printf "\033D" # index
printf "X"
|__________|
|__________|
|A_________|
|__________|
|Xc________|

IND V-6:左右捲動區域之外

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[?69h" # enable left/right margins
printf "\033[1;3r" # scroll region top/bottom
printf "\033[3;5s" # scroll region left/right
printf "\033[3;3H"
printf "A"
printf "\033[3;1H"
printf "\033D" # index
printf "X"
|__________|
|__________|
|XcA_______|

IND V-7:左右捲動區域之內

printf "\033[1;1H" # move to top-left
printf "\033[0J"   # clear screen
printf "AAAAAA\n"
printf "AAAAAA\n"
printf "AAAAAA"
printf "\033[?69h" # enable left/right margins
printf "\033[1;3s" # set scroll region left/right
printf "\033[1;3r" # set scroll region top/bottom
printf "\033[3;1H" # Move to bottom left
printf "\033D" # index
|AAAAAA____|
|AAAAAA____|
|c__AAA____|