[FarGroup/FarManager] master: Refactoring (39b9808ec)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
May 14, 2026, 7:46:10 PM (13 days ago) May 14
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/39b9808ec508998d35913f76470f4a94c525a90e

>---------------------------------------------------------------

commit 39b9808ec508998d35913f76470f4a94c525a90e
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Fri May 15 00:42:04 2026 +0100

Refactoring


>---------------------------------------------------------------

39b9808ec508998d35913f76470f4a94c525a90e
far/console.cpp | 44 +++++++++++++++++++++++++++++---------------
far/console.hpp | 6 +++++-
far/platform.hpp | 3 +++
3 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/far/console.cpp b/far/console.cpp
index d452ee5ee..40cf879ea 100644
--- a/far/console.cpp
+++ b/far/console.cpp
@@ -726,8 +726,6 @@ protected:
m_StreamBuf(std::make_unique<consolebuf>(GetStdHandle(STD_OUTPUT_HANDLE))),
m_StreamBuffersOverrider(std::make_unique<stream_buffers_overrider>())
{
- if (get_run_mode() == run_mode::interactive)
- m_ExternalConsole = std::make_unique<external_console>();
}

bool console::Allocate() const
@@ -1300,6 +1298,22 @@ protected:
return Result;
}

+ void console::load_external() const
+ {
+ if (m_ExternalConsole)
+ return;
+
+ m_ExternalConsole = get_run_mode() == run_mode::interactive?
+ std::make_unique<external_console>() :
+ nullptr;
+ }
+
+ auto console::get_external(auto const Accessor) const
+ {
+ load_external();
+ return m_ExternalConsole && *m_ExternalConsole? std::invoke(Accessor, (*m_ExternalConsole)->Imports).value() : nullptr;
+ }
+
bool console::PeekOneInput(INPUT_RECORD& Record) const
{
// See below
@@ -1410,11 +1424,11 @@ protected:

bool console::ReadOutput(matrix<FAR_CHAR_INFO>& Buffer, point const BufferCoord, rectangle const& ReadRegionRelative) const
{
- if (m_ExternalConsole && m_ExternalConsole->Imports.pReadOutput)
+ if (const auto ReadOutputExternal = get_external(&external_console::ModuleImports::pReadOutput))
{
const COORD BufferSize{ static_cast<short>(Buffer.width()), static_cast<short>(Buffer.height()) };
auto ReadRegion = make_rect(ReadRegionRelative);
- return m_ExternalConsole->Imports.pReadOutput(Buffer.data(), BufferSize, make_coord(BufferCoord), &ReadRegion) != FALSE;
+ return ReadOutputExternal(Buffer.data(), BufferSize, make_coord(BufferCoord), &ReadRegion) != FALSE;
}

const int Delta = sWindowMode? GetDelta() : 0;
@@ -2372,11 +2386,11 @@ protected:
return implementation::WriteOutputVT(Buffer, BufferCoord, WriteRegion);
}

- if (m_ExternalConsole && m_ExternalConsole->Imports.pWriteOutput)
+ if (const auto WriteOutputExternal = get_external(&external_console::ModuleImports::pWriteOutput))
{
const COORD BufferSize{ static_cast<short>(Buffer.width()), static_cast<short>(Buffer.height()) };
auto WriteRegion = make_rect(WriteRegionRelative);
- return m_ExternalConsole->Imports.pWriteOutput(Buffer.data(), BufferSize, make_coord(BufferCoord), &WriteRegion) != FALSE;
+ return WriteOutputExternal(Buffer.data(), BufferSize, make_coord(BufferCoord), &WriteRegion) != FALSE;
}

const int Delta = sWindowMode? GetDelta() : 0;
@@ -2467,8 +2481,8 @@ protected:

bool console::Commit() const
{
- if (m_ExternalConsole && m_ExternalConsole->Imports.pCommit)
- return m_ExternalConsole->Imports.pCommit() != FALSE;
+ if (const auto CommitExternal = get_external(&external_console::ModuleImports::pCommit))
+ return CommitExternal() != FALSE;

// reserved
return true;
@@ -2476,8 +2490,8 @@ protected:

bool console::GetTextAttributes(FarColor& Attributes) const
{
- if (m_ExternalConsole && m_ExternalConsole->Imports.pGetTextAttributes)
- return m_ExternalConsole->Imports.pGetTextAttributes(&Attributes) != FALSE;
+ if (const auto GetTextAttributesExternal = get_external(&external_console::ModuleImports::pGetTextAttributes))
+ return GetTextAttributesExternal(&Attributes) != FALSE;

CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo;
if (!get_console_screen_buffer_info(GetOutputHandle(), &ConsoleScreenBufferInfo))
@@ -2489,8 +2503,8 @@ protected:

bool console::SetTextAttributes(const FarColor& Attributes) const
{
- if (m_ExternalConsole && m_ExternalConsole->Imports.pSetTextAttributes)
- return m_ExternalConsole->Imports.pSetTextAttributes(&Attributes) != FALSE;
+ if (const auto SetTextAttributesExternal = get_external(&external_console::ModuleImports::pSetTextAttributes))
+ return SetTextAttributesExternal(&Attributes) != FALSE;

return (IsVtActive()? implementation::SetTextAttributesVT : implementation::SetTextAttributesNT)(Attributes);
}
@@ -2758,8 +2772,8 @@ protected:

bool console::ClearExtraRegions(const FarColor& Color, int Mode) const
{
- if (m_ExternalConsole && m_ExternalConsole->Imports.pClearExtraRegions)
- return m_ExternalConsole->Imports.pClearExtraRegions(&Color, Mode) != FALSE;
+ if (const auto ClearExtraRegionsExternal = get_external(&external_console::ModuleImports::pClearExtraRegions))
+ return ClearExtraRegionsExternal(&Color, Mode) != FALSE;

CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!get_console_screen_buffer_info(GetOutputHandle(), &csbi))
@@ -3064,7 +3078,7 @@ protected:

bool console::ExternalRendererLoaded() const
{
- return m_ExternalConsole && m_ExternalConsole->Imports.pWriteOutput;
+ return get_external(&external_console::ModuleImports::pWriteOutput) != nullptr;
}

size_t console::GetWidthPreciseExpensive(string_view const Str)
diff --git a/far/console.hpp b/far/console.hpp
index b1c8371e9..965d0c882 100644
--- a/far/console.hpp
+++ b/far/console.hpp
@@ -244,6 +244,10 @@ namespace console_detail

std::optional<KEY_EVENT_RECORD> queued() const;

+ void load_external() const;
+
+ auto get_external(auto Accessor) const;
+
HANDLE m_OriginalInputHandle;
HANDLE m_ActiveConsoleScreenBuffer{};
mutable string m_Title;
@@ -259,7 +263,7 @@ namespace console_detail
KEY_EVENT_RECORD mutable m_QueuedKeys{};

class external_console;
- std::unique_ptr<external_console> m_ExternalConsole;
+ mutable std::optional<std::unique_ptr<external_console>> m_ExternalConsole;
};
}

diff --git a/far/platform.hpp b/far/platform.hpp
index 824646ee7..62c0181c3 100644
--- a/far/platform.hpp
+++ b/far/platform.hpp
@@ -408,6 +408,9 @@ namespace os

[[nodiscard]]
explicit(false) operator raw_function_pointer() const { return std::bit_cast<raw_function_pointer>(get_pointer(true)); }
+
+ [[nodiscard]]
+ raw_function_pointer value() const { return std::bit_cast<raw_function_pointer>(get_pointer(false)); }
};
}



Reply all
Reply to author
Forward
0 new messages