I want to make a program that should show the history of commands like shells do using curves.

My problem is that i don't know how to clear and re-write another command in the same position without print one more prompt.

ex :
myshell > command1
By pressing the up-curve i want to do
myshell > command2
And not print and the last command like
myshell > command1
myshell > command2
In reality i want to clear and write without clearing the whole screen.

Is this easy or better use something else ?