From: Adrien Gallouët Date: Tue, 30 Sep 2025 17:52:41 +0000 (+0200) Subject: common : disable progress bar without a tty (#16352) X-Git-Tag: upstream/0.0.6764~113 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=bf6f3b3a1965d70e07ca94aab7b01268fe483e96;p=pkg%2Fggml%2Fsources%2Fllama.cpp common : disable progress bar without a tty (#16352) * common : disable progress bar without a tty Signed-off-by: Adrien Gallouët * Add missing headers Signed-off-by: Adrien Gallouët --------- Signed-off-by: Adrien Gallouët --- diff --git a/common/arg.cpp b/common/arg.cpp index 3c932264..8da74f90 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -54,6 +54,13 @@ #endif #define LLAMA_MAX_URL_LENGTH 2084 // Maximum URL Length in Chrome: 2083 +// isatty +#if defined(_WIN32) +#include +#else +#include +#endif + using json = nlohmann::ordered_json; std::initializer_list mmproj_examples = { @@ -100,6 +107,14 @@ static void write_file(const std::string & fname, const std::string & content) { } } +static bool is_output_a_tty() { +#if defined(_WIN32) + return _isatty(_fileno(stdout)); +#else + return isatty(1); +#endif +} + common_arg & common_arg::set_examples(std::initializer_list examples) { this->examples = std::move(examples); return *this; @@ -652,7 +667,11 @@ static std::string show_masked_url(const common_url & parts) { return parts.scheme + "://" + (parts.user.empty() ? "" : "****:****@") + parts.host + parts.path; } -static void print_progress(size_t current, size_t total) { // TODO isatty +static void print_progress(size_t current, size_t total) { + if (!is_output_a_tty()) { + return; + } + if (!total) { return; }