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