Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: build and test
run: |
go test -race -timeout=100s -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov_tmp ./...
go test -race -timeout=180s -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov_tmp ./...
grep -v -E "_mock.go|/mocks/" $GITHUB_WORKSPACE/profile.cov_tmp > $GITHUB_WORKSPACE/profile.cov

- name: golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fmt:
~/.claude/format.sh

race:
go test -race -timeout=100s ./...
go test -race -timeout=180s ./...

version:
@echo "branch: $(BRANCH), hash: $(HASH), timestamp: $(TIMESTAMP)"
Expand Down
3 changes: 1 addition & 2 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ func loadConfigFile(iniParser *flags.IniParser, configPath string) {
if err == nil || errors.Is(err, os.ErrNotExist) {
return
}
var pathErr *os.PathError
if errors.As(err, &pathErr) {
if _, ok := errors.AsType[*os.PathError](err); ok {
return // file access error (permission denied, etc.)
}
fmt.Fprintf(os.Stderr, "warning: config %s: %v\n", configPath, err)
Expand Down
3 changes: 1 addition & 2 deletions app/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ func runVCSEnv(workDir string, env []string, binary string, args ...string) (str
cmd.Env = env
out, err := cmd.Output()
if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
return "", fmt.Errorf("%s %s: %s", binary, strings.Join(args, " "), string(exitErr.Stderr))
}
return "", fmt.Errorf("%s %s: %w", binary, strings.Join(args, " "), err)
Expand Down
3 changes: 1 addition & 2 deletions app/diff/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func NewJjDirectoryReader(workDir string) *DirectoryReader {
func (dr *DirectoryReader) ChangedFiles(_ string, _ bool) ([]FileEntry, error) {
out, err := dr.listFiles()
if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
stderr := strings.TrimSpace(string(exitErr.Stderr))
if stderr != "" {
return nil, fmt.Errorf("%s: %s", dr.listSource, stderr)
Expand Down
3 changes: 1 addition & 2 deletions app/diff/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ func readFileAsContext(path string) ([]DiffLine, error) {

lines, err := readReaderAsContext(f)
if err != nil {
var ctxErr readerContextError
if errors.As(err, &ctxErr) {
if ctxErr, ok := errors.AsType[readerContextError](err); ok {
return nil, fmt.Errorf("%s file %s: %w", ctxErr.op, path, ctxErr.err)
}
return nil, fmt.Errorf("read file %s: %w", path, err)
Expand Down
36 changes: 36 additions & 0 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/term"
"github.com/jessevdk/go-flags"
"github.com/muesli/termenv"

Expand Down Expand Up @@ -123,6 +124,22 @@ func run(opts options) (int, error) {
)

programOptions := []tea.ProgramOption{tea.WithAltScreen(), tea.WithoutSignalHandler()}
tuiOut, err := (tuiOutput{
stdout: os.Stdout,
isTerminal: term.IsTerminal,
openTTY: func() (*os.File, error) {
// stdin mode and Bubble Tea's default input fallback open a separate
// read handle; each side owns and closes its handle independently.
return os.OpenFile("/dev/tty", os.O_WRONLY, 0)
},
}).open()
if err != nil {
return 0, err
}
if tuiOut != os.Stdout {
defer func() { _ = tuiOut.Close() }()
}
programOptions = append(programOptions, tea.WithOutput(tuiOut))
if !opts.NoMouse {
programOptions = append(programOptions, tea.WithMouseCellMotion())
}
Expand Down Expand Up @@ -292,6 +309,25 @@ func run(opts options) (int, error) {
return 0, nil
}

type tuiOutput struct {
stdout *os.File
isTerminal func(uintptr) bool
openTTY func() (*os.File, error)
}

// open keeps Bubble Tea's display traffic out of redirected stdout, which is
// reserved for the final annotation stream. Terminal stdout is returned as-is.
func (r tuiOutput) open() (*os.File, error) {
if r.isTerminal(r.stdout.Fd()) {
return r.stdout, nil
}
tty, err := r.openTTY()
if err != nil {
return nil, fmt.Errorf("revdiff requires an interactive terminal for the TUI: %w", err)
}
return tty, nil
}

type finalizeReq struct {
opts options
annotations string
Expand Down
Loading