Move this check before allocation.
Make sure the text is null terminated.
Make sure text fits tightly terminal + simplified logic
Better input scroll logic.