Skip to content
Myr

winpty_windows.go

This file

Path

src/winpty_windows.go

80 lines · 1.7 KiB · Go

Last changed by

Not known.

History of this file

Take it

1//go:build windows23package fzf45import (6	"fmt"7	"os"8	"os/exec"9	"strings"1011	"github.com/junegunn/fzf/src/util"12)1314func isMintty345() bool {15	return util.CompareVersions(os.Getenv("TERM_PROGRAM_VERSION"), "3.4.5") >= 016}1718func needWinpty(opts *Options) bool {19	if os.Getenv("TERM_PROGRAM") != "mintty" {20		return false21	}22	if isMintty345() {23		/*24		 See: https://github.com/junegunn/fzf/issues/38092526		 "MSYS=enable_pcon" allows fzf to run properly on mintty 3.4.5 or later.27		*/28		if strings.Contains(os.Getenv("MSYS"), "enable_pcon") {29			return false30		}3132		// Setting the environment variable here unfortunately doesn't help,33		// so we need to start a child process with "MSYS=enable_pcon"34		//   os.Setenv("MSYS", "enable_pcon")35		return true36	}37	if opts.NoWinpty {38		return false39	}40	if _, err := exec.LookPath("winpty"); err != nil {41		return false42	}43	return true44}4546func runWinpty(args []string, opts *Options) (int, error) {47	argStr := escapeSingleQuote(args[0])48	for _, arg := range args[1:] {49		argStr += " " + escapeSingleQuote(arg)50	}51	argStr += ` --no-winpty`5253	if isMintty345() {54		return runProxy(argStr, func(temp string, needBash bool) (*exec.Cmd, error) {55			sh, err := sh(needBash)56			if err != nil {57				return nil, err58			}5960			cmd := exec.Command(sh, temp)61			cmd.Env = append(os.Environ(), "MSYS=enable_pcon")62			cmd.Stdin = os.Stdin63			cmd.Stdout = os.Stdout64			cmd.Stderr = os.Stderr65			return cmd, nil66		}, opts, false)67	}6869	return runProxy(argStr, func(temp string, needBash bool) (*exec.Cmd, error) {70		sh, err := sh(needBash)71		if err != nil {72			return nil, err73		}7475		cmd := exec.Command(sh, "-c", fmt.Sprintf(`winpty < /dev/tty > /dev/tty -- sh %q`, temp))76		cmd.Stdout = os.Stdout77		cmd.Stderr = os.Stderr78		return cmd, nil79	}, opts, false)80}