When an application sends a character to the terminal that is not part of a control sequence and is a non control character the terminal adds this character to the cell array.
TODO: zero width composing characters
If the pending-wrap state is set:
- If wraparound mode is set:
- some terminals save the fact that the line wrapped for their terminal resize and clipboard heuristics.
- if media control: auto print finished lines is active, print the current line.
- invoke index
- Move the cursor to the left margin of the scrolling region
- unset pending-wrap state
If wraparound mode is set:
- If the cursor is on or left of the right-most column in the scrolling region:
- If the width of the printed character is bigger than the space between the cursor (inclusive) and the right-most column of the scrolling region, force a wrap as if the pending wrap state was set (don't force a second wrap if it was set)
- If the width of the printed character is bigger than the space between the cursor (inclusive) and the right-most column of the screen, force a wrap as if the pending wrap state was set (don't force a second wrap if it was set)
If wraparound mode is not set:
- If the width of the printed character is bigger than the space between the cursor (inclusive) and the right-most column of the screen, move the cursor left so that the printed character does fit into the remaining space (TODO only xterm doesn't do this?)
If insert mode is active the current content of the cell pointed to by the cursor is moved right as if by invoking insert blanks with the width of the printed character.
If the current SGR state includes invisible the character is replaced by the same number of spaces as its original width.
Then the character is placed into the cell the cursor points to. If the width of the character is greater than 1 the cell and cells to the right are used. Then the cursor is moved right by the amount of cells corresponding to the width. If the cursor would cross the right margin in this mode the cursor is placed at the right margin and the pending wrap state is set.
If the update splits a multi cell character that character is erased by replacing it with spaces without changing its attributes.
The cells filled with the character are colored and styled according to the current SGR state.