1 /*
2  * Copyright 2019 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "progress.hpp"
18 
19 #include <cstdio>
20 
21 namespace host_tool
22 {
23 
updateProgress(std::int64_t bytes)24 void ProgressStdoutIndicator::updateProgress(std::int64_t bytes)
25 {
26     /* Print progress update. */
27     currentBytes += bytes;
28     std::fprintf(stdout, "\rProgress: %.2f%%",
29                  100.0 * currentBytes / totalBytes);
30     if (currentBytes == totalBytes)
31         std::fprintf(stdout, "\n");
32 
33     std::fflush(stdout);
34 }
35 
start(std::int64_t bytes)36 void ProgressStdoutIndicator::start(std::int64_t bytes)
37 {
38     totalBytes = bytes;
39     currentBytes = 0;
40 }
41 
finish()42 void ProgressStdoutIndicator::finish() {}
43 
abort()44 void ProgressStdoutIndicator::abort() {}
45 
46 } // namespace host_tool
47