Here in your code
\r
\r means Carriage Return, which means: return the cursor to the beginning of the line in more simple words we can say that it's deleting each character from the active position upto the beginning.
\n
\n mean New Line
\b
\b mean Backspace
Let's take it one step at a time:
<new line>ab<backspace>si<carriage return>ha
First, handle the backspace. Note that even though it is "non-erase", the next character to be output would overwrite what was backspaced over:
<new line>asi<carriage return>ha
Now, a carriage return means to go back to the beginning of the line. So the "ha" overwrites the "as" in "asi:
<new line>hai
Now, the cursor is currently sitting on the i, so the next character to be output would overwrite i.