Skip to content

Commit

Permalink
Windows support (#15)
Browse files Browse the repository at this point in the history
* Begin adding better windows support

* Support colors and output on windows
  • Loading branch information
zix99 authored Nov 24, 2019
1 parent dd09628 commit 81faafb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 1 addition & 4 deletions pkg/color/coloring.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package color
import (
"fmt"
"os"
"runtime"
"strings"
)

Expand Down Expand Up @@ -43,9 +42,7 @@ var Enabled = true
var groupColors = [...]ColorCode{Red, Green, Yellow, Blue, Magenta, Cyan}

func init() {
if runtime.GOOS == "windows" {
Enabled = false
} else if fi, err := os.Stdout.Stat(); err == nil {
if fi, err := os.Stdout.Stat(); err == nil {
if (fi.Mode() & os.ModeCharDevice) == 0 {
Enabled = false
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/multiterm/multiterm_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package multiterm

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

func addFlagToWindowsTerm(file *os.File) error {
term := windows.Handle(file.Fd())
var outMode uint32
if err := windows.GetConsoleMode(term, &outMode); err == nil {
if err := windows.SetConsoleMode(term, outMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
return err
}
} else {
return err
}
return nil
}

func init() {
addFlagToWindowsTerm(os.Stdout)
addFlagToWindowsTerm(os.Stderr)
}

0 comments on commit 81faafb

Please sign in to comment.