I'm working on an application where users are able to execute commands on a server, for this I decided to use this project (great work by the way!), some of these commands are asynchronous jobs which I run using goroutines. I'd like to write the output in the same terminal, however calling things like fmt.Println() breaks the current render.
If there a way I could do this? Eg using a method like InsertLineAboveInput() or something? Or maybe forcibly re-drawing the output? This is the example code I'm working with:
func pollOutput() {
for {
time.Sleep(time.Second))
fmt.Println("Example line") // This breaks the output
prompt.InsertLineAboveInput("Example line") // Something like this, force redraw, etc
}
}
func main() {
go pollOutput() // Example, real implementation is more complex
term := prompt.New(
executor,
completer,
prompt.OptionLivePrefix(func() (string, bool) {
if context == "" {
return "shell>", true
} else {
return fmt.Sprintf("shell(%s)> ", context), true
}
}),
)
term.Run()
}
Question
I'm working on an application where users are able to execute commands on a server, for this I decided to use this project (great work by the way!), some of these commands are asynchronous jobs which I run using goroutines. I'd like to write the output in the same terminal, however calling things like
fmt.Println()
breaks the current render.If there a way I could do this? Eg using a method like
InsertLineAboveInput()
or something? Or maybe forcibly re-drawing the output? This is the example code I'm working with:Thanks a bunch for the reply!