Skip to content

Commit

Permalink
fix: escape sequences on windows powershell (#234)
Browse files Browse the repository at this point in the history
* fix: escape sequences on windows powershell

* cleanup binaries

* Update init_windows.go

* Update internal/cli/root.go

Co-authored-by: Rita Zerrizuela <[email protected]>

Co-authored-by: Rita Zerrizuela <[email protected]>
  • Loading branch information
jfatta and Widcket authored Apr 5, 2021
1 parent 804d3b6 commit 7e224d1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/golang/mock v1.5.0
github.com/golang/snappy v0.0.3 // indirect
github.com/google/go-cmp v0.5.5
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/klauspost/compress v1.11.9 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/lestrrat-go/jwx v1.1.4
Expand All @@ -33,7 +34,7 @@ require (
github.com/zalando/go-keyring v0.1.1
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
golang.org/x/sys v0.0.0-20210305023407-0d6cb8bd5a4b // indirect
golang.org/x/sys v0.0.0-20210305023407-0d6cb8bd5a4b
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
golang.org/x/text v0.3.5 // indirect
gopkg.in/auth0.v5 v5.11.0
Expand Down
7 changes: 7 additions & 0 deletions internal/ansi/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !windows

package ansi

// InitConsole initializes any platform-specific aspect of the terminal.
// This method will run for all except Windows.
func InitConsole() {}
21 changes: 21 additions & 0 deletions internal/ansi/init_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ansi

import (
"golang.org/x/sys/windows"
)

// InitConsole configures the standard output and error streams
// on Windows systems. This is necessary to enable colored and ANSI output.
// This is the Windows implementation of ansi/init.go.
func InitConsole() {
setWindowsConsoleMode(windows.Stdout, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
setWindowsConsoleMode(windows.Stderr, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
}

func setWindowsConsoleMode(handle windows.Handle, flags uint32) {
var mode uint32
// set the console mode if not already there:
if err := windows.GetConsoleMode(handle, &mode); err == nil {
_ = windows.SetConsoleMode(handle, mode|flags)
}
}
6 changes: 6 additions & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/buildinfo"
"github.com/auth0/auth0-cli/internal/display"
"github.com/auth0/auth0-cli/internal/instrumentation"
Expand Down Expand Up @@ -107,6 +108,11 @@ func Execute() {
}
}()

// platform specific terminal initialization:
// this should run for all commands,
// for most of the architectures there's no requirements:
ansi.InitConsole()

if err := rootCmd.ExecuteContext(context.TODO()); err != nil {
cli.renderer.Heading("error")
cli.renderer.Errorf(err.Error())
Expand Down
1 change: 1 addition & 0 deletions vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e224d1

Please sign in to comment.