Skip to content

Commit 64f8ac1

Browse files
author
Akshay Shekher
committed
only print new line if stdout is not being piped, pbcopy thanks you
1 parent 2d8ccff commit 64f8ac1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/emos/main.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ func printResult(e *emos.Emoji) {
6262
b.WriteString(e.Image)
6363
}
6464

65-
fmt.Printf("%s\n", b.String())
65+
if !isStdoutPiped() {
66+
b.WriteByte('\n')
67+
}
68+
fmt.Printf("%s", b.String())
69+
}
70+
71+
func isStdoutPiped() bool {
72+
info, err := os.Stdout.Stat()
73+
if err != nil {
74+
return false
75+
}
76+
return info.Mode()&os.ModeCharDevice == 0
6677
}
6778

6879
func configFile(name string) string {

0 commit comments

Comments
 (0)