summaryrefslogtreecommitdiffstats
path: root/commands/hugo.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-26 14:32:32 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-26 14:33:44 +0200
commitdf021317a964a482cd1cd579de5a12d50faf0d08 (patch)
tree5c8b357a86e99698296b01134f39ba4a6b9f14fe /commands/hugo.go
parent78578632f545283741a01f024a6ccedc0b695a30 (diff)
commands: Only show Ansi escape codes if in a terminal
Diffstat (limited to 'commands/hugo.go')
-rw-r--r--commands/hugo.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/commands/hugo.go b/commands/hugo.go
index 1cfbdcf7c..ce11626eb 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -27,6 +27,7 @@ import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers"
+ "github.com/gohugoio/hugo/common/terminal"
"syscall"
@@ -264,6 +265,17 @@ func setValueFromFlag(flags *flag.FlagSet, key string, cfg config.Provider, targ
}
}
+func isTerminal() bool {
+ return terminal.IsTerminal(os.Stdout)
+
+}
+func ifTerminal(s string) string {
+ if !isTerminal() {
+ return ""
+ }
+ return s
+}
+
func (c *commandeer) fullBuild() error {
var (
g errgroup.Group
@@ -271,10 +283,12 @@ func (c *commandeer) fullBuild() error {
)
if !c.h.quiet {
- fmt.Print(hideCursor + "Building sites … ")
- defer func() {
- fmt.Print(showCursor + clearLine)
- }()
+ fmt.Print(ifTerminal(hideCursor) + "Building sites … ")
+ if isTerminal() {
+ defer func() {
+ fmt.Print(showCursor + clearLine)
+ }()
+ }
}
copyStaticFunc := func() error {