Skip to content

Commit

Permalink
Merge pull request #11461 from rouault/fix_11460
Browse files Browse the repository at this point in the history
GDALTermProgress(): implement OSC 9;4 progress reporting protocol as …
  • Loading branch information
rouault authored Dec 9, 2024
2 parents 16da110 + 3dc1e30 commit d511807
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions port/cpl_known_config_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ constexpr static const char* const apszKnownConfigOptions[] =
"GDAL_STACTA_SKIP_MISSING_METATILE", // from stactadataset.cpp
"GDAL_SWATH_SIZE", // from gdalmultidim.cpp, rasterio.cpp
"GDAL_TEMP_DRIVER_NAME", // from nearblack_lib_floodfill.cpp
"GDAL_TERM_PROGRESS_OSC_9_4", // from cpl_progress.cpp
"GDAL_TIFF_DEFLATE_SUBCODEC", // from gtiffdataset.cpp
"GDAL_TIFF_ENDIANNESS", // from gtiffdataset_write.cpp
"GDAL_TIFF_INTERNAL_MASK", // from gtiffdataset_write.cpp
Expand Down
29 changes: 29 additions & 0 deletions port/cpl_progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <algorithm>

#include "cpl_conv.h"
#include "cpl_string.h"

/************************************************************************/
/* GDALDummyProgress() */
Expand Down Expand Up @@ -276,6 +277,34 @@ int CPL_STDCALL GDALTermProgress(double dfComplete,
fprintf(stdout, "\b");
nLastTick = -1;
nCharacterCountLastTime = 0;

#ifdef _WIN32
constexpr const char *WINDOWS_TERMINAL_ENV_VAR = "WT_SESSION";
constexpr const char *CONEMU_ENV_VAR = "ConEmuANSI";
#endif
static const bool bAllowOSC94 = CPLTestBool(CPLGetConfigOption(
"GDAL_TERM_PROGRESS_OSC_9_4",
#ifdef _WIN32
// Detect if we are running under Windows Terminal
(CPLGetConfigOption(WINDOWS_TERMINAL_ENV_VAR, nullptr) != nullptr ||
// or ConEmu
CPLGetConfigOption(CONEMU_ENV_VAR, nullptr) != nullptr)
? "YES"
: "NO"
#else
"YES"
#endif
));
if (bAllowOSC94)
{
// Implement OSC 9;4 progress reporting protocol
// https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
if (nThisTick == MAX_TICKS)
fprintf(stdout, "\x1b]9;4;0;100\x07");
else
fprintf(stdout, "\x1b]9;4;1;%d\x07",
(nThisTick * 100) / MAX_TICKS);
}
}

while (nThisTick > nLastTick)
Expand Down

0 comments on commit d511807

Please sign in to comment.