Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions writter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package isatty

import "io"

// IsWriterTerminal return true if the writer is terminal.
func IsWriterTerminal(w io.Writer) bool {
if f, ok := w.(filelike); ok {
return IsTerminal(f.Fd())
}
return false
}

// IsWriterCygwinTerminal return true if the writer is a cygwin or msys2 terminal.
func IsWriterCygwinTerminal(w io.Writer) bool {
if f, ok := w.(filelike); ok {
return IsCygwinTerminal(f.Fd())
}
return false
}

type filelike interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a type alias to avoid defining a real type:

Suggested change
type filelike interface {
type filelike = interface {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely can do it. I'm just wondering why? The type is private, so what's the point?

Fd() uintptr
}
18 changes: 18 additions & 0 deletions writter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package isatty_test

import (
"os"
"testing"

"github.com/mattn/go-isatty"
)

func TestIsWriterTerminal(t *testing.T) {
// test for non-panic
isatty.IsWriterTerminal(os.Stdout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log test result:

Suggested change
isatty.IsWriterTerminal(os.Stdout)
t.Log("os.Stdout:", isatty.IsWriterTerminal(os.Stdout))

}

func TestIsWriterCygwinTerminal(t *testing.T) {
// test for non-panic
isatty.IsWriterCygwinTerminal(os.Stdout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log test result:

Suggested change
isatty.IsWriterCygwinTerminal(os.Stdout)
t.Log("os.Stdout:", isatty.IsWriterCygwinTerminal(os.Stdout))

}