Comments (9)
I have found an ugly workaround using go:linkname and SIGWINCH.
Probably good enough for pet projects, but be wary of the required import of "unsafe".
import (
"syscall"
_ "unsafe" // Required for go:linkname
"github.com/c-bata/go-prompt"
)
// Map the local variable "consoleWriter" to the one of go-prompt
//go:linkname consoleWriter github.com/c-bata/go-prompt.consoleWriter
var consoleWriter prompt.ConsoleWriter
func AsyncWrite(str string) {
consoleWriter.EraseLine() // Erase current line
consoleWriter.EraseDown() // Required to remove the completions menu
consoleWriter.WriteRawStr("\r" + str) // 'r' to go back to the start of line
syscall.Kill(syscall.Getpid(), syscall.SIGWINCH) // Required to force the re-render of the prompt
}
Note: rather than using syscall.Kill, it is possible to use the reflection API, but it doesn't really make it cleaner.
from go-prompt.
I noticed that I can achieve the desired functionality by raising SIGWINCH after printing my output, since that will cause go-prompt to re-render the prompt. Bit crude solution, but it works, so feel free to close this issue if this solution is deemed adequate.
from go-prompt.
I'm also interested in this. The SIGWINCH workaround re-renders the prompt but the first line of the output still has the previous prompt prefixed (you have to add a \x0d for CR) and also part of the menu "sticks" to the output lines if the menu was open at the time of the print. Maybe there can be a channel where we could send async messages for rendering.
from go-prompt.
A p.GetScrollbackWriter() io.Writer
method would be nice and should solve this need. Almost all programs can use a writer like that for the basis of their logging, etc, without needing internal modification to work well with go-prompt.
from go-prompt.
I did something like this before here (in a library that's much less cool than go-prompt)... the only thing I learned is that it's safest to always the cursor back up to the top of your footer/prompt area at the end of every render -- that means even uncontrolled prints to the terminal don't get overwritten, for the most part.
(It's still important to have the p.GetScrollbackWriter() io.Writer
part and prefer to use it though; just printing to the terminal directly will both overwrite the footer/prompt, and it's preferable to do a clear before printing a new line in case the footer/prompt is longer than the new line.)
from go-prompt.
I think you can pause the executor by waitGroup
or select
to prevent new prompt pops up.
from go-prompt.
I was looking for this feature too. Bumping the issue.
from go-prompt.
I too am looking for a feature that can do this. I was hoping maybe there was a solution that works for Windows as well :(
from go-prompt.
Hitting this right now as well!
Sending SIGWINCH partially solves the problem but the main problem then is the upper line of the completions stays and is never cleared. That's what @juanmera said too.
There should really be a channel to send log messages as part of prompt
.
from go-prompt.
Related Issues (20)
- [Feature Request] Example for Simple Yes/No/Quit question?
- Update README: `aws-sso` uses go-prompt
- [Feature Request] Option to escape special characters or quote strings containing special characters
- [Feature Request] MacOS keyboard support is not complete
- Sorry for the delayed response. I've just pushed v0.2.6 tag.
- [Feature Request] Need a way to terminate unresponsive executors HOT 1
- [Bug]Strange bug when using `fmt.Scanln` after upgrade to v0.2.6 HOT 1
- [Bug] `prompt.Input` leaks file descriptor of "/dev/tty"
- [Question] Force prompt.Input() redraw during goroutine
- Allow specifiying arbitrary io.ReadWriters to read input and write output to (including escape codes)
- [Bug] Unexpected behavior of log output HOT 1
- How to customize suggestion rendering?
- [Bug] Terminal Colors not reset after application exists HOT 2
- [Bug] In the v0.2.6 , the icnl attribute of the stty is modified, but the attribute is not restored. v0.2.5 is ok HOT 5
- A CI/CD Observability Solution Suggestion
- Project FireQL using go-prompt HOT 1
- GPT cli An interactive ChatGPT client featuring shortcuts and auto-complete - thanks to go-prompt
- [Feature Request]
- [Feature Request] Allow for TTYs other than STDIN
- [Bug] panic: runtime error: integer divide by zero
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-prompt.