Skip to content

Commit 05d1960

Browse files
committed
Merge branch 'dev'
2 parents a4a8c70 + fd8552c commit 05d1960

23 files changed

Lines changed: 303 additions & 68 deletions

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ namespace vix::commands::RunCommand::detail
111111
#endif
112112
}
113113

114-
#ifndef _WIN32
115114
struct LiveRunResult
116115
{
117-
int rawStatus = 0; // waitpid status
118-
int exitCode = 0; // normalized 0..255 or 128+signal
116+
int rawStatus = 0;
117+
int exitCode = 0;
119118
std::string stdoutText;
120119
std::string stderrText;
121120
bool failureHandled = false;
@@ -130,7 +129,6 @@ namespace vix::commands::RunCommand::detail
130129
const std::string &spinnerLabel,
131130
bool passthroughRuntime,
132131
int timeoutSec = 0);
133-
#endif
134132

135133
// Script mode (vix run foo.cpp)
136134
std::filesystem::path get_scripts_root();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#if defined(_WIN32)
4+
#ifndef WIN32_LEAN_AND_MEAN
5+
#define WIN32_LEAN_AND_MEAN
6+
#endif
7+
#ifndef NOMINMAX
8+
#define NOMINMAX
9+
#endif
10+
#include <windows.h>
11+
#endif

include/vix/cli/util/Shell.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
#include <cstdlib>
55
#include <string>
6+
#include <vix/utils/Env.hpp>
67

78
namespace vix::cli::util
89
{
910
inline bool debug_enabled()
1011
{
11-
const char *v = std::getenv("VIX_DEBUG");
12+
const char *v = vix::utils::vix_getenv("VIX_DEBUG");
1213
if (!v)
1314
return false;
1415

src/cmake/CMakeBuild.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <vix/cli/util/Fs.hpp>
2323
#include <vix/cli/util/Strings.hpp>
2424

25+
#include <vix/utils/Env.hpp>
26+
2527
#ifndef _WIN32
2628
#include <fcntl.h>
2729
#include <sys/wait.h>
@@ -248,7 +250,7 @@ namespace vix::cli::build
248250
{
249251
if (quiet)
250252
return false;
251-
const char *v = std::getenv("VIX_BUILD_HEARTBEAT");
253+
const char *v = vix::utils::vix_getenv("VIX_BUILD_HEARTBEAT");
252254
if (!v)
253255
return false;
254256

src/commands/AddCommand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <vix/cli/util/Shell.hpp>
1616
#include <vix/cli/util/Ui.hpp>
1717
#include <vix/cli/Style.hpp>
18-
18+
#include <vix/utils/Env.hpp>
1919
#include <nlohmann/json.hpp>
2020

2121
#include <algorithm>
@@ -38,9 +38,9 @@ namespace vix::commands
3838
std::string home_dir()
3939
{
4040
#ifdef _WIN32
41-
const char *home = std::getenv("USERPROFILE");
41+
const char *home = vix::utils::vix_getenv("USERPROFILE");
4242
#else
43-
const char *home = std::getenv("HOME");
43+
const char *home = vix::utils::vix_getenv("HOME");
4444
#endif
4545
return home ? std::string(home) : std::string();
4646
}

src/commands/DepsCommand.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <vix/cli/util/Ui.hpp>
1616
#include <vix/cli/util/Shell.hpp>
1717
#include <vix/cli/Style.hpp>
18+
#include <vix/utils/Env.hpp>
1819

1920
#include <nlohmann/json.hpp>
2021

@@ -38,9 +39,9 @@ namespace vix::commands
3839
static std::string home_dir()
3940
{
4041
#ifdef _WIN32
41-
const char *home = std::getenv("USERPROFILE");
42+
const char *home = vix::utils::vix_getenv("USERPROFILE");
4243
#else
43-
const char *home = std::getenv("HOME");
44+
const char *home = vix::utils::vix_getenv("HOME");
4445
#endif
4546
return home ? std::string(home) : std::string();
4647
}

src/commands/InstallCommand.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#include <vix/cli/commands/InstallCommand.hpp>
4040
#include <vix/cli/Style.hpp>
41-
41+
#include <vix/utils/Env.hpp>
4242
#include <nlohmann/json.hpp>
4343

4444
#include <filesystem>
@@ -54,10 +54,10 @@
5454
#include <vector>
5555

5656
#ifndef _WIN32
57-
#include <cctype> // std::isspace
58-
#include <cstdio> // popen, pclose, fgets
59-
#include <cstdlib> // std::system, std::getenv
60-
#include <unistd.h> // getpid
57+
#include <cctype>
58+
#include <cstdio>
59+
#include <cstdlib>
60+
#include <unistd.h>
6161
#else
6262
#include <cctype>
6363
#include <cstdlib>
@@ -145,7 +145,7 @@ namespace
145145

146146
std::string env_or_empty(const char *name)
147147
{
148-
const char *v = std::getenv(name);
148+
const char *v = vix::utils::vix_getenv(name);
149149
if (v && *v)
150150
return std::string(v);
151151
return {};
@@ -639,7 +639,7 @@ namespace
639639

640640
if (!sopt.pubkey.has_value())
641641
{
642-
const char *home = std::getenv("HOME");
642+
const char *home = vix::utils::vix_getenv("HOME");
643643
if (home && *home)
644644
{
645645
const fs::path p1 = fs::path(home) / ".config" / "vix" / "keys" / "vix-pack.pub";

src/commands/NewCommand.cpp

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
* Vix.cpp
1212
*
1313
*/
14+
#if defined(_WIN32)
15+
#include <vix/platform/windows.hpp>
16+
#endif
17+
1418
#include <vix/cli/commands/NewCommand.hpp>
1519
#include <vix/cli/Style.hpp>
1620
#include <vix/cli/Utils.hpp>
21+
#include <vix/utils/Env.hpp>
1722

1823
#include <algorithm>
1924
#include <atomic>
@@ -178,13 +183,13 @@ int main()
178183

179184
static bool is_noninteractive_env()
180185
{
181-
if (const char *v = std::getenv("VIX_NONINTERACTIVE"))
186+
if (const char *v = vix::utils::vix_getenv("VIX_NONINTERACTIVE"))
182187
{
183188
const std::string s = v;
184189
if (!s.empty() && s != "0" && s != "false" && s != "FALSE")
185190
return true;
186191
}
187-
if (std::getenv("CI") != nullptr)
192+
if (vix::utils::vix_getenv("CI") != nullptr)
188193
return true;
189194

190195
return false;
@@ -410,8 +415,82 @@ int main()
410415
static Key read_key()
411416
{
412417
#if defined(_WIN32)
413-
// ... (ton code Windows inchangé)
418+
// -------- Windows (Console Input) --------
419+
HANDLE hIn = ::GetStdHandle(STD_INPUT_HANDLE);
420+
if (hIn == INVALID_HANDLE_VALUE || hIn == nullptr)
421+
return Key::None;
422+
423+
while (true)
424+
{
425+
if (g_cancelled.load())
426+
return Key::CtrlC;
427+
428+
DWORD pending = 0;
429+
if (!::GetNumberOfConsoleInputEvents(hIn, &pending))
430+
return Key::None;
431+
432+
if (pending == 0)
433+
{
434+
::Sleep(50); // keep responsive
435+
continue;
436+
}
437+
438+
INPUT_RECORD rec{};
439+
DWORD readCount = 0;
440+
if (!::ReadConsoleInputW(hIn, &rec, 1, &readCount) || readCount != 1)
441+
continue;
442+
443+
if (rec.EventType != KEY_EVENT)
444+
continue;
445+
446+
const KEY_EVENT_RECORD &k = rec.Event.KeyEvent;
447+
448+
// only handle key DOWN
449+
if (!k.bKeyDown)
450+
continue;
451+
452+
// Ctrl+C detection (either control state or ascii 3)
453+
const bool ctrlDown = (k.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) != 0;
454+
455+
// Virtual keys first (arrows, enter, escape)
456+
switch (k.wVirtualKeyCode)
457+
{
458+
case VK_UP:
459+
return Key::Up;
460+
case VK_DOWN:
461+
return Key::Down;
462+
case VK_RETURN:
463+
return Key::Enter;
464+
case VK_ESCAPE:
465+
return Key::Escape;
466+
default:
467+
break;
468+
}
469+
470+
// Character-based mapping
471+
const wchar_t ch = k.uChar.UnicodeChar;
472+
473+
if (ctrlDown && (ch == L'c' || ch == L'C'))
474+
return Key::CtrlC;
475+
476+
if (ch == 3) // ETX (rare here, but safe)
477+
return Key::CtrlC;
478+
479+
if (ch == L' ')
480+
return Key::Space;
481+
482+
if (ch == L'a' || ch == L'A')
483+
return Key::ToggleAll;
484+
485+
if (ch == L'q' || ch == L'Q')
486+
return Key::Quit;
487+
488+
// unknown key -> ignore
489+
return Key::None;
490+
}
491+
return Key::None;
414492
#else
493+
// -------- Unix (poll/read) --------
415494
while (true)
416495
{
417496
if (g_cancelled.load())
@@ -421,11 +500,9 @@ int main()
421500
pfd.fd = STDIN_FILENO;
422501
pfd.events = POLLIN;
423502

424-
// timeout 50ms to stay responsive to Ctrl+C
425503
const int r = ::poll(&pfd, 1, 50);
426504
if (r < 0)
427505
{
428-
// EINTR: interrupted by signal -> treat as cancel if SIGINT
429506
if (g_cancelled.load())
430507
return Key::CtrlC;
431508
continue;
@@ -456,7 +533,6 @@ int main()
456533
unsigned char s1 = 0;
457534
unsigned char s2 = 0;
458535

459-
// If escape alone -> return Escape quickly (do NOT block)
460536
pollfd p2{};
461537
p2.fd = STDIN_FILENO;
462538
p2.events = POLLIN;

src/commands/OrmCommand.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111
* Vix.cpp
1212
*
1313
*/
14+
#if defined(_WIN32)
15+
#include <vix/platform/windows.hpp>
16+
#endif
17+
1418
#include <vix/cli/commands/OrmCommand.hpp>
19+
#include <vix/utils/Env.hpp>
1520
#include <iostream>
1621
#include <cstdlib>
1722
#include <filesystem>
23+
#include <string>
1824

1925
#if defined(__APPLE__)
2026
#include <mach-o/dyld.h>
@@ -26,7 +32,7 @@ namespace
2632
{
2733
static const char *env_or(const char *k, const char *defv)
2834
{
29-
if (const char *v = std::getenv(k))
35+
if (const char *v = vix::utils::vix_getenv(k))
3036
return v;
3137
return defv;
3238
}
@@ -87,11 +93,11 @@ namespace
8793
static std::string find_migrator_tool()
8894
{
8995
// New preferred env var
90-
if (const char *t = std::getenv("VIX_DB_TOOL"))
96+
if (const char *t = vix::utils::vix_getenv("VIX_DB_TOOL"))
9197
return std::string(t);
9298

9399
// Backward compat (old name)
94-
if (const char *t = std::getenv("VIX_ORM_TOOL"))
100+
if (const char *t = vix::utils::vix_getenv("VIX_ORM_TOOL"))
95101
return std::string(t);
96102

97103
const auto try_paths = [](const std::vector<fs::path> &paths) -> std::string

src/commands/PackCommand.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#include <vix/cli/commands/PackCommand.hpp>
1515
#include <vix/cli/Style.hpp>
16+
#include <vix/utils/Env.hpp>
1617
#include <nlohmann/json.hpp>
1718
#include <filesystem>
1819
#include <fstream>
@@ -200,7 +201,7 @@ namespace
200201
#ifndef _WIN32
201202
static std::optional<fs::path> find_default_minisign_seckey()
202203
{
203-
const char *home = std::getenv("HOME");
204+
const char *home = vix::utils::vix_getenv("HOME");
204205
if (!home || !*home)
205206
return std::nullopt;
206207

@@ -680,7 +681,7 @@ namespace
680681

681682
std::string env_or_default(const char *name, const std::string &fallback)
682683
{
683-
const char *v = std::getenv(name);
684+
const char *v = vix::utils::vix_getenv(name);
684685
if (v && *v)
685686
return std::string(v);
686687
return fallback;

0 commit comments

Comments
 (0)