Skip to content

Commit 27a2b02

Browse files
cwsaylorclaude
andcommitted
Fix diff pane corruption from binary file content
Binary files like .DS_Store were being read with os.ReadFile and rendered directly into the diff viewport. The raw bytes contained null bytes and control characters that corrupted the terminal's rendering state, causing the display to jumble on scroll. Add isBinary() detection (null-byte check in first 8KB, same heuristic git uses) and show "Binary file: <path>" instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 008bb4c commit 27a2b02

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.9.0] - 2026-03-22
9+
10+
### Fixed
11+
12+
- Fix diff pane corruption caused by binary file content (e.g., .DS_Store) being rendered directly to the terminal
13+
- Detect binary files using null-byte heuristic (same approach as git) and display "Binary file" message instead of raw content
14+
815
## [0.8.1] - 2026-03-19
916

1017
### Fixed

git.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ func isGitRepository(path string) bool {
8989
return err == nil
9090
}
9191

92+
// isBinary reports whether content appears to be binary by checking
93+
// for null bytes in the first 8KB (same heuristic git uses).
94+
func isBinary(data []byte) bool {
95+
n := len(data)
96+
if n > 8192 {
97+
n = 8192
98+
}
99+
for i := 0; i < n; i++ {
100+
if data[i] == 0 {
101+
return true
102+
}
103+
}
104+
return false
105+
}
106+
92107
func getFileDiff(repoPath, filePath string) (string, error) {
93108
// First try working directory changes
94109
cmd := exec.Command("git", "diff", "HEAD", "--", filePath)
@@ -113,6 +128,9 @@ func getFileDiff(repoPath, filePath string) (string, error) {
113128
if strings.HasPrefix(cleanPath, filepath.Clean(repoPath)+string(filepath.Separator)) {
114129
content, contentErr := os.ReadFile(cleanPath)
115130
if contentErr == nil {
131+
if isBinary(content) {
132+
return fmt.Sprintf("Binary file: %s", filePath), nil
133+
}
116134
return fmt.Sprintf("New file: %s\n\n%s", filePath, string(content)), nil
117135
}
118136
}
@@ -123,6 +141,9 @@ func getFileDiff(repoPath, filePath string) (string, error) {
123141
if err != nil {
124142
return "", err
125143
}
144+
if isBinary(output) {
145+
return fmt.Sprintf("Binary file: %s", filePath), nil
146+
}
126147
return string(output), nil
127148
}
128149

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
// Version is set via ldflags at build time
24-
var Version = "0.8.1"
24+
var Version = "0.9.0"
2525

2626

2727
type focusedPane int

0 commit comments

Comments
 (0)