Skip to content

Commit

Permalink
Wait at least 500ms to start indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Slackadays committed Aug 20, 2023
1 parent 8fbfad4 commit 5606f1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cb/src/clipboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void showClipboardContents();
void setupAction(int& argc, char* argv[]);
void checkForNoItems();
void startIndicator();
void setupIndicator();
void indicatorThread();
void deduplicateItems();
unsigned long long totalItemSize();
void checkItemSize();
Expand Down
8 changes: 6 additions & 2 deletions src/cb/src/indicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool stopIndicator(bool change_condition_variable) {
return true;
}

void setupIndicator() {
void indicatorThread() {
if (!is_tty.err || output_silent || progress_silent) return;

bool hasFocus = true;
Expand Down Expand Up @@ -76,6 +76,10 @@ void setupIndicator() {
};

auto display_progress = [&](const auto& formattedNum, const std::string_view& actionText = doing_action[action]) {
if (std::chrono::steady_clock::now() - start < std::chrono::milliseconds(500)) {
cv.wait_for(lock, std::chrono::milliseconds(17), [&] { return progress_state != IndicatorState::Active; });
return;
}
std::string progressBar;
if (step < 40) {
progressBar += repeatString("โ–ˆ", step);
Expand Down Expand Up @@ -168,5 +172,5 @@ void setupIndicator() {
void startIndicator() { // If cancelled, leave cancelled
IndicatorState expect = IndicatorState::Done;
progress_state.compare_exchange_strong(expect, IndicatorState::Active);
indicator = std::thread(setupIndicator);
indicator = std::thread(indicatorThread);
}

0 comments on commit 5606f1b

Please sign in to comment.