progress bar: factor out activity ancestor precedence logic
Change-Id: I2bc736cd176f0147477dfb94dd48a4c8a1f8ec77
This commit is contained in:
parent
5623e759ec
commit
e30b15ca93
2 changed files with 41 additions and 12 deletions
|
@ -168,23 +168,29 @@ void ProgressBar::startActivity(
|
||||||
i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1));
|
i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type == actFileTransfer && hasAncestor(*state, actCopyPath, parent))
|
if (ancestorTakesPrecedence(*state, type, parent)) {
|
||||||
|| (type == actFileTransfer && hasAncestor(*state, actQueryPathInfo, parent))
|
|
||||||
|| (type == actCopyPath && hasAncestor(*state, actSubstitute, parent)))
|
|
||||||
i->visible = false;
|
i->visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
update(*state);
|
update(*state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether an activity has an ancestore with the specified
|
bool ProgressBar::hasAncestor(State & state, ActivityType type, ActivityId act) const
|
||||||
type. */
|
|
||||||
bool ProgressBar::hasAncestor(State & state, ActivityType type, ActivityId act)
|
|
||||||
{
|
{
|
||||||
|
// 0 is the sentinel value for a non-existent activity ID.
|
||||||
while (act != 0) {
|
while (act != 0) {
|
||||||
auto i = state.its.find(act);
|
auto const foundActIt = state.its.find(act);
|
||||||
if (i == state.its.end()) break;
|
if (foundActIt == state.its.end()) {
|
||||||
if (i->second->type == type) return true;
|
break;
|
||||||
act = i->second->parent;
|
}
|
||||||
|
|
||||||
|
ActInfo const & foundActInfo = *foundActIt->second;
|
||||||
|
|
||||||
|
if (foundActInfo.type == type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
act = foundActInfo.parent;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -494,6 +500,23 @@ void ProgressBar::setPrintBuildLogs(bool printBuildLogs)
|
||||||
this->printBuildLogs = printBuildLogs;
|
this->printBuildLogs = printBuildLogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProgressBar::ancestorTakesPrecedence(State & state, ActivityType type, ActivityId parent)
|
||||||
|
{
|
||||||
|
if (type == actFileTransfer && hasAncestor(state, actCopyPath, parent)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == actFileTransfer && hasAncestor(state, actQueryPathInfo, parent)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == actCopyPath && hasAncestor(state, actSubstitute, parent)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Logger * makeProgressBar()
|
Logger * makeProgressBar()
|
||||||
{
|
{
|
||||||
return new ProgressBar(shouldANSI());
|
return new ProgressBar(shouldANSI());
|
||||||
|
|
|
@ -106,7 +106,8 @@ struct ProgressBar : public Logger
|
||||||
ActivityId parent
|
ActivityId parent
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
bool hasAncestor(State & state, ActivityType type, ActivityId act);
|
/** Check whether an activity has an ancestor with the specified type. */
|
||||||
|
bool hasAncestor(State & state, ActivityType type, ActivityId act) const;
|
||||||
|
|
||||||
void stopActivity(ActivityId act) override;
|
void stopActivity(ActivityId act) override;
|
||||||
|
|
||||||
|
@ -116,13 +117,18 @@ struct ProgressBar : public Logger
|
||||||
|
|
||||||
std::chrono::milliseconds draw(State & state);
|
std::chrono::milliseconds draw(State & state);
|
||||||
|
|
||||||
std::string getStatus(State & state);
|
std::string getStatus(State & state) const;
|
||||||
|
|
||||||
void writeToStdout(std::string_view s) override;
|
void writeToStdout(std::string_view s) override;
|
||||||
|
|
||||||
std::optional<char> ask(std::string_view msg) override;
|
std::optional<char> ask(std::string_view msg) override;
|
||||||
|
|
||||||
void setPrintBuildLogs(bool printBuildLogs) override;
|
void setPrintBuildLogs(bool printBuildLogs) override;
|
||||||
|
|
||||||
|
/** Returns true if the given activity should not be rendered,
|
||||||
|
* in lieu of rendering its parent instead.
|
||||||
|
*/
|
||||||
|
bool ancestorTakesPrecedence(State & state, ActivityType type, ActivityId parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger * makeProgressBar();
|
Logger * makeProgressBar();
|
||||||
|
|
Loading…
Reference in a new issue