Cursor Position (CUP)
Move the cursor to row `y` and column `x`.
- 0x1B
- ESC
- 0x5B
- [
- ____
- y
- 0x3B
- ;
- ____
- x
- 0x48
- H
The parameters y
and x
must be integers greater than or equal to 1.
If either is less than or equal to 0, adjust that parameter to be 1.
The values y
and x
are both one-based. For example, the top row is row 1
and the leftmost column on the screen is column 1.
This sequence always unsets the pending wrap state.
If origin mode is NOT set, the cursor is moved exactly to the
row and column specified by y
and x
. The maximum value for y
is the
bottom row of the screen and the maximum value for x
is the rightmost
column of the screen.
If origin mode is set, the cursor position is set relative
to the top-left corner of the scroll region. y = 1
corresponds to
the top margin and x = 1
corresponds to the left margin.
The maximum value for y
is the bottom margin and the maximum
value for x
is the right margin.
When origin mode is set, it is impossible set a cursor position using this sequence outside the boundaries of the scroll region.
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[2;3H"
printf "A"
|__________|
|__Ac______|
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[500;500H"
printf "A"
|__________|
|__________|
|_________Ac
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[2;3r" # scroll region top/bottom
printf "\033[?6h" # origin mode
printf "\033[1;1H" # move to top-left
printf "X"
|__________|
|X_________|
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[?69h" # enable left/right margins
printf "\033[3;5s" # scroll region left/right
printf "\033[2;3r" # scroll region top/bottom
printf "\033[?6h" # origin mode
printf "\033[1;1H" # move to top-left
printf "X"
|__________|
|__X_______|
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[?69h" # enable left/right margins
printf "\033[3;5s" # scroll region left/right
printf "\033[2;3r" # scroll region top/bottom
printf "\033[?6h" # origin mode
printf "\033[500;500H" # move to top-left
printf "X"
|__________|
|__________|
|____X_____|
cols=$(tput cols)
printf "\033[${cols}G" # move to last column
printf "A" # set pending wrap state
printf "\033[1;1H"
printf "X"
|Xc_______X|