Skip to content
Open
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
10 changes: 8 additions & 2 deletions wechat_cli/output/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

def output_json(data, file=None):
file = file or sys.stdout
json.dump(data, file, ensure_ascii=False, indent=2)
file.write('\n')
# Encode to UTF-8 bytes to avoid encoding issues on Windows
json_str = json.dumps(data, ensure_ascii=False, indent=2) + '\n'
if hasattr(file, 'buffer'):
# Write bytes directly to binary buffer for proper UTF-8 encoding
file.buffer.write(json_str.encode('utf-8'))
else:
# Fallback for file objects without buffer attribute
file.write(json_str)


def output_text(text, file=None):
Expand Down