Skip to content

Commit

Permalink
Merge pull request #477 from o-sdn-o/vt-input-mode
Browse files Browse the repository at this point in the history
Add $VTM to the child process's environment block
  • Loading branch information
o-sdn-o authored Nov 19, 2023
2 parents affcba8 + 0b4df26 commit 93520ad
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
8 changes: 5 additions & 3 deletions src/netxs/apps/desk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ namespace netxs::app::desk
{
boss.base::hidden = true;
auto data_src_shadow = ptr::shadow(data_src);
item_area->LISTEN(tier::release, e2::form::state::mouse, state, -)
item_area->LISTEN(tier::release, e2::form::state::mouse, hover, -)
{
if (disabled) return;
if (boss.base::hidden != !state)
boss.RISEUP(tier::request, events::ui::toggle, unfolded, ());
auto hidden = !unfolded || !hover;
if (boss.base::hidden != hidden)
{
boss.base::hidden = !state;
boss.base::hidden = hidden;
boss.base::reflow();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace netxs::app

namespace netxs::app::shared
{
static const auto version = "v0.9.24";
static const auto version = "v0.9.25";
static const auto ipc_prefix = "vtm";
static const auto log_suffix = "_log";
static const auto usr_config = "~/.config/vtm/settings.xml"s;
Expand Down
10 changes: 8 additions & 2 deletions src/netxs/desktopio/consrv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,18 @@ struct consrv
nullptr,
nullptr);
auto wide_cmdline = utf::to_utf(cmdline);
auto env_ptr = ::GetEnvironmentStringsW(); // Add $VTM=1 to environment block.
auto new_env = [&](auto i){ while (*i++ || *i) { } return wide{ env_ptr, (size_t)(i - env_ptr) }; }(env_ptr);
if (utf::divide(utf::to_utf(new_env), '\0', [&](auto v){ return !v.starts_with("VTM="); })) new_env += L"VTM=1\0"s;
::FreeEnvironmentStringsW(env_ptr);
auto ret = ::CreateProcessW(nullptr, // lpApplicationName
wide_cmdline.data(), // lpCommandLine
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
TRUE, // bInheritHandles
EXTENDED_STARTUPINFO_PRESENT, // dwCreationFlags (override startupInfo type)
nullptr, // lpEnvironment
EXTENDED_STARTUPINFO_PRESENT | // dwCreationFlags (override startupInfo type)
CREATE_UNICODE_ENVIRONMENT, // Environment block in UTF-16.
new_env.data(), // lpEnvironment
cwd.size() ? utf::to_utf(cwd).c_str()// lpCurrentDirectory
: nullptr,
&startinf.StartupInfo, // lpStartupInfo (ptr to STARTUPINFOEX)
Expand Down Expand Up @@ -5236,6 +5241,7 @@ struct consrv : ipc::stdcon
"rc4: ", rc4.value, " errcode: ", rc4.error, "\n"
"fds: ", fds.value, " errcode: ", fds.error);
}
os::env::set("VTM", "1");
os::env::set("TERM", "xterm-256color");
os::env::set("COLORTERM", "truecolor");
os::process::spawn(cwd, cmdline);
Expand Down
31 changes: 18 additions & 13 deletions src/netxs/desktopio/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2299,17 +2299,22 @@ namespace netxs::os
auto cmdarg = utf::to_utf(utf::concat(os::process::binary(), " --onlylog", " -p ", prefix, " -c :", ospath, " -s"));
auto proinf = PROCESS_INFORMATION{};
auto upinfo = STARTUPINFOEXW{ sizeof(STARTUPINFOEXW) };
auto rc = ::CreateProcessW(nullptr, // lpApplicationName
cmdarg.data(), // lpCommandLine
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
TRUE, // bInheritHandles
DETACHED_PROCESS | // dwCreationFlags
EXTENDED_STARTUPINFO_PRESENT, // override startupInfo type
nullptr, // lpEnvironment
nullptr, // lpCurrentDirectory
&upinfo.StartupInfo, // lpStartupInfo
&proinf); // lpProcessInformation
auto ptoken = os::invalid_fd;
auto slzero = DWORD{ 0 };
auto rc = ::OpenProcessToken(::GetCurrentProcess(), TOKEN_ALL_ACCESS, &ptoken);
rc = rc && ::CreateProcessAsUserW(ptoken,
nullptr, // lpApplicationName
cmdarg.data(), // lpCommandLine
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
TRUE, // bInheritHandles
DETACHED_PROCESS | // dwCreationFlags
EXTENDED_STARTUPINFO_PRESENT, // override startupInfo type
nullptr, // lpEnvironment
nullptr, // lpCurrentDirectory
&upinfo.StartupInfo, // lpStartupInfo
&proinf); // lpProcessInformation
os::close(ptoken);
auto success = std::unique_ptr<std::remove_pointer<fd_t>::type, decltype(&::CloseHandle)>(handle, &::CloseHandle); // Do not close until confirmation from the child process is received.
if (rc) // Success. The fork concept is not supported on Windows.
{
Expand Down Expand Up @@ -2347,7 +2352,7 @@ namespace netxs::os
#endif

if (success) log(prompt::os, "Process forked");
else os::fail("Can't fork process");
else os::fail("Failed to fork process");

return std::pair{ std::move(success), faux }; // Parent branch.
}
Expand Down Expand Up @@ -4931,7 +4936,7 @@ namespace netxs::os
os::stdout_fd = saved_fd;
if (ok(::SetConsoleActiveScreenBuffer(os::stdout_fd), "::SetConsoleActiveScreenBuffer()", os::unexpected))
{
if (s != dtvt::consize()) // wt issue GH #16231
if (!(dtvt::vtmode & ui::console::nt16) && s != dtvt::consize()) // wt issue GH #16231
{
std::cout << prompt::os << ansi::err("Terminal is out of sync. See https://github.com/microsoft/terminal/issues/16231 for details.") << "\n";
}
Expand Down
12 changes: 6 additions & 6 deletions src/netxs/desktopio/utf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,12 +1113,12 @@ namespace netxs::utf
auto frag = view{ utf8.data() + cur, pos - cur };
if constexpr (SkipEmpty) if (frag.empty()) { cur = pos + 1; continue; }
if constexpr (Plain) proc(frag);
else if (!proc(frag)) return;
else if (!proc(frag)) return faux;
cur = pos + 1;
}
auto end = view{ utf8.data() + cur, utf8.size() - cur };
if constexpr (SkipEmpty) if (end.empty()) return;
proc(end);
if constexpr (SkipEmpty) if (end.empty()) return true;
return proc(end);
}
else
{
Expand All @@ -1130,12 +1130,12 @@ namespace netxs::utf
auto frag = view{ utf8.data() + next, cur - next };
if constexpr (SkipEmpty) if (frag.empty()) { cur = pos; continue; }
if constexpr (Plain) proc(frag);
else if (!proc(frag)) return;
else if (!proc(frag)) return faux;
cur = pos;
}
auto end = view{ utf8.data(), cur };
if constexpr (SkipEmpty) if (end.empty()) return;
proc(end);
if constexpr (SkipEmpty) if (end.empty()) return true;
return proc(end);
}
}
template<feed Dir = feed::fwd, bool SkipEmpty = faux, class V1, class V2>
Expand Down

0 comments on commit 93520ad

Please sign in to comment.