Skip to content

Commit bf6f3b3

Browse files
authored
common : disable progress bar without a tty (ggml-org#16352)
* common : disable progress bar without a tty Signed-off-by: Adrien Gallouët <[email protected]> * Add missing headers Signed-off-by: Adrien Gallouët <[email protected]> --------- Signed-off-by: Adrien Gallouët <[email protected]>
1 parent 7c156df commit bf6f3b3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

common/arg.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
#endif
5555
#define LLAMA_MAX_URL_LENGTH 2084 // Maximum URL Length in Chrome: 2083
5656

57+
// isatty
58+
#if defined(_WIN32)
59+
#include <io.h>
60+
#else
61+
#include <unistd.h>
62+
#endif
63+
5764
using json = nlohmann::ordered_json;
5865

5966
std::initializer_list<enum llama_example> mmproj_examples = {
@@ -100,6 +107,14 @@ static void write_file(const std::string & fname, const std::string & content) {
100107
}
101108
}
102109

110+
static bool is_output_a_tty() {
111+
#if defined(_WIN32)
112+
return _isatty(_fileno(stdout));
113+
#else
114+
return isatty(1);
115+
#endif
116+
}
117+
103118
common_arg & common_arg::set_examples(std::initializer_list<enum llama_example> examples) {
104119
this->examples = std::move(examples);
105120
return *this;
@@ -652,7 +667,11 @@ static std::string show_masked_url(const common_url & parts) {
652667
return parts.scheme + "://" + (parts.user.empty() ? "" : "****:****@") + parts.host + parts.path;
653668
}
654669

655-
static void print_progress(size_t current, size_t total) { // TODO isatty
670+
static void print_progress(size_t current, size_t total) {
671+
if (!is_output_a_tty()) {
672+
return;
673+
}
674+
656675
if (!total) {
657676
return;
658677
}

0 commit comments

Comments
 (0)