Skip to content

Add partial support for cygwin terminal on windows #938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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