Skip to content

Commit 44d35ed

Browse files
committed
Improved support for Windows terminals
Command Prompt, PowerShell, MinGW
1 parent 4876222 commit 44d35ed

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

command/report.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"regexp"
9+
"strings"
910

1011
"github.com/git-time-metric/gtm/report"
1112
"github.com/git-time-metric/gtm/scm"
@@ -65,9 +66,14 @@ func (r ReportCmd) Run(args []string) int {
6566
commits = append(commits, a)
6667
}
6768

68-
// TODO: if running from within a MINGW console isatty does not work
69+
// if running from within a MINGW console isatty detection does not work
6970
// https://github.com/mintty/mintty/issues/482
70-
if !isatty.IsTerminal(os.Stdin.Fd()) && len(commits) == 0 && *limit == 0 {
71+
isMinGW := strings.HasPrefix(os.Getenv("MSYSTEM"), "MINGW")
72+
if isMinGW && *limit == 0 && len(commits) == 0 {
73+
fmt.Println("\nGTM does not fully support the MinGW console, defaulting to gtm report -n 1")
74+
fmt.Println("To avoid this message, use gtm report -n option or directly provide SHA1s as arguments")
75+
}
76+
if !isMinGW && !isatty.IsTerminal(os.Stdin.Fd()) && len(commits) == 0 && *limit == 0 {
7177
scanner := bufio.NewScanner(os.Stdin)
7278
for scanner.Scan() {
7379
if !sha1Regex.MatchString(scanner.Text()) {

project/project.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"log"
99
"os"
1010
"path/filepath"
11+
"runtime"
1112
"strings"
1213
"text/template"
1314
"time"
1415

15-
"golang.org/x/crypto/ssh/terminal"
16-
1716
"github.com/git-time-metric/gtm/scm"
17+
isatty "github.com/mattn/go-isatty"
1818
)
1919

2020
var (
@@ -112,7 +112,7 @@ func Initialize() (string, error) {
112112
}
113113

114114
headerFormat := "%s"
115-
if terminal.IsTerminal(int(os.Stdout.Fd())) {
115+
if isatty.IsTerminal(os.Stdout.Fd()) && runtime.GOOS != "windows" {
116116
headerFormat = "\x1b[1m%s\x1b[0m"
117117
}
118118

@@ -171,7 +171,7 @@ func Uninitialize() (string, error) {
171171
}
172172

173173
headerFormat := "%s"
174-
if terminal.IsTerminal(int(os.Stdout.Fd())) {
174+
if isatty.IsTerminal(os.Stdout.Fd()) && runtime.GOOS != "windows" {
175175
headerFormat = "\x1b[1m%s\x1b[0m"
176176
}
177177
b := new(bytes.Buffer)

report/report.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package report
33
import (
44
"bytes"
55
"os"
6+
"runtime"
67
"text/template"
78

8-
"golang.org/x/crypto/ssh/terminal"
9-
109
"github.com/git-time-metric/gtm/note"
1110
"github.com/git-time-metric/gtm/util"
11+
isatty "github.com/mattn/go-isatty"
1212
)
1313

1414
var funcMap = template.FuncMap{
@@ -89,7 +89,7 @@ func Commits(commits []string, totalOnly bool) (string, error) {
8989
t = template.Must(template.New("Commits").Funcs(funcMap).Parse(commitsTpl))
9090
}
9191
headerFormat := "%s"
92-
if terminal.IsTerminal(int(os.Stdout.Fd())) {
92+
if isatty.IsTerminal(os.Stdout.Fd()) && runtime.GOOS != "windows" {
9393
headerFormat = "\x1b[1m%s\x1b[0m"
9494
}
9595
err := t.Execute(

0 commit comments

Comments
 (0)