remove signed to unsigned conversion + check for errors

This commit is contained in:
Daniel Breitlauch
2023-04-04 12:32:37 +02:00
parent 5050a88877
commit 6549b77d0b
4 changed files with 30 additions and 18 deletions

View File

@@ -164,7 +164,7 @@ private:
}
}
std::pair<std::string, size_t> get_prefix_text() {
std::pair<std::string, int> get_prefix_text() {
std::stringstream os;
os << get_value<details::ProgressBarOption::prefix_text>();
const auto result = os.str();
@@ -172,7 +172,7 @@ private:
return {result, result_size};
}
std::pair<std::string, size_t> get_postfix_text() {
std::pair<std::string, int> get_postfix_text() {
std::stringstream os;
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
auto now = std::chrono::high_resolution_clock::now();
@@ -269,7 +269,9 @@ public:
const auto terminal_width = terminal_size().second;
// prefix + bar_width + postfix should be <= terminal_width
const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);
if (remaining > 0) {
if (prefix_length == -1 || postfix_length == -1) {
os << "\r";
} else if (remaining > 0) {
os << std::string(remaining, ' ') << "\r";
} else if (remaining < 0) {
// Do nothing. Maybe in the future truncate postfix with ...

View File

@@ -160,7 +160,7 @@ private:
template <typename Indicator> friend class DynamicProgress;
std::atomic<bool> multi_progress_mode_{false};
std::pair<std::string, size_t> get_prefix_text() {
std::pair<std::string, int> get_prefix_text() {
std::stringstream os;
os << get_value<details::ProgressBarOption::prefix_text>();
const auto result = os.str();
@@ -168,7 +168,7 @@ private:
return {result, result_size};
}
std::pair<std::string, size_t> get_postfix_text() {
std::pair<std::string, int> get_postfix_text() {
std::stringstream os;
os << " " << get_value<details::ProgressBarOption::postfix_text>();
@@ -219,7 +219,9 @@ public:
const auto terminal_width = terminal_size().second;
// prefix + bar_width + postfix should be <= terminal_width
const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);
if (remaining > 0) {
if (prefix_length == -1 || postfix_length == -1) {
os << "\r";
} else if (remaining > 0) {
os << std::string(remaining, ' ') << "\r";
} else if (remaining < 0) {
// Do nothing. Maybe in the future truncate postfix with ...

View File

@@ -216,7 +216,7 @@ private:
}
}
std::pair<std::string, size_t> get_prefix_text() {
std::pair<std::string, int> get_prefix_text() {
std::stringstream os;
os << get_value<details::ProgressBarOption::prefix_text>();
const auto result = os.str();
@@ -224,7 +224,7 @@ private:
return {result, result_size};
}
std::pair<std::string, size_t> get_postfix_text() {
std::pair<std::string, int> get_postfix_text() {
std::stringstream os;
const auto max_progress =
get_value<details::ProgressBarOption::max_progress>();
@@ -338,7 +338,9 @@ public:
const auto terminal_width = terminal_size().second;
// prefix + bar_width + postfix should be <= terminal_width
const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);
if (remaining > 0) {
if (prefix_length == -1 || postfix_length == -1) {
os << "\r";
} else if (remaining > 0) {
os << std::string(remaining, ' ') << "\r";
} else if (remaining < 0) {
// Do nothing. Maybe in the future truncate postfix with ...

View File

@@ -2128,7 +2128,7 @@ private:
}
}
std::pair<std::string, size_t> get_prefix_text() {
std::pair<std::string, int> get_prefix_text() {
std::stringstream os;
os << get_value<details::ProgressBarOption::prefix_text>();
const auto result = os.str();
@@ -2136,7 +2136,7 @@ private:
return {result, result_size};
}
std::pair<std::string, size_t> get_postfix_text() {
std::pair<std::string, int> get_postfix_text() {
std::stringstream os;
const auto max_progress =
get_value<details::ProgressBarOption::max_progress>();
@@ -2250,7 +2250,9 @@ public:
const auto terminal_width = terminal_size().second;
// prefix + bar_width + postfix should be <= terminal_width
const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);
if (remaining > 0) {
if (prefix_length == -1 || postfix_length == -1) {
os << "\r";
} else if (remaining > 0) {
os << std::string(remaining, ' ') << "\r";
} else if (remaining < 0) {
// Do nothing. Maybe in the future truncate postfix with ...
@@ -2437,7 +2439,7 @@ private:
}
}
std::pair<std::string, size_t> get_prefix_text() {
std::pair<std::string, int> get_prefix_text() {
std::stringstream os;
os << get_value<details::ProgressBarOption::prefix_text>();
const auto result = os.str();
@@ -2445,7 +2447,7 @@ private:
return {result, result_size};
}
std::pair<std::string, size_t> get_postfix_text() {
std::pair<std::string, int> get_postfix_text() {
std::stringstream os;
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
auto now = std::chrono::high_resolution_clock::now();
@@ -2542,7 +2544,9 @@ public:
const auto terminal_width = terminal_size().second;
// prefix + bar_width + postfix should be <= terminal_width
const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);
if (remaining > 0) {
if (prefix_length == -1 || postfix_length == -1) {
os << "\r";
} else if (remaining > 0) {
os << std::string(remaining, ' ') << "\r";
} else if (remaining < 0) {
// Do nothing. Maybe in the future truncate postfix with ...
@@ -2724,7 +2728,7 @@ private:
template <typename Indicator> friend class DynamicProgress;
std::atomic<bool> multi_progress_mode_{false};
std::pair<std::string, size_t> get_prefix_text() {
std::pair<std::string, int> get_prefix_text() {
std::stringstream os;
os << get_value<details::ProgressBarOption::prefix_text>();
const auto result = os.str();
@@ -2732,7 +2736,7 @@ private:
return {result, result_size};
}
std::pair<std::string, size_t> get_postfix_text() {
std::pair<std::string, int> get_postfix_text() {
std::stringstream os;
os << " " << get_value<details::ProgressBarOption::postfix_text>();
@@ -2783,7 +2787,9 @@ public:
const auto terminal_width = terminal_size().second;
// prefix + bar_width + postfix should be <= terminal_width
const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);
if (remaining > 0) {
if (prefix_length == -1 || postfix_length == -1) {
os << "\r";
} else if (remaining > 0) {
os << std::string(remaining, ' ') << "\r";
} else if (remaining < 0) {
// Do nothing. Maybe in the future truncate postfix with ...