Append lines and scroll at the end of console.

Based on the patch created by Joao Augusto (commit 47358ff)