aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2024-03-17 20:48:51 -0400
committerAdam Harrison <adamdharrison@gmail.com>2024-03-17 20:48:59 -0400
commit45daf1cd375b9835d913f689e1bce2b4fc93ac54 (patch)
treea1d6de1de85173edc369a3e29988b426a49084a5
parentd1fa522c4063e4c0738d3cd800ed9c598c2a92c4 (diff)
downloadlite-xl-plugin-manager-45daf1cd375b9835d913f689e1bce2b4fc93ac54.tar.gz
lite-xl-plugin-manager-45daf1cd375b9835d913f689e1bce2b4fc93ac54.zip
Added in a fix to detect windows consoles from cmd.exe.
-rw-r--r--src/lpm.c16
-rw-r--r--src/lpm.lua2
2 files changed, 16 insertions, 2 deletions
diff --git a/src/lpm.c b/src/lpm.c
index e63ff78..8b73cc2 100644
--- a/src/lpm.c
+++ b/src/lpm.c
@@ -1471,7 +1471,21 @@ int main(int argc, char* argv[]) {
lua_setglobal(L, "VERSION");
lua_pushliteral(L, ARCH_PLATFORM);
lua_setglobal(L, "PLATFORM");
- lua_pushboolean(L, isatty(fileno(stdout)));
+ #if _WIN32
+ DWORD handles[] = { STD_OUTPUT_HANDLE, STD_ERROR_HANDLE };
+ int setVirtualProcessing = 0;
+ for (int i = 0; i < 2; ++i) {
+ DWORD mode = 0;
+ if (GetConsoleMode(GetStdHandle(handles[i]), &mode)) {
+ if (SetConsoleMode(GetStdHandle(handles[i]), mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
+ setVirtualProcessing = 1;
+ }
+ }
+ // This will fail with mintty, see here: https://github.com/mintty/mintty/issues/482
+ lua_pushboolean(L, setVirtualProcessing || isatty(fileno(stdout)));
+ #else
+ lua_pushboolean(L, isatty(fileno(stdout)));
+ #endif
lua_setglobal(L, "TTY");
#if _WIN32
lua_pushliteral(L, "\\");
diff --git a/src/lpm.lua b/src/lpm.lua
index 250e507..1fffb39 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -528,7 +528,7 @@ end
local LATEST_MOD_VERSION = "3.0.0"
local EXECUTABLE_EXTENSION = PLATFORM == "windows" and ".exe" or ""
local HOME, USERDIR, CACHEDIR, JSON, TABLE, HEADER, RAW, VERBOSE, FILTRATION, MOD_VERSION, QUIET, FORCE, REINSTALL, CONFIG, NO_COLOR, AUTO_PULL_REMOTES, ARCH, ASSUME_YES, NO_INSTALL_OPTIONAL, TMPDIR, DATADIR, BINARY, POST, PROGRESS, SYMLINK, REPOSITORY, EPHEMERAL, MASK, settings, repositories, lite_xls, system_bottle, progress_bar_label, write_progress_bar
-local SHOULD_COLOR = os.getenv("TERM") and os.getenv("TERM") ~= "dumb" and not os.getenv("NO_COLOR")
+local SHOULD_COLOR = (PLATFORM == "windows" or (os.getenv("TERM") and os.getenv("TERM") ~= "dumb")) and not os.getenv("NO_COLOR")
local Addon, Repository, LiteXL, Bottle, lpm, log = {}, {}, {}, {}, {}, {}
local function engage_locks(func, err, warn)