Horizontal Position Absolute (HPA)
Move the cursor to a specific column without changing the row.
- 0x1B
- ESC
- 0x5B
- [
- ____
- x
- 0x47
- G
- 0x1B
- ESC
- 0x5B
- [
- ____
- x
- 0x60
- `
The parameter x must be an integer greater than or equal to 1. If x is
less than or equal to 0, adjust x to be 1. If x is omitted, x defaults
to 1. The column value is one-based: the leftmost column is column 1.
This sequence always unsets the pending wrap state.
HPA is functionally equivalent to Cursor Position (CUP)
with the row set to the current cursor row and the column set to x. The
cursor row never changes as a direct effect of HPA, but origin mode may
still influence the resulting position (see below).
If origin mode is NOT set, the cursor is moved to column x
clamped to the rightmost screen column.
If origin mode is set, x = 1 corresponds to the
left margin and the maximum value for x is the
right margin. When origin mode is set, it is impossible to position
the cursor outside the horizontal scroll region with this sequence.
Note
Two final bytes are accepted for HPA:
Gand`(backtick). The backtick form is a legacy alias accepted by xterm and most modern terminals; both forms are equivalent. HPA is functionally similar to CHA (Cursor Horizontal Absolute,CSI Px G), and in practice the two sequences share the same handler in many implementations.
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[2;1H" # move to row 2, column 1
printf "A"
printf "\033[5G" # HPA to column 5
printf "X"
|__________|
|A___Xc____|
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[3\`" # HPA (backtick form) to column 3
printf "X"
|__Xc______|
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[500G" # HPA past the right edge
printf "X"
|_________Xc
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 columns 3..5
printf "\033[?6h" # origin mode
printf "\033[1;1H" # origin-relative top-left
printf "\033[500G" # HPA past the right margin
printf "X"
|____Xc____|
cols=$(tput cols)
printf "\033[${cols}G" # move to last column
printf "A" # set pending wrap state
printf "\033[3G" # HPA cancels pending wrap
printf "X"
|__Xc_____A|