Skip to content

Commit

Permalink
add buffer flush before direct write
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman-Koshelev committed Oct 3, 2023
1 parent 5c4fc70 commit b66a57b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ extern "C" __declspec(dllimport) int __stdcall WriteConsoleW( //
FMT_FUNC bool write_console(std::FILE* f, string_view text) {
int fd = _fileno(f);
if (!_isatty(fd)) return false;
std::fflush(f);
auto u16 = utf8_to_utf16(text);
return WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)), u16.c_str(),
static_cast<dword>(u16.size()), nullptr, nullptr) != 0;
Expand Down
1 change: 1 addition & 0 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ inline bool write_ostream_unicode(std::ostream& os, fmt::string_view data) {
return false;
#endif
if (!c_file) return false;
os.flush();
return write_console(c_file, data);
}

Expand Down

0 comments on commit b66a57b

Please sign in to comment.