Skip to content

Commit ed8a883

Browse files
committed
[cli] Minimize non-live effects on spinner
Maintain locks and running state in spinner, even when non-live.
1 parent 0ebb71a commit ed8a883

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

src/client/cli/cmd/animated_spinner.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ mp::AnimatedSpinner::~AnimatedSpinner()
4242

4343
void mp::AnimatedSpinner::start(const std::string& start_message)
4444
{
45-
if (!is_live)
46-
{
47-
current_message = start_message;
48-
cout << start_message << std::flush;
49-
return;
50-
}
51-
5245
std::unique_lock<decltype(mutex)> lock{mutex};
46+
5347
if (!running)
5448
{
5549
current_message = start_message;
5650
running = true;
57-
clear_line(cout);
58-
cout << start_message << " " << std::flush;
59-
t = std::thread(&AnimatedSpinner::draw, this);
51+
52+
if (is_live)
53+
{
54+
clear_line(cout);
55+
cout << start_message << " " << std::flush;
56+
t = std::thread(&AnimatedSpinner::draw, this);
57+
}
58+
else
59+
cout << start_message << std::flush;
6060
}
6161
}
6262

@@ -68,19 +68,21 @@ void mp::AnimatedSpinner::start()
6868

6969
void mp::AnimatedSpinner::stop()
7070
{
71-
if (!is_live)
72-
return;
73-
7471
std::unique_lock<decltype(mutex)> lock{mutex};
7572
if (running)
7673
{
7774
running = false;
78-
cv.notify_one();
79-
lock.unlock();
80-
if (t.joinable())
81-
t.join();
75+
if (is_live)
76+
{
77+
cv.notify_one();
78+
lock.unlock();
79+
if (t.joinable())
80+
t.join();
81+
}
8282
}
83-
clear_line(cout);
83+
84+
if (is_live)
85+
clear_line(cout);
8486
}
8587

8688
void mp::AnimatedSpinner::print(std::ostream& stream, const std::string& message)

0 commit comments

Comments
 (0)