Horizontal Position Relative (HPR)

Move the cursor forward `n` columns without changing the row.

  1. 0x1B
    ESC
  2. 0x5B
    [
  3. ____
    x
  4. 0x61
    a

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.

This sequence always unsets the pending wrap state.

HPR moves the cursor x columns to the right of its current position. The cursor row does not change. HPR is paired with HPA the same way CUF is paired with CHA: HPA selects an absolute column, HPR selects a column relative to where the cursor is now.

The rightmost boundary the cursor can move to is determined by the current cursor column and the right margin. If the cursor begins to the right of the right margin, the rightmost column is the rightmost column of the screen. The cursor stops at the boundary regardless of the remaining value of x; this sequence never wraps to the next line and never modifies cell content.

Note

In practice HPR and CUF (Cursor Forward, CSI Pn C) produce identical results for the same parameter; both clamp at the right margin and both unset pending wrap. Many terminals share the same handler for both sequences.

Validation

HPR V-1: Normal Usage

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "A"
printf "\033[3a" # HPR forward 3 columns
printf "X"
|A___Xc____|

HPR V-2: Default Parameter

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "A"
printf "\033[a" # HPR with default (1)
printf "X"
|A_Xc______|

HPR V-3: Clamps at Right Margin

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "A"
printf "\033[500a" # HPR way past the edge
printf "X"
|A________Xc

HPR V-4: Pending Wrap is Unset

cols=$(tput cols)
printf "\033[${cols}G" # move to last column
printf "A" # set pending wrap state
printf "\033[1a" # HPR cancels pending wrap
printf "X"
|________AX|