Skip to content

Go core - Windows config paths and TTY reattach #2

Description

@shtirlitsDva

Task: Go core — Windows config paths and TTY reattach

Description

Two surgical Go fixes that together unblock revdiff on Windows. Both touch cmd/revdiff/main.go and are bundled into one task to avoid merge conflicts on that file.

Fix 1 — TTY reattach for --stdin mode. cmd/revdiff/main.go:329 hardcodes os.Open("/dev/tty"). On Windows the equivalent is os.Open("CONIN$"). Split the call site behind a build-tagged helper so each platform compiles cleanly.

Fix 2 — Config/themes/keybindings paths on Windows. defaultConfigPath() (line 272), defaultKeysPath() (line 300), and defaultThemesDir() (line 520) all build paths under ~/.config/revdiff/. On Windows, route through os.UserConfigDir() (returns %APPDATA%) so configs land at %APPDATA%\revdiff\. Unix paths are unchanged — macOS users currently using ~/.config/revdiff/ see no behavior shift.

Acceptance Criteria

  • cmd/revdiff/tty_unix.go created with //go:build !windows constraint and a single exported openInteractiveTTY() (*os.File, error) returning os.Open("/dev/tty").
  • cmd/revdiff/tty_windows.go created with //go:build windows constraint and the same signature returning os.Open("CONIN$").
  • openTTY() in cmd/revdiff/main.go (lines 328–334) is replaced/refactored to call openInteractiveTTY() so the hardcoded /dev/tty literal is gone from main.go.
  • defaultConfigPath(), defaultKeysPath(), defaultThemesDir() consult runtime.GOOS. On windows they use os.UserConfigDir() joined with revdiff/<config|keybindings|themes>. On all other platforms they keep returning the existing filepath.Join(home, ".config", "revdiff", ...) paths verbatim.
  • cmd/revdiff/main_test.go covers both branches: existing tests still pass on Unix, new tests verify the Windows branch (use injected runtime.GOOS or build-tag a sibling test file main_windows_test.go).
  • go build ./cmd/revdiff succeeds on both Linux and Windows (validated via GOOS=linux go build and GOOS=windows go build from any host).
  • go test ./... passes on Linux/macOS with no behavior change.
  • --dump-config on Windows shows paths under %APPDATA%\revdiff\; on Unix shows ~/.config/revdiff/.
  • No new entries in go.mod — only standard library (os, runtime, path/filepath) used.
  • No //nolint directives required.

Technical Details

Files to create

  • cmd/revdiff/tty_unix.go — ~10 lines, build tag //go:build !windows.
  • cmd/revdiff/tty_windows.go — ~10 lines, build tag //go:build windows.

Files to modify

  • cmd/revdiff/main.go — replace the body of openTTY() (or inline its callers) to use openInteractiveTTY(). Add runtime.GOOS == "windows" branch to the three default-path helpers. The os.UserConfigDir() call should be the only Windows-specific addition; everything else stays in runtime.GOOS == "windows" arms.
  • cmd/revdiff/main_test.go — add table-driven tests for the path helpers covering both windows and linux/darwin GOOS values. If using a real runtime.GOOS (not injected), build-tag a sibling file main_paths_windows_test.go for the Windows-only assertions.

Implementation notes

  • Prefer dependency injection (a goosFn func() string package var) over runtime.GOOS directly so tests can drive both branches without build tags. Default the var to func() string { return runtime.GOOS } and override in tests.
  • os.UserConfigDir() returns %APPDATA% on Windows (e.g., C:\Users\you\AppData\Roaming). Joining with "revdiff" gives C:\Users\you\AppData\Roaming\revdiff. Use filepath.Join, never string concat.
  • Per CLAUDE.md, on Unix the existing ~/.config/revdiff/ layout must be preserved exactly — do not switch macOS to ~/Library/Application Support/revdiff/.
  • openInteractiveTTY() is a tiny helper; do not export it from another package — keep it in package main.
  • The PowerShell launcher (task 003) and the validation step (task 006) depend on the --dump-config output reflecting the new paths. Confirm via revdiff.exe --dump-config after building.

Audit references (line numbers from initial scan, may drift slightly)

  • cmd/revdiff/main.go:272defaultConfigPath
  • cmd/revdiff/main.go:300defaultKeysPath
  • cmd/revdiff/main.go:329 — hardcoded /dev/tty open
  • cmd/revdiff/main.go:520defaultThemesDir
  • cmd/revdiff/main_test.go:425–426 — existing path tests to update

Dependencies

  • None. This task can start immediately.
  • Blocks meaningful validation in tasks 002, 003, 004, 005, 006 (they need a working revdiff.exe to test against), but does not block their creation.

Effort Estimate

  • Size: S
  • Scope: ~50 lines of Go across 3 files + ~30 lines of test. Single PR.

Definition of Done

  • Code implemented per acceptance criteria
  • Tests written and passing on both Unix and Windows branches
  • make test (Unix) green
  • Code reviewed
  • No regressions in existing --dump-config / --init-themes / --list-themes flows on macOS or Linux

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

epic:windows-supportBelongs to the windows-support epicin-progressWork has started on this issuetaskTask within an epic

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions