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