Println arbitrarily prints line after the prompt
#39
test code
var app = grumble.New(&grumble.Config{
Name: "foo",
Description: "An awesome foo bar",
})
func init() {
app.AddCommand(&grumble.Command{
Name: "listen",
Aliases: []string{"l"},
Help: "listen",
Args: func(a *grumble.Args) {
a.String("host", `a host to listen to (for ipv6 put in square brackets. eg: "[::1]")`, grumble.Default("0.0.0.0"))
},
Run: func(c *grumble.Context) error {
go Pr()
return nil
},
})
}
func Pr() {
app.Println("[-] A listener is already running.")
}
in windwos10 cmd

in windwos10 powershell

Thank you for this sample. I can now reproduce it as well.
The issue is probably the concurrent write to Stdout(). Even though we are using readline's Stdout() (when possible), I am not sure if they implemented it properly.
This is their code that handles the writes around stdout:
func (w *wrapWriter) Write(b []byte) (int, error) {
if !w.t.IsReading() {
return w.target.Write(b)
}
var (
n int
err error
)
w.r.buf.Refresh(func() {
n, err = w.target.Write(b)
})
if w.r.IsSearchMode() {
w.r.SearchRefresh(-1)
}
if w.r.IsInCompleteMode() {
w.r.CompleteRefresh()
}
return n, err
}
The IsReading() method uses an atomic for the check, but no kind of locking is taking place...
@skaldesh let's try a quick fix with a mutex. In the long term we should search for a readline alternative (#15)
There is a solution in project Sliver that I think you can try
Clearln = "\r\x1b[2K"
fmt.Println(Clearn + " demo string")
@sairson Thank you for your help, it looks like this now, but it looks more comfortable than before
