fix: add Windows compatibility for terminal width detection#132
fix: add Windows compatibility for terminal width detection#132sirmalloc merged 3 commits intosirmalloc:mainfrom
Conversation
On Windows, the Unix-specific commands (ps, stty, tput) and shell redirects (2>/dev/null) don't work and cause issues: - tput doesn't exist on Windows - 2>/dev/null creates a literal file named "null" instead of redirecting stderr This fix adds a platform check at the start of getTerminalWidth() and canDetectTerminalWidth() to use process.stdout.columns on Windows, which is the cross-platform Node.js API for this purpose. Fixes sirmalloc#117 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
@ItsDaRa Have you tested this and seen the terminal width return appropriately on Windows? The main issue has always been that Claude Code calls the statusline as a subprocess without an actual connection to the terminal Claude Code is running in, so typical width detection always returns 80. If you can verify this by adding the "terminal width" widget to your statusline and resizing the terminal and verify it updates properly, then I'll merge this and push a new build out. I don't currently have a Windows machine easily accessible. |
|
Apologizes, I didn't get any sort of notification. I'll try to test it in the next days and get back to you |
Merged PRs: - sirmalloc#138: fix: support bare repo worktrees in GitWorktree widget - sirmalloc#135: feat: add git-indicators widget - sirmalloc#132: fix: Windows terminal width detection - sirmalloc#131: feat: Task Timer widget - sirmalloc#123: feat: Add backups for settings.json - sirmalloc#121: feat: Add configurable context warning alerts - sirmalloc#120: feat: Add Mercurial support - sirmalloc#119: feat: Add Git Root Dir widget - sirmalloc#58: feat: Add support for local/project settings Fixes Issues: - sirmalloc#117: Windows tput cols creates null file - sirmalloc#122: claude's settings.json deleted/lost - sirmalloc#112: Add mercurial support Additional fixes: - Resolved circular dependency in renderer.ts/widgets.ts - Fixed lint errors in multiple files
Return null/false for win32 in terminal width helpers to keep width detection disabled on Windows and avoid Unix-style fallback paths that can create C:\dev\null.
|
I tweaked this and merged it. We can't rely on process.stdout.columns to tell us the actual columns on windows when we are invoked as a subprocess of claude code, so for now we disable terminal width detection entirely on windows. This avoids creating the empty file at c:\dev\null. |
|
All right noted. Sorry I didn't get back to you but I just can't make sense out of it. It seems like it's random, making it harder to troubleshoot, it seem to happen more often when 2 sessions opened in the same repo, but that's all I could get. If I had to bet, I would say it's on Claude Code side, more than ccstatusline itself. |
Summary
getTerminalWidth()andcanDetectTerminalWidth()insrc/utils/terminal.tsprocess.stdout.columnson Windows instead of Unix-only shell commandsProblem
On Windows, the current terminal width detection causes issues:
tputcommand doesn't existps,stty,awkare Unix-only utilities2>/dev/nullcreates a literal file named "null" in the working directory instead of suppressing stderrThis results in spurious "null" files being created wherever Claude Code is run.
Solution
Added a platform check at the start of both functions:
process.stdout.columnsis the Node.js cross-platform API for terminal width and works reliably on Windows.Test plan
Fixes #117
🤖 Generated with Claude Code