Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
1b9d9c1
test: reproduce the GitBash selection failure on Windows (#98)
linghengqian Nov 14, 2026
a392bf2
fix: select and confirm by line in GitBash mintty (#98)
linghengqian Nov 14, 2026
2f39e7e
fix: a typed version wins over a list position in line selection (#98)
linghengqian Nov 14, 2026
bdef9d4
test: accept the -nat pipe names a real MSYS2 pty gives native progra…
linghengqian Nov 14, 2026
fea4588
Merge upstream main into fix/98-gitbash-select
linghengqian Nov 14, 2026
4138deb
test: type the answers into Git Bash in a mintty window on Windows (#98)
linghengqian Nov 14, 2026
0b38e37
test: find the mintty window by its class in the Git Bash driver (#98)
linghengqian Nov 14, 2026
2ee2b45
test: run the mintty check in both pipe and console modes (#98)
linghengqian Nov 14, 2026
04ebbc1
test: print the mintty result when the check fails (#98)
linghengqian Nov 14, 2026
1986ebd
test: cover the line selection, confirm and tty helpers the Codecov n…
linghengqian Nov 14, 2026
19d983c
fix: accept only the documented pty pipe names (#98)
linghengqian Nov 14, 2026
177c7ab
docs: say that isCygwinTerminal reports the pipe as a terminal (#98)
linghengqian Nov 14, 2026
2aa04e1
feat: arrow keys in a classic Git Bash pty, through stty raw mode (#98)
linghengqian Nov 14, 2026
a71499f
docs: the arrow keys select a version in native Git Bash (#98)
linghengqian Nov 14, 2026
1bdc01c
ci: run every workflow job only in version-fox/vfox (#98)
linghengqian Nov 14, 2026
7189418
test: give the mintty window 30 seconds, and try the launch once more…
linghengqian Nov 14, 2026
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ concurrency:

jobs:
build:
if: github.repository == 'version-fox/vfox'
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -37,6 +38,7 @@ jobs:
uses: codecov/codecov-action@v7

windows-regressions:
if: github.repository == 'version-fox/vfox'
name: Windows shell and interrupted installation regressions
runs-on: windows-latest
timeout-minutes: 15
Expand Down Expand Up @@ -65,6 +67,7 @@ jobs:
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

nushell:
if: github.repository == 'version-fox/vfox'
name: Nushell integration
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -98,6 +101,7 @@ jobs:
go test ./cmd/commands -run '^TestNushell' -count=1 -v

fish-completion:
if: github.repository == 'version-fox/vfox'
name: Fish completion integration
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/compile-inno-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:

jobs:
compile-inno-setup:
if: github.repository == 'version-fox/vfox'
name: Compile setup and publish
runs-on: windows-latest
defaults:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/compile-msix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:

jobs:
compile-msix:
if: github.repository == 'version-fox/vfox'
name: Build MSIX bundle and publish
runs-on: windows-latest
defaults:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ permissions:

jobs:
build:
if: github.repository == 'version-fox/vfox'
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -60,6 +61,7 @@ jobs:
path: docs/.vitepress/dist
# Deployment job
deploy:
if: github.repository == 'version-fox/vfox'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:

jobs:
test-windows:
if: github.repository == 'version-fox/vfox'
name: Test on Windows
runs-on: windows-latest

Expand Down Expand Up @@ -59,6 +60,7 @@ jobs:
path: ${{ runner.temp }}\.vfox

test-msix-windows:
if: github.repository == 'version-fox/vfox'
name: Test MSIX packaging on Windows
runs-on: windows-latest
timeout-minutes: 20
Expand Down Expand Up @@ -90,6 +92,7 @@ jobs:
path: msix-e2e-out

test-unix:
if: github.repository == 'version-fox/vfox'
name: Test on Unix
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -132,7 +135,7 @@ jobs:
name: Test Summary
runs-on: ubuntu-latest
needs: [test-windows, test-unix, test-msix-windows]
if: always()
if: always() && github.repository == 'version-fox/vfox'

steps:
- name: Download all artifacts
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/gitbash-mintty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Git Bash in mintty

on:
push:
pull_request:
workflow_dispatch:

jobs:
mintty:
if: github.repository == 'version-fox/vfox'
name: Select and confirm in a Git Bash mintty window
runs-on: windows-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Build the test binary
shell: pwsh
run: go test -c -o "$env:RUNNER_TEMP\commands.test.exe" ./cmd/commands
- name: Classic pseudo terminal, which reaches the program as a pipe
shell: pwsh
run: ./scripts/gitbash-mintty-test.ps1 -TestBinary "$env:RUNNER_TEMP\commands.test.exe" -WorkDir "$env:RUNNER_TEMP\gitbash-mintty-pipe" -Stdio pipe -MsysOptions disable_pcon
- name: Pseudo console, the default of the MSYS2 runtime here
if: always()
shell: pwsh
run: ./scripts/gitbash-mintty-test.ps1 -TestBinary "$env:RUNNER_TEMP\commands.test.exe" -WorkDir "$env:RUNNER_TEMP\gitbash-mintty-console" -Stdio console
1 change: 1 addition & 0 deletions .github/workflows/go-releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:

jobs:
release:
if: github.repository == 'version-fox/vfox'
runs-on: ubuntu-latest
env:
flags: ""
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ permissions:

jobs:
create-release:
if: github.repository == 'version-fox/vfox'
runs-on: ubuntu-latest
environment: production
steps:
Expand Down
58 changes: 58 additions & 0 deletions cmd/commands/choose_line_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2026 Han Li and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package commands

import (
"bytes"
"strings"
"testing"

"github.com/version-fox/vfox/internal/shared/printer"
)

func TestSelectVersionByLineReportsReadError(t *testing.T) {
var out bytes.Buffer
version, err := selectVersionByLine(failingReader{}, &out, []string{"18.20.8"}, "nodejs")
if err == nil {
t.Fatalf("selectVersionByLine() = %q, want an error for a failing read", version)
}
}

// The down arrow in raw mode, then Enter, chooses the second version.
func TestSelectVersionWithRawKeys(t *testing.T) {
var out bytes.Buffer
prompt := printer.Prompt{Input: printer.RawKeys, In: strings.NewReader("\x1b[B\r"), Out: &out}
version, err := selectVersionWith(prompt, []string{"18.20.8", "20.19.0"}, "nodejs")
if err != nil {
t.Fatalf("selectVersionWith() error: %v", err)
}
if version != "20.19.0" {
t.Errorf("selectVersionWith() = %q, want %q", version, "20.19.0")
}
}

func TestSelectVersionWithLineReadsTheChoice(t *testing.T) {
var out bytes.Buffer
prompt := printer.Prompt{Input: printer.Line, In: strings.NewReader("2\n"), Out: &out}
version, err := selectVersionWith(prompt, []string{"18.20.8", "20.19.0"}, "nodejs")
if err != nil {
t.Fatalf("selectVersionWith() error: %v", err)
}
if version != "20.19.0" {
t.Errorf("selectVersionWith() = %q, want %q", version, "20.19.0")
}
}
117 changes: 117 additions & 0 deletions cmd/commands/gitbash_mintty_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright 2026 Han Li and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package commands

import (
"encoding/binary"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"unicode/utf16"

"github.com/pterm/pterm"
"github.com/version-fox/vfox/internal/shared/printer"
"github.com/version-fox/vfox/internal/shared/util"
"golang.org/x/sys/windows"
)

// TestGitBashMinttySelection runs the terminal code in a Git Bash window: the
// test binary runs under Git for Windows' bash.exe in a mintty window, as it
// does for a person at mintty. scripts/gitbash-mintty-test.ps1 starts it and
// presses the keys. When the test waits for an answer it creates a marker file in
// VFOX_TEST_GITBASH_MINTTY_DIR, and it writes its result there too.
//
// VFOX_TEST_GITBASH_MINTTY_STDIO says what the window gives the program: "pipe"
// for a pseudo terminal that reaches it as a pipe, where the arrow keys work in
// raw mode, or "console" for a pseudo console, where the keyboard library reads
// them.
func TestGitBashMinttySelection(t *testing.T) {
dir := os.Getenv("VFOX_TEST_GITBASH_MINTTY_DIR")
if dir == "" {
t.Skip("only runs in a Git Bash mintty window, started by scripts/gitbash-mintty-test.ps1")
}
stdio := os.Getenv("VFOX_TEST_GITBASH_MINTTY_STDIO")
if stdio != "pipe" && stdio != "console" {
t.Fatalf("VFOX_TEST_GITBASH_MINTTY_STDIO = %q, want pipe or console", stdio)
}
var report strings.Builder
fmt.Fprintf(&report, "MSYS: %q\n", os.Getenv("MSYS"))
fmt.Fprintf(&report, "stdin: %s\n", gitBashHandleKind(os.Stdin.Fd()))
fmt.Fprintf(&report, "stdout: %s\n", gitBashHandleKind(os.Stdout.Fd()))
isTTY, canReadKeys := util.IsTTY(), util.CanReadKeys()
input := printer.InputFor()
fmt.Fprintf(&report, "IsTTY: %v\nCanReadKeys: %v\ninput: %v\n", isTTY, canReadKeys, input)

markWaiting(t, dir, "select")
version, selectErr := selectFromOptions([]string{"18.20.8", "20.19.0"}, "nodejs")
fmt.Fprintf(&report, "selected: %q, error: %v\n", version, selectErr)

markWaiting(t, dir, "confirm")
confirmed, confirmErr := printer.Confirm(&pterm.DefaultInteractiveConfirm, "Proceed with the check?")
fmt.Fprintf(&report, "confirmed: %v, error: %v\n", confirmed, confirmErr)

want := printer.RawKeys
if stdio == "console" {
want = printer.Keyboard
}
ok := isTTY && input == want && selectErr == nil && version == "20.19.0" && confirmErr == nil && confirmed
if err := os.WriteFile(filepath.Join(dir, "result.txt"), []byte(report.String()), 0o644); err != nil {
t.Fatal(err)
}
if !ok {
t.Errorf("Git Bash in mintty, %s:\n%s", stdio, report.String())
}
}

// markWaiting tells the driver that the test is about to wait for the answer to step.
func markWaiting(t *testing.T, dir, step string) {
t.Helper()
if err := os.WriteFile(filepath.Join(dir, step+".ready"), nil, 0o644); err != nil {
t.Fatal(err)
}
}

// gitBashHandleKind describes a standard handle: the name of a pipe, or the file type.
func gitBashHandleKind(fd uintptr) string {
fileType, err := windows.GetFileType(windows.Handle(fd))
if err != nil {
return "error: " + err.Error()
}
if fileType != windows.FILE_TYPE_PIPE {
return fmt.Sprintf("file type %d", fileType)
}
return "pipe " + gitBashPipeName(fd)
}

// gitBashPipeName returns the name of a pipe as FileNameInfo reports it.
func gitBashPipeName(fd uintptr) string {
buf := make([]byte, 4+2*260)
if err := windows.GetFileInformationByHandleEx(windows.Handle(fd), windows.FileNameInfo, &buf[0], uint32(len(buf))); err != nil {
return "error: " + err.Error()
}
size := int(binary.LittleEndian.Uint32(buf[:4]))
if size > len(buf)-4 {
size = len(buf) - 4
}
units := make([]uint16, size/2)
for i := range units {
units[i] = binary.LittleEndian.Uint16(buf[4+2*i:])
}
return string(utf16.Decode(units))
}
8 changes: 4 additions & 4 deletions cmd/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/version-fox/vfox/internal/env"
"github.com/version-fox/vfox/internal/sdk"
"github.com/version-fox/vfox/internal/shared/logger"
"github.com/version-fox/vfox/internal/shared/printer"
"github.com/version-fox/vfox/internal/shared/util"
)

Expand Down Expand Up @@ -156,7 +157,7 @@ func installCmd(ctx context.Context, cmd *cli.Command) error {
if util.IsNonInteractiveTerminal() {
return cli.Exit(fmt.Sprintf("install requires specifying a version for %s", name), 1)
}
showAvailable, _ := pterm.DefaultInteractiveConfirm.Show(fmt.Sprintf("No %s version provided, do you want to select a version to install?", pterm.Red(name)))
showAvailable, _ := printer.Confirm(&pterm.DefaultInteractiveConfirm, fmt.Sprintf("No %s version provided, do you want to select a version to install?", pterm.Red(name)))
if showAvailable {
err := RunSearch(name, []string{})
if err != nil {
Expand Down Expand Up @@ -218,9 +219,8 @@ func installAll(autoConfirm bool) error {
if util.IsNonInteractiveTerminal() {
return cli.Exit("Use the -y flag to automatically confirm installation in non-interactive environments", 1)
}
result, _ := pterm.DefaultInteractiveConfirm.
WithDefaultValue(true).
Show("Do you want to install these plugins and SDKs?")
result, _ := printer.Confirm(pterm.DefaultInteractiveConfirm.
WithDefaultValue(true), "Do you want to install these plugins and SDKs?")
if !result {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/commands/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/sdk"
"github.com/version-fox/vfox/internal/shared/printer"
"github.com/version-fox/vfox/internal/shared/util"
)

Expand Down Expand Up @@ -134,9 +135,8 @@ func linkDetected(cmd *cli.Command) error {
if util.IsNonInteractiveTerminal() {
return cli.Exit("Use the -y flag to link what was found in non-interactive environments", 1)
}
confirmed, _ := pterm.DefaultInteractiveConfirm.
WithDefaultValue(true).
Show(fmt.Sprintf("Link %d %s installation(s)?", len(candidates), name))
confirmed, _ := printer.Confirm(pterm.DefaultInteractiveConfirm.
WithDefaultValue(true), fmt.Sprintf("Link %d %s installation(s)?", len(candidates), name))
if !confirmed {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/commands/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/pterm/pterm"
"github.com/urfave/cli/v3"
"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/shared/printer"
"github.com/version-fox/vfox/internal/shared/util"
)

Expand Down Expand Up @@ -58,12 +59,11 @@ func removeCmd(ctx context.Context, cmd *cli.Command) error {
if util.IsNonInteractiveTerminal() {
return cli.Exit("Use the -y flag to skip confirmation in non-interactive environments", 1)
}
result, _ := pterm.DefaultInteractiveConfirm.
result, _ := printer.Confirm(pterm.DefaultInteractiveConfirm.
WithTextStyle(&pterm.ThemeDefault.DefaultText).
WithConfirmStyle(&pterm.ThemeDefault.DefaultText).
WithRejectStyle(&pterm.ThemeDefault.DefaultText).
WithDefaultText("Please confirm").
Show()
WithDefaultText("Please confirm"), "")
if !result {
return cli.Exit("remove canceled", 1)
}
Expand Down
Loading
Loading