Skip to content

Commit

Permalink
create ios/console.go and ios/console_windows.go files in ios
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Feb 4, 2022
1 parent f001d4d commit d0c066b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/spf13/viper v1.10.0
github.com/tidwall/gjson v1.14.0
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838
golang.org/x/sys v0.0.0-20211210111614-af8b64212486
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
)

Expand Down Expand Up @@ -62,7 +63,6 @@ require (
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
16 changes: 16 additions & 0 deletions ios/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build !windows

package ios

import (
"os"
"errors"
)

func (s *IOStreams) EnableVirtualTerminalProcessing() error {
return nil
}

func enableVirtualTerminalProcessing(f *os.File) error {
return errors.New("not implemented")
}
31 changes: 31 additions & 0 deletions ios/console_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// +build windows

package ios

import (
"os"

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

func (s *IOStreams) EnableVirtualTerminalProcessing() error {
if !s.IsStdoutTTY() {
return nil
}

f, ok := s.originalOut.(*os.File)
if !ok {
return nil
}

return enableVirtualTerminalProcessing(f)
}

func enableVirtualTerminalProcessing(f *os.File) error {
stdout := windows.Handle(f.Fd())

var originalMode uint32
windows.GetConsoleMode(stdout, &originalMode)

return windows.SetConsoleMode(stdout, originalMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
}

0 comments on commit d0c066b

Please # to comment.