GHC 2020-07-02

4 comments.

, https://git.io/JJTUY in creack/pty
ptmx doesn't play well with ioutil.ReadAll on Linux?
====================================================

Consider this slight variation of the example in README:

```go
package main

import (
        "github.com/creack/pty"
        "fmt"
        "log"
        "io/ioutil"
        "os/exec"
)

func main() {
        c := exec.Command("grep", "--color=auto", "bar")
        f, err := pty.Start(c)
        if err != nil {
                panic(err)
        }

        go func() {
                f.Write([]byte("foo\n"))
                f.Write([]byte("bar\n"))
                f.Write([]byte("baz\n"))
                f.Write([]byte{4}) // EOT
        }()
        output, err := ioutil.ReadAll(f)
        if err != nil {
                log.Fatalf("error reading from pty: %#v; content read thus far: %v", err, string(output))
        }
        fmt.Print(string(output))
}
```

On Ubuntu 20.04 with go 1.13 or 1.14, I'm getting this error:

```
2020/07/02 13:08:25 error reading from pty: &os.PathError{Op:"read", Path:"/dev/ptmx", Err:0x5}; content read thus far: foo
bar
baz
bar
```

It seems `/dev/ptmx` is just... gone before `ioutil.ReadAll` could get an EOF? FWIW I have no problem reading with a `bufio.Scanner`, and the same code seems to work on macOS just fine.

I'm pretty new to golang and I suspect there's some intricacy of `ioutil.ReadAll` that I'm not seeing, so this might be more of a question than a bug report. Nevertheless, it would be nice if `ioutil.ReadAll` worked with ptmx. What do you think?

, https://git.io/JJUhz in zmwangx/ets
Do note that TAB is not expanded.

, https://git.io/JJUAS in zmwangx/ets
Turns out it's literally impossible to do this with pflag. https://github.com/spf13/pflag/issues/126

What's even more stupid is even a fallback I came up with — using `-c` as a boolean flag, and `--color <colorname>` as a string flag — is impossible. You simply can't have a standalone short option with pflag. https://github.com/spf13/pflag/pull/256

Go is a decade old now and one can't implement the CLI interface of `ls` without writing their own goddamn parser. Great. Guess the community really hates GNU.

You don't know how much I miss Python.

So now I'm gonna settle for `-c, --color`. If there's interest (which probably won't happen anyway as I never promote my projects anywhere...) a separate option like `-C, --custom-color <colorname>` could be added.

, https://git.io/JJU9C in zmwangx/ets
Add color option to easily color timestamps
===========================================

`-c, --color [colorname]`.