I'm trying to create a messaging client with a terminal interface. The problem I'm having is I want to print messages to stdout while the user might be typing into stdin. When I do this the user input typed into stdin get disrupted by the message. Is there any way to clear the last line of stdin, then print to stdout and then restore the last line of stdin so the user can finish their message?
Currently I read from stdin with bufio.Reader.ReadString('
')
and I print to stdout with the normal fmt.Println
and fmt.Printf
functions
An example of the current situation:
# user is typing message
Hey Stan ho
# message from other user comes in
# it is: "Hey Bart"
# last line in terminal is now:
Hey Stan hoHey bart
What I want is to clear the "Hey Stan ho" then print the incoming message and then put the "Hey Stan ho" back