Skip to content

Commit

Permalink
Merge pull request #938 from afbjorklund/windows-terminal
Browse files Browse the repository at this point in the history
Add partial support for cygwin terminal on windows
  • Loading branch information
AkihiroSuda authored Jul 3, 2022
2 parents d2d8d04 + 174459a commit de9f354
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cmd/limactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/lima-vm/lima/pkg/store/dirnames"
"github.com/lima-vm/lima/pkg/version"
"github.com/mattn/go-isatty"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -58,6 +60,12 @@ func newApp() *cobra.Command {
if debug {
logrus.SetLevel(logrus.DebugLevel)
}
if runtime.GOOS == "windows" && isatty.IsCygwinTerminal(os.Stdout.Fd()) {
formatter := new(logrus.TextFormatter)
// the default setting does not recognize cygwin on windows
formatter.ForceColors = true
logrus.StandardLogger().SetFormatter(formatter)
}
if os.Geteuid() == 0 {
return errors.New("must not run as the root")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/limactl/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
return err
}
sshArgs := sshutil.SSHArgsFromOpts(sshOpts)
if isatty.IsTerminal(os.Stdout.Fd()) {
if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
// required for showing the shell prompt: https://stackoverflow.com/a/626574
sshArgs = append(sshArgs, "-t")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/limactl/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ $ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/ma
ValidArgsFunction: startBashComplete,
RunE: startAction,
}
// TODO: "survey" does not support using cygwin terminal on windows yet
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")
startCommand.Flags().String("name", "", "override the instance name")
startCommand.Flags().Bool("list-templates", false, "list available templates and exit")
Expand Down
2 changes: 1 addition & 1 deletion pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func createBar(size int64) (*pb.ProgressBar, error) {
bar := pb.New64(size)

bar.Set(pb.Bytes, true)
if isatty.IsTerminal(os.Stdout.Fd()) {
if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
bar.SetTemplateString(`{{counters . }} {{bar . | green }} {{percent .}} {{speed . "%s/s"}}`)
bar.SetRefreshRate(200 * time.Millisecond)
} else {
Expand Down

0 comments on commit de9f354

Please sign in to comment.