Skip to content

Commit de9f354

Browse files
authored
Merge pull request #938 from afbjorklund/windows-terminal
Add partial support for cygwin terminal on windows
2 parents d2d8d04 + 174459a commit de9f354

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

cmd/limactl/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"runtime"
89
"strings"
910

1011
"github.com/lima-vm/lima/pkg/store/dirnames"
1112
"github.com/lima-vm/lima/pkg/version"
13+
"github.com/mattn/go-isatty"
1214
"github.com/sirupsen/logrus"
1315
"github.com/spf13/cobra"
1416
)
@@ -58,6 +60,12 @@ func newApp() *cobra.Command {
5860
if debug {
5961
logrus.SetLevel(logrus.DebugLevel)
6062
}
63+
if runtime.GOOS == "windows" && isatty.IsCygwinTerminal(os.Stdout.Fd()) {
64+
formatter := new(logrus.TextFormatter)
65+
// the default setting does not recognize cygwin on windows
66+
formatter.ForceColors = true
67+
logrus.StandardLogger().SetFormatter(formatter)
68+
}
6169
if os.Geteuid() == 0 {
6270
return errors.New("must not run as the root")
6371
}

cmd/limactl/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
136136
return err
137137
}
138138
sshArgs := sshutil.SSHArgsFromOpts(sshOpts)
139-
if isatty.IsTerminal(os.Stdout.Fd()) {
139+
if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
140140
// required for showing the shell prompt: https://stackoverflow.com/a/626574
141141
sshArgs = append(sshArgs, "-t")
142142
}

cmd/limactl/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ $ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/ma
5454
ValidArgsFunction: startBashComplete,
5555
RunE: startAction,
5656
}
57+
// TODO: "survey" does not support using cygwin terminal on windows yet
5758
startCommand.Flags().Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), "enable TUI interactions such as opening an editor, defaults to true when stdout is a terminal")
5859
startCommand.Flags().String("name", "", "override the instance name")
5960
startCommand.Flags().Bool("list-templates", false, "list available templates and exit")

pkg/downloader/downloader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func createBar(size int64) (*pb.ProgressBar, error) {
292292
bar := pb.New64(size)
293293

294294
bar.Set(pb.Bytes, true)
295-
if isatty.IsTerminal(os.Stdout.Fd()) {
295+
if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
296296
bar.SetTemplateString(`{{counters . }} {{bar . | green }} {{percent .}} {{speed . "%s/s"}}`)
297297
bar.SetRefreshRate(200 * time.Millisecond)
298298
} else {

0 commit comments

Comments
 (0)