blob: 68b31cc0578615e34f42a1a08ffd615b71410ab0 [file] [log] [blame]
Patrick Venturecf9b2192019-06-27 12:09:52 -07001/*
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
21namespace host_tool
22{
23
24void 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);
Patrick Ventured62a3d42019-06-28 16:19:11 -070030 if (currentBytes == totalBytes)
31 std::fprintf(stdout, "\n");
32
Patrick Venturecf9b2192019-06-27 12:09:52 -070033 std::fflush(stdout);
34}
35
36void ProgressStdoutIndicator::start(std::int64_t bytes)
37{
38 totalBytes = bytes;
39 currentBytes = 0;
40}
41
William A. Kennington III0d5bb782021-01-19 15:50:42 -080042void ProgressStdoutIndicator::finish()
43{}
44
45void ProgressStdoutIndicator::abort()
46{}
47
Patrick Venturecf9b2192019-06-27 12:09:52 -070048} // namespace host_tool