Nix  2.93.0-dev
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
progress-bar.hh
Go to the documentation of this file.
1#pragma once
3
4#include <chrono>
5
7#include "lix/libutil/sync.hh"
8
9namespace nix {
10
11struct ProgressBar : public Logger
12{
13 struct ActInfo
14 {
15 using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
16
17 std::string s, lastLine, phase;
18 ActivityType type = actUnknown;
19 uint64_t done = 0;
20 uint64_t expected = 0;
21 uint64_t running = 0;
22 uint64_t failed = 0;
23 std::map<ActivityType, uint64_t> expectedByType;
24 bool visible = true;
25 ActivityId parent;
26 std::optional<std::string> name;
27 TimePoint startTime;
28 };
29
31 {
32 std::map<ActivityId, std::list<ActInfo>::iterator> its;
33 uint64_t done = 0;
34 uint64_t expected = 0;
35 uint64_t failed = 0;
36 };
37
38 struct State
39 {
40 std::list<ActInfo> activities;
41 std::map<ActivityId, std::list<ActInfo>::iterator> its;
42
43 std::map<ActivityType, ActivitiesByType> activitiesByType;
44
45 int lastLines = 0;
46
47 uint64_t filesLinked = 0, bytesLinked = 0;
48
49 uint64_t corruptedPaths = 0, untrustedPaths = 0;
50
51 uint32_t paused = 1;
52 bool haveUpdate = false;
53 };
54
55 Sync<State> state_;
56
57 std::thread updateThread;
58
59 std::condition_variable quitCV, updateCV;
60
61 bool printBuildLogs = false;
62 bool printMultiline = false;
63 bool isTTY;
64
65 ProgressBar(bool isTTY);
66
68
69 void pause() override;
70
71 void resetProgress() override;
72
73 void resume() override;
74
75 bool isVerbose() override;
76
77 void log(Verbosity lvl, std::string_view s) override;
78
79 void logEI(const ErrorInfo & ei) override;
80
81 void log(State & state, Verbosity lvl, std::string_view s);
82
83 void startActivity(
84 ActivityId act,
85 Verbosity lvl,
86 ActivityType type,
87 const std::string & s,
88 const Fields & fields,
89 ActivityId parent
90 ) override;
91
92 bool hasAncestor(State & state, ActivityType type, ActivityId act);
93
94 void stopActivity(ActivityId act) override;
95
96 void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override;
97
98 void update(State & state);
99
100 std::string getStatus(State & state);
101
102 void writeToStdout(std::string_view s) override;
103
104 std::optional<char> ask(std::string_view msg) override;
105
106 void setPrintBuildLogs(bool printBuildLogs) override;
107
108 void setPrintMultiline(bool printMultiline) override;
109
110private:
111 void eraseProgressDisplay(State & state);
112
113 std::chrono::milliseconds restoreProgressDisplay(State & state);
114};
115
116Logger * makeProgressBar();
117
118}
Definition logging.hh:101
Definition sync.hh:37
ActivityType
Definition logging.hh:10
ResultType
Definition logging.hh:50
Definition error.hh:96
Definition progress-bar.hh:14
Definition progress-bar.hh:31
Definition progress-bar.hh:39
Definition progress-bar.hh:12