By messes up terminal history do you mean when you push up in terminal the previous lines that show up are rendered badly or that your actual history is effected in some way?
I used the ANSI control codes for moving the cursor, which seems to overwrite previous lines. Not sure if there's another way to achieve that without overwriting lines though.