設定頂部與底部邊界 (DECSTBM)

設定頂部與底部邊界,也稱為捲動區域。

  1. 0x1B
    ESC
  2. 0x5B
    [
  3. ____
    t
  4. 0x3B
    ;
  5. ____
    b
  6. 0x72
    r

參數 t 和 b 是整數值。如果任一值為 0,該值將被 重設為預設值。t 的預設值是 1, b 的預設值是畫面的列數。

值 t 和 b 可以省略。如果任一值被省略, 則使用其預設值。請注意,不可能省略 t 而不省略 b。唯一有效的序列是 CSI t ; b r、 CSI t r 和 CSI r。

如果 top 大於等於 bottom,此序列不執行任何動作。捲動區域 必須至少有兩列(b 必須大於 t)。 此序列描述的其餘部分假定 t 和 b 為有效值。

此序列會取消待定換行狀態,並將游標移到 畫面左上角。如果設定了 原點模式,游標會 移到捲動區域的左上角。

要重設捲動區域,呼叫此序列並將兩個值都設為 "0"。這將強制 t 和 b 的預設值, 即整個畫面。

頂部與底部邊界構成了所謂的_捲動區域_。捲動區域影響 許多序列的操作,如 插入行、游標下移 等。捲動區域是將終端機的修改限制在 畫面內矩形區域的有效且高效的方式。

驗證

DECSTBM V-1:整個畫面

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "ABC\n"
printf "DEF\n"
printf "GHI\n"
printf "\033[r" # scroll region top/bottom
printf "\033[T"
|c_______|
|ABC_____|
|DEF_____|
|GHI_____|

DECSTBM V-2:僅頂部

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "ABC\n"
printf "DEF\n"
printf "GHI\n"
printf "\033[2r" # scroll region top/bottom
printf "\033[T"
|ABC_____|
|________|
|DEF_____|
|GHI_____|

DECSTBM V-3:頂部與底部

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "ABC\n"
printf "DEF\n"
printf "GHI\n"
printf "\033[1;2r" # scroll region top/bottom
printf "\033[T"
|________|
|ABC_____|
|GHI_____|

DECSTBM V-4:頂部等於底部

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "ABC\n"
printf "DEF\n"
printf "GHI\n"
printf "\033[2;2r" # scroll region top/bottom
printf "\033[T"
|________|
|ABC_____|
|DEF_____|
|GHI_____|