air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
16.53k stars 779 forks source link

`air` does not support basic I/O operations #428

Closed lead8000 closed 8 months ago

lead8000 commented 1 year ago

This is a small example that shows the issue. Here is the source code:

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    reader := bufio.NewReader(os.Stdin)
    fmt.Print("Enter your name: ")
    name, _ := reader.ReadString('\n')
    fmt.Println("Hello,", name)
}

This is the result of running it with air. Waits to print, but never prints:

$ air
  __    _   ___  
 / /\  | | | |_) 
/_/--\ |_| |_| \_ , built with Go 

watching .
!exclude tmp
building...
running...
Enter your name: myName

And this is the result of running it without air:

$ go run ./main.go
Enter your name: myName
Hello, myName
xiantang commented 1 year ago

Yes, because Air listens for events like Ctrl-C, if we support passing input to our program, it will also pass Ctrl-C to our program

makiuchi-d commented 1 year ago

arelo supports stdin passing. In addition, Ctrl-C works well.

$ arelo -- go run .
2023/05/31 22:57:37 [ARELO] start: go run .
Enter your name: myName
Hello, myName

2023/05/31 22:57:45 [ARELO] command exit status 0
^C2023/05/31 22:57:50 [ARELO] signal: interrupt
$
xiantang commented 8 months ago

dupl https://github.com/cosmtrek/air/issues/387

erlichmen commented 3 months ago

stdio still doesn't work, The following code will return err "EOF" and not read from the stdio the response

        fmt.Println("Are you sure? (yes/no)")

        reader := bufio.NewReader(os.Stdin)

        response, err := reader.ReadString('\n')
        if err != nil {
            log.Fatalln("Error reading input:", err)
            return
        }