Permalink
Browse files

commands: Only show Ansi escape codes if in a terminal

  • Loading branch information...
bep committed Oct 26, 2018
1 parent 7857863 commit df021317a964a482cd1cd579de5a12d50faf0d08
Showing with 25 additions and 50 deletions.
  1. +7 −0 commands/helpers.go
  2. +0 −23 commands/helpers_others.go
  3. +0 −23 commands/helpers_windows.go
  4. +18 −4 commands/hugo.go
@@ -23,6 +23,13 @@ import (
"github.com/spf13/cobra"
)
const (
ansiEsc = "\u001B"
clearLine = "\r\033[K"
hideCursor = ansiEsc + "[?25l"
showCursor = ansiEsc + "[?25h"
)
type flagsToConfigHandler interface {
flagsToConfig(cfg config.Provider)
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -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,17 +265,30 @@ 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
langCount map[string]uint64
)
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 {

0 comments on commit df02131

Please sign in to comment.