Skip to content

Commit

Permalink
commands: Only show Ansi escape codes if in a terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Oct 26, 2018
1 parent 7857863 commit df02131
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 50 deletions.
7 changes: 7 additions & 0 deletions commands/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
23 changes: 0 additions & 23 deletions commands/helpers_others.go

This file was deleted.

23 changes: 0 additions & 23 deletions commands/helpers_windows.go

This file was deleted.

22 changes: 18 additions & 4 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/terminal"

"syscall"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit df02131

Please sign in to comment.