Hello,
I modified your script to get the same layout in textarea as the typed text. Replacement of '\n' and '\r' by distinct characters (different from " " as was in your original script) in the read and write sections solves it.
Joined : modified script with comments and sample.
Regards,
Jean.