Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Force prompt.Input() redraw during goroutine #255

Open
Paradoxis opened this issue Apr 24, 2022 · 0 comments
Open

[Question] Force prompt.Input() redraw during goroutine #255

Paradoxis opened this issue Apr 24, 2022 · 0 comments

Comments

@Paradoxis
Copy link

Paradoxis commented Apr 24, 2022

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:

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()
}

Thanks a bunch for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant