I am writing an interactive application that accepts user inputs in a loop and prints out responses in the background. The reader part of my code looks like:
scanner := bufio.NewReader(os.Stdin)
for {
fmt.Print(":: ") // prompt for user to enter stuff
in,_:=scanner.ReadString('
')
}
However, while I am waiting for the user input, I want to print some asynchronous data I got over the network like so:
>> Some text
>> :: Hi I'm the user and I'm
Now some background data arrives:
>> Some text
>> This data was printed while user was inputting
>> :: Hi I'm the user and I'm
And now the user can finish their input:
>> Some text
>> This data was printed while user was inputting
>> :: Hi I'm the user and I'm entering some text
>> ::
I'm thinking that the background routine would need to scan stdin
for text, erase it somehow, print its own data, and restore the original text. I do not know how to scan text that has not been input via the enter key, or how to clear a line. How do I go about it?