Skip to content

Wrong output from shell.Println when receiving from a goroutine #19

Open
@synw

Description

@synw

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:

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:

>>> Feedback
Feedback
Feedback

To get the prompt back you have to type a letter

feed(c) outputs correctly:

Feedback
Feedback
Feedback
>>>  

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions