abiosoft / abiosoft/ishell

Wrong output from shell.Println when receiving from a goroutine

Open
#19 11 comments 1 reaction 0 assignees View on GitHub
in progress
Dominant language
Go
Stars
1.8k
Forks
213
PR merge metrics
No merged PRs in 30d

Description

I am trying to print some output from a channel to the shell. When receiving from a goroutine it prints without a newline and does not give the prompt back. Example:
```go
package main

import (
"time"
"github.com/abiosoft/ishell"
)

func feed(c chan string) {
for i := 0; i<3; i++ {
c <- "Feedback"
time.Sleep(time.Second)
}
}

func main(){
shell := ishell.New()
c := make(chan string)

// listen
go func() {
for msg := range(c) {
shell.Println(msg)
}
}()

// this does output correctly
//feed(c)
// this does not
go feed(c)

shell.Start()
}
```
`go feed(c)` outputs:
```bash
>>> Feedback
Feedback
Feedback
```
To get the prompt back you have to type a letter

`feed(c)` outputs correctly:
```bash
Feedback
Feedback
Feedback
>>>
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.