Skip to content

Commit

Permalink
Continue 6424
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Feb 1, 2025
1 parent b022d5e commit 5f98e7d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 2025-02-01 02:10:34+00:00 - build 6425

1. Continue 6424.

--------------------------------------------------------------------------------
drkns 2025-02-01 00:27:00+00:00 - build 6424

Expand Down
26 changes: 16 additions & 10 deletions far/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,20 @@ namespace console_detail
BufferSize = 8192
};

static bool is_redirected(int const HandleType)
static bool is_redirected(HANDLE const Handle)
{
DWORD Mode;
return !GetConsoleMode(GetStdHandle(HandleType), &Mode);
return !GetConsoleMode(Handle, &Mode);
}

class consolebuf final: public std::wstreambuf
{
public:
NONCOPYABLE(consolebuf);

explicit(false) consolebuf(int const Type):
m_Type(Type),
m_Redirected(is_redirected(Type)),
explicit(false) consolebuf(HANDLE const Handle):
m_Handle(Handle),
m_Redirected(is_redirected(m_Handle)),
m_InBuffer(BufferSize, {}),
m_OutBuffer(BufferSize, {})
{
Expand Down Expand Up @@ -395,7 +395,7 @@ namespace console_detail
if (m_Redirected)
{
DWORD BytesRead;
if (!ReadFile(GetStdHandle(m_Type), Str.data(), static_cast<DWORD>(Str.size() * sizeof(wchar_t)), &BytesRead, {}))
if (!ReadFile(m_Handle, Str.data(), static_cast<DWORD>(Str.size() * sizeof(wchar_t)), &BytesRead, {}))
throw far_fatal_exception(L"File read error"sv);

return BytesRead / sizeof(wchar_t);
Expand All @@ -418,7 +418,7 @@ namespace console_detail
const auto write = [&](void const* Data, size_t const Size)
{
DWORD BytesWritten;
if (!WriteFile(GetStdHandle(m_Type), Data, static_cast<DWORD>(Size), &BytesWritten, {}))
if (!WriteFile(m_Handle, Data, static_cast<DWORD>(Size), &BytesWritten, {}))
throw far_fatal_exception(L"File write error"sv);
};

Expand Down Expand Up @@ -454,14 +454,14 @@ namespace console_detail
{
if (m_Redirected)
{
FlushFileBuffers(GetStdHandle(m_Type));
FlushFileBuffers(m_Handle);
return;
}

::console.Commit();
}

int m_Type;
HANDLE m_Handle;
bool m_Redirected;
string m_InBuffer, m_OutBuffer;
std::optional<FarColor> m_Colour;
Expand All @@ -473,7 +473,7 @@ namespace console_detail
NONCOPYABLE(stream_buffer_overrider);

stream_buffer_overrider(std::wios& Stream, int const HandleType, std::optional<FarColor> const Color = {}):
m_Buf(HandleType),
m_Buf(GetStdHandle(HandleType)),
m_Override(Stream, m_Buf)
{
if (Color)
Expand Down Expand Up @@ -672,6 +672,7 @@ namespace console_detail

console::console():
m_OriginalInputHandle(GetStdHandle(STD_INPUT_HANDLE)),
m_StreamBuf(std::make_unique<consolebuf>(GetStdHandle(STD_OUTPUT_HANDLE))),
m_StreamBuffersOverrider(std::make_unique<stream_buffers_overrider>())
{
placement::construct(ExternalConsole);
Expand Down Expand Up @@ -2802,6 +2803,11 @@ namespace console_detail
return std::ranges::any_of(m_Buffer | std::views::take(EventsRead), Predicate);
}

std::wostream& console::OriginalOutputStream()
{
return m_OutputStream;
}

bool console::ScrollScreenBuffer(rectangle const& ScrollRectangle, point DestinationOrigin, const FAR_CHAR_INFO& Fill) const
{
const CHAR_INFO SysFill{ { Fill.Char }, colors::FarColorToConsoleColor(Fill.Attributes) };
Expand Down
6 changes: 6 additions & 0 deletions far/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ namespace console_detail
std::vector<INPUT_RECORD> m_Buffer{ 256 };
};

[[nodiscard]]
std::wostream& OriginalOutputStream();

private:
class implementation;
friend class implementation;
Expand All @@ -247,6 +250,9 @@ namespace console_detail
HANDLE m_ActiveConsoleScreenBuffer{};
mutable string m_Title;

std::unique_ptr<std::wstreambuf> m_StreamBuf;
std::wostream m_OutputStream{ m_StreamBuf.get() };

class stream_buffers_overrider;
std::unique_ptr<stream_buffers_overrider> m_StreamBuffersOverrider;

Expand Down
2 changes: 1 addition & 1 deletion far/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ namespace
{
try
{
sink_console::process(console.GetOutputHandle(), Message);
console.OriginalOutputStream() << far::format(L"[{}][{}][{}] {} [{}]"sv, Message.m_Time, Message.m_ThreadId, Message.m_LevelString, Message.m_Data, Message.m_Location) << std::endl;
}
catch (far_exception const& e)
{
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6424
6425

0 comments on commit 5f98e7d

Please sign in to comment.