Skip to content

Commit

Permalink
Continue 6348.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jul 21, 2024
1 parent fb6b5e3 commit 6829295
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 55 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 2024-07-21 12:25:59+01:00 - build 6351

1. Continue 6348.1.

--------------------------------------------------------------------------------
drkns 2024-07-20 21:38:24+01:00 - build 6350

Expand Down
42 changes: 21 additions & 21 deletions far/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ void CommandLine::SetPromptSize(int NewSize)
PromptSize = NewSize? std::clamp(NewSize, 5, 95) : DEFAULT_CMDLINE_WIDTH;
}

static bool ProcessFarCommands(string_view Command, function_ref<void(bool)> const ConsoleActivatior)
static bool ProcessFarCommands(string_view Command, function_ref<void()> const ConsoleActivatior)
{
inplace::trim(Command);

Expand All @@ -922,14 +922,14 @@ static bool ProcessFarCommands(string_view Command, function_ref<void(bool)> con

if (equal_icase(Command, L"config"sv))
{
ConsoleActivatior(false);
ConsoleActivatior();
Global->Opt->AdvancedConfig();
return true;
}

if (equal_icase(Command, L"about"sv))
{
ConsoleActivatior(true);
ConsoleActivatior();

std::wcout << L'\n' << build::version_string() << L'\n' << build::copyright() << L'\n';

Expand Down Expand Up @@ -985,7 +985,7 @@ static bool ProcessFarCommands(string_view Command, function_ref<void(bool)> con
{
if (const auto LogParameters = Command.substr(LogCommand.size()); LogParameters.starts_with(L' ') || LogParameters.empty())
{
ConsoleActivatior(false);
ConsoleActivatior();
logging::configure(trim(LogParameters));
return true;
}
Expand Down Expand Up @@ -1040,7 +1040,7 @@ void CommandLine::ExecString(execute_info& Info)
}
};

const auto Activator = [&](bool DoConsolise)
const auto Activator = [&]
{
if (!ExecutionContext)
ExecutionContext = Global->WindowManager->Desktop()->ConsoleSession().GetContext();
Expand All @@ -1060,7 +1060,7 @@ void CommandLine::ExecString(execute_info& Info)
if (Info.Command.empty())
{
// Just scroll the screen
Activator(false);
Activator();
console.start_output();
console.command_finished();
return;
Expand All @@ -1085,14 +1085,14 @@ void CommandLine::ExecString(execute_info& Info)

if (!ExtractIfExistCommand(Info.Command))
{
Activator(false);
Activator();
return;
}

ProcessEcho(Info);
if (Info.Command.empty())
{
Activator(false);
Activator();
return;
}

Expand All @@ -1118,7 +1118,7 @@ void CommandLine::ExecString(execute_info& Info)
IsUpdateNeeded = true;
}

bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void(bool)> const ConsoleActivatior)
bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void()> const ConsoleActivatior)
{
auto SetPanel = Global->CtrlObject->Cp()->ActivePanel();

Expand All @@ -1143,7 +1143,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void

if (Command.size() == 2 && Command[1] == L':' && Arguments.empty())
{
ConsoleActivatior(false);
ConsoleActivatior();

const auto DriveLetter = upper(CmdLine[0]);
if (!FarChDir(os::fs::drive::get_device_path(DriveLetter)))
Expand Down Expand Up @@ -1173,7 +1173,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
if (SetParams.find_first_of(L"|>"sv) != SetParams.npos)
return false;

ConsoleActivatior(true);
ConsoleActivatior();

const os::env::provider::strings EnvStrings;
for (const auto& i: enum_substrings(EnvStrings.data()))
Expand All @@ -1188,7 +1188,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
return true;
}

ConsoleActivatior(false);
ConsoleActivatior();

const auto VariableValue = SetParams.substr(pos + 1);
const auto VariableName = SetParams.substr(0, pos);
Expand Down Expand Up @@ -1216,15 +1216,15 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
return false;
}

ConsoleActivatior(false);
ClearScreen(colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN));
ConsoleActivatior();
console.Clear(colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN));
return true;
}

// PUSHD путь | ..
if (equal_icase(Command, L"PUSHD"sv))
{
ConsoleActivatior(false);
ConsoleActivatior();

const auto PushDir = m_CurDir;

Expand All @@ -1241,7 +1241,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
// TODO: добавить необязательный параметр - число, сколько уровней пропустить, после чего прыгнуть.
if (equal_icase(Command, L"POPD"sv))
{
ConsoleActivatior(false);
ConsoleActivatior();

if (!ppstack.empty())
{
Expand All @@ -1264,7 +1264,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
// CLRD
if (equal_icase(Command, L"CLRD"sv))
{
ConsoleActivatior(false);
ConsoleActivatior();

clear_and_shrink(ppstack);
os::env::del(L"FARDIRSTACK"sv);
Expand Down Expand Up @@ -1294,7 +1294,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
char_width::invalidate();
}

ConsoleActivatior(false);
ConsoleActivatior();

Text(ChcpParams);

Expand All @@ -1317,15 +1317,15 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
if (CdParams.empty())
return false;

ConsoleActivatior(false);
ConsoleActivatior();

IntChDir(CdParams, !IsCommandCd);
return true;
}

if (equal_icase(Command, L"TITLE"))
{
ConsoleActivatior(false);
ConsoleActivatior();

ConsoleTitle::SetUserTitle(Arguments);

Expand All @@ -1342,7 +1342,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
if (!from_string(Arguments, ExitCode))
LOGWARNING(L"Error parsing exit arguments: {}"sv, Arguments);

ConsoleActivatior(false);
ConsoleActivatior();
Global->WindowManager->ExitMainLoop(FALSE, ExitCode);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion far/cmdline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class CommandLine final: public SimpleScreenObject
private:
void DisplayObject() override;
size_t DrawPrompt();
bool ProcessOSCommands(string_view CmdLine, function_ref<void(bool)> ConsoleActivatior);
bool ProcessOSCommands(string_view CmdLine, function_ref<void()> ConsoleActivatior);
struct segment
{
string Text;
Expand Down
19 changes: 19 additions & 0 deletions far/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,25 @@ namespace console_detail
return true;
}

bool console::Clear(const FarColor& Color) const
{
ClearExtraRegions(Color, CR_BOTH);

point ViewportSize;
if (!GetSize(ViewportSize))
return false;

const auto ConColor = colors::FarColorToConsoleColor(Color);
const DWORD Size = ViewportSize.x * ViewportSize.y;

COORD const Coord{ 0, GetDelta() };
DWORD CharsWritten;
FillConsoleOutputCharacter(GetOutputHandle(), L' ', Size, Coord, &CharsWritten);
FillConsoleOutputAttribute(GetOutputHandle(), ConColor, Size, Coord, &CharsWritten);

return true;
}

bool console::ScrollWindow(int Lines, int Columns) const
{
bool process = false;
Expand Down
2 changes: 2 additions & 0 deletions far/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ namespace console_detail

bool ClearExtraRegions(const FarColor& Color, int Mode) const;

bool Clear(const FarColor& Color) const;

bool ScrollWindow(int Lines, int Columns = 0) const;

bool ScrollWindowToBegin() const;
Expand Down
35 changes: 16 additions & 19 deletions far/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ static void after_process_creation(
os::handle Thread,
point const& ConsoleSize,
rectangle const& ConsoleWindowRect,
function_ref<void(bool)> const ConsoleActivator,
function_ref<void()> const ConsoleActivator,
bool const UsingComspec
)
{
const auto resume_process = [&](bool const Consolise)
const auto resume_process = [&]
{
ConsoleActivator(Consolise);
ConsoleActivator();

if (Thread)
{
Expand All @@ -557,15 +557,15 @@ static void after_process_creation(
switch (WaitMode)
{
case execute_info::wait_mode::no_wait:
resume_process(false);
resume_process();
console.command_finished();
return;

case execute_info::wait_mode::if_needed:
{
const auto NeedWaiting = os::process::get_process_subsystem(Process.get()) != os::process::image_type::graphical;

resume_process(NeedWaiting);
resume_process();

if (!NeedWaiting)
{
Expand All @@ -582,7 +582,7 @@ static void after_process_creation(
return;

case execute_info::wait_mode::wait_finish:
resume_process(true);
resume_process();
Process.wait();
log_process_exit_code(Info, Process, UsingComspec);
return;
Expand Down Expand Up @@ -751,7 +751,7 @@ class external_execution_context

static bool execute_impl(
const execute_info& Info,
function_ref<void(bool)> const ConsoleActivator,
function_ref<void()> const ConsoleActivator,
string& FullCommand,
string& Command,
string& Parameters,
Expand All @@ -764,23 +764,20 @@ static bool execute_impl(
std::optional<external_execution_context> Context;
auto ConsoleActivatorInvoked = false;

const auto ExtendedActivator = [&](bool const Consolise)
const auto ExtendedActivator = [&]
{
if (Context)
return;

if (!ConsoleActivatorInvoked)
{
ConsoleActivator(Consolise);
ConsoleActivator();
ConsoleActivatorInvoked = true;
}

if (Consolise)
{
console.GetWindowRect(ConsoleWindowRect);
console.GetSize(ConsoleSize);
Context.emplace();
}
console.GetWindowRect(ConsoleWindowRect);
console.GetSize(ConsoleSize);
Context.emplace();
};

const auto execute_process = [&]
Expand All @@ -806,12 +803,12 @@ static bool execute_impl(
if (os::last_error().Win32Error == ERROR_EXE_MACHINE_TYPE_MISMATCH)
{
SCOPED_ACTION(os::last_error_guard);
ExtendedActivator(false);
ExtendedActivator();
return false;
}
}

ExtendedActivator(Info.WaitMode != execute_info::wait_mode::no_wait);
ExtendedActivator();

const auto execute_shell = [&]
{
Expand All @@ -820,7 +817,7 @@ static bool execute_impl(
return false;

if (Process)
after_process_creation(Info, os::handle(Process), Info.WaitMode, {}, ConsoleSize, ConsoleWindowRect, [](bool){}, UsingComspec);
after_process_creation(Info, os::handle(Process), Info.WaitMode, {}, ConsoleSize, ConsoleWindowRect, []{}, UsingComspec);
return true;
};

Expand All @@ -834,7 +831,7 @@ static bool execute_impl(
return execute_process() || execute_shell();
}

void Execute(execute_info& Info, function_ref<void(bool)> const ConsoleActivator)
void Execute(execute_info& Info, function_ref<void()> const ConsoleActivator)
{
// CreateProcess retardedly doesn't take into account CurrentDirectory when searching for the executable.
// SearchPath looks there as well and if it's set to something else we could get unexpected results.
Expand Down
2 changes: 1 addition & 1 deletion far/execute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

void OpenFolderInShell(string_view Folder);

void Execute(struct execute_info& Info, function_ref<void(bool)> ConsoleActivator = [](bool){});
void Execute(struct execute_info& Info, function_ref<void()> ConsoleActivator = []{});

bool ExpandOSAliases(string& FullCommand);

Expand Down
11 changes: 0 additions & 11 deletions far/interf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,17 +1180,6 @@ void SetRealColor(const FarColor& Color)
console.SetTextAttributes(Color);
}

void ClearScreen(const FarColor& Color)
{
Global->ScrBuf->FillRect({ 0, 0, ScrX, ScrY }, { L' ', {}, {}, Color });
if(Global->Opt->WindowMode)
{
console.ClearExtraRegions(Color, CR_BOTH);
}
Global->ScrBuf->Flush();
console.SetTextAttributes(Color);
}

const FarColor& GetColor()
{
return CurColor;
Expand Down
1 change: 0 additions & 1 deletion far/interf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ void SetColor(int Color);
void SetColor(PaletteColors Color);
void SetColor(const FarColor& Color);
void SetRealColor(const FarColor& Color);
void ClearScreen(const FarColor& Color);
const FarColor& GetColor();

void Box(rectangle Where, const FarColor& Color,int Type);
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6350
6351

0 comments on commit 6829295

Please sign in to comment.