Example #1
0
progressbar::progressbar(const file& f, const quvi::media& m)
  : _update_interval(1),
    _expected_bytes(m.content_length()),
    _initial_bytes(f.initial_length()),
    _time_started(0),
    _last_update(0),
    _term_width(0),
    _dot_count(0),
    _count(0),
    _width(0),
    _file(f),
    _done(false),
    _mode(normal)
{
  if (_initial_bytes > _expected_bytes)
    _expected_bytes = _initial_bytes;

#ifdef WITH_RESIZE
  signal(SIGWINCH, handle_sigwinch);

  if (!_term_width || recv_sigwinch)
    {
      _term_width = get_term_width();

      if (!_term_width)
        _term_width = default_term_width;
    }
#else
  _term_width = default_term_width;
#endif

  _width = _term_width;

  const po::variables_map map = cc::opts.map();
  time(&_time_started);

  if (opts.flags.background)
    _mode = dotline;
  else
    {
      const std::string s = map["progressbar"].as<std::string>();
      if (s == "simple")
        _mode = simple;
      else if (s == "dotline")
        _mode = dotline;
    }

  _update_interval = fabs(map["update-interval"].as<double>());
}