• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 18299973882

07 Oct 2025 02:14AM UTC coverage: 81.92% (-3.3%) from 85.194%
18299973882

push

github

web-flow
Switch to using coveralls github action for reporting (#3594)

16586 of 23090 branches covered (71.83%)

Branch coverage included in aggregate %.

53703 of 62712 relevant lines covered (85.63%)

43428488.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.86
/src/progress_bar.cpp
1

2
#include "openmc/progress_bar.h"
3

4
#include <iomanip>
5
#include <iostream>
6
#include <sstream>
7

8
#if defined(__unix__) || defined(__unix) ||                                    \
9
  (defined(__APPLE__) && defined(__MACH__))
10
#include <unistd.h>
11
#endif
12

13
#define BAR_WIDTH 72
14

15
bool is_terminal()
4,785✔
16
{
17
#ifdef _POSIX_VERSION
18
  return isatty(STDOUT_FILENO) != 0;
4,785✔
19
#else
20
  return false;
21
#endif
22
}
23

24
ProgressBar::ProgressBar()
55✔
25
{
26
  // initialize bar
27
  set_value(0.0);
55✔
28
}
55✔
29

30
void ProgressBar::set_value(double val)
4,785✔
31
{
32

33
  if (!is_terminal())
4,785!
34
    return;
4,785✔
35

36
  // set the bar percentage
37
  if (val >= 100.0) {
×
38
    bar.append("100");
×
39
  } else if (val <= 0.0) {
×
40
    bar.append("  0");
×
41
  } else {
42
    std::stringstream ss;
×
43
    ss << std::setfill(' ') << std::setw(3) << (int)val;
×
44
    bar.append(ss.str());
×
45
  }
×
46

47
  bar.append("% |");
×
48
  // remaining width of the bar
49
  int remaining_width = BAR_WIDTH - bar.size() - 2;
×
50

51
  // set the bar width
52
  if (val >= 100.0) {
×
53
    bar.append(remaining_width, '=');
×
54
  } else if (val < 0.0) {
×
55
    bar.append(remaining_width, ' ');
×
56
  } else {
57
    int width = (int)((double)remaining_width * val / 100);
×
58
    bar.append(width, '=');
×
59
    bar.append(1, '>');
×
60
    bar.append(remaining_width - width - 1, ' ');
×
61
  }
62

63
  bar.append("|+");
×
64

65
  // write the bar
66
  std::cout << '\r' << bar << std::flush;
×
67
  if (val >= 100.0) {
×
68
    std::cout << "\n";
×
69
  }
70

71
  // reset the bar value
72
  bar = "";
×
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc