Skip to content

Support usage in scenarios where stdin / stdout are pipes (but stderr is a TTY) #129

@cipriancraciun

Description

@cipriancraciun

Usually in almost all circumstances /dev/sdterr is a TTY; meanwhile /dev/stdin and/or /dev/stdout can be redirected to files or pipes. (In fact if /dev/stderr is not a TTY, most likely the other two are inherited or poorly set-up, and this process isn't meant to handle the terminal.)

At the moment liner checks if any of stdin or stdout are redirected, and if so degrades to a "dumb" terminal:

  • liner/input.go

    Lines 38 to 49 in abb5e9d

    s.terminalSupported = TerminalSupported()
    if m, err := TerminalMode(); err == nil {
    s.origMode = *m.(*termios)
    } else {
    s.inputRedirected = true
    }
    if _, err := getMode(syscall.Stdout); err != 0 {
    s.outputRedirected = true
    }
    if s.inputRedirected && s.outputRedirected {
    s.terminalSupported = false
    }

My proposal (which I could implement if accepted) is to either:

  • (preferably) always use /dev/stderr for both input and output and check that itself is a TTY;
  • alternatively if either stdin or stdout seems to be redirected, check if perhaps stderr is a TTY and use that;

I currently use liner in such a scenario, and for the moment I replace syscall.Stdin / syscall.Stdout with syscall.Stderr and it seems to do the trick. However this hack works in my limited case, but as said I'm willing to code this proposed feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions