Skip to content

Commit 355d8a0

Browse files
committed
Force unbuffered stderr for smoother streaming
1 parent 7f8ede1 commit 355d8a0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "autocmd-cli"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
description = "Natural language to shell command."
55
readme = "README.md"
66
requires-python = ">=3.8"

src/autocmd_cli/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def reset_autocmd() -> None:
9696
print("Reset complete.", file=sys.stderr)
9797

9898
def main() -> None:
99+
# Force unbuffered stderr
100+
if sys.stderr:
101+
sys.stderr.reconfigure(write_through=True) if hasattr(sys.stderr, 'reconfigure') else None
102+
99103
load_dotenv()
100104

101105
if len(sys.argv) > 1 and sys.argv[1] == "--reset":
@@ -127,7 +131,12 @@ def main() -> None:
127131
) as stream:
128132
full_response = ""
129133
for text in stream.text_stream:
130-
print(text, end="", flush=True, file=sys.stderr)
134+
# Write directly to buffer to bypass any text wrapper buffering
135+
if hasattr(sys.stderr, 'buffer'):
136+
sys.stderr.buffer.write(text.encode('utf-8'))
137+
sys.stderr.buffer.flush()
138+
else:
139+
print(text, end="", flush=True, file=sys.stderr)
131140
full_response += text
132141

133142
# Clear the stderr line so the final command is clean on stdout

0 commit comments

Comments
 (0)