256
256
PackageManagerFancy::GetTerminalSize()
258
258
struct winsize win;
259
PackageManagerFancy::TermSize s;
259
PackageManagerFancy::TermSize s = { 0, 0 };
261
261
// FIXME: get from "child_pty" instead?
262
262
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) != 0)
265
265
if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
266
std::cerr << "GetTerminalSize: " << win.ws_row << std::endl;
266
std::cerr << "GetTerminalSize: " << win.ws_row << " x " << win.ws_col << std::endl;
268
268
s.rows = win.ws_row;
269
269
s.columns = win.ws_col;
275
275
if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
276
276
std::cerr << "SetupTerminalScrollArea: " << nr_rows << std::endl;
278
if (unlikely(nr_rows <= 1))
278
281
// scroll down a bit to avoid visual glitch when the screen
279
282
// area shrinks by one row
280
283
std::cout << "\n";
296
299
// setup tty size to ensure xterm/linux console are working properly too
297
300
// see bug #731738
298
301
struct winsize win;
299
ioctl(child_pty, TIOCGWINSZ, (char *)&win);
300
win.ws_row = nr_rows - 1;
301
ioctl(child_pty, TIOCSWINSZ, (char *)&win);
302
if (ioctl(child_pty, TIOCGWINSZ, (char *)&win) != -1)
304
win.ws_row = nr_rows - 1;
305
ioctl(child_pty, TIOCSWINSZ, (char *)&win);
304
309
void PackageManagerFancy::HandleSIGWINCH(int)
306
int nr_terminal_rows = GetTerminalSize().rows;
311
int const nr_terminal_rows = GetTerminalSize().rows;
307
312
SetupTerminalScrollArea(nr_terminal_rows);
310
316
void PackageManagerFancy::Start(int a_child_pty)
312
318
child_pty = a_child_pty;
313
int nr_terminal_rows = GetTerminalSize().rows;
314
if (nr_terminal_rows > 0)
315
SetupTerminalScrollArea(nr_terminal_rows);
319
int const nr_terminal_rows = GetTerminalSize().rows;
320
SetupTerminalScrollArea(nr_terminal_rows);
318
323
void PackageManagerFancy::Stop()
320
int nr_terminal_rows = GetTerminalSize().rows;
325
int const nr_terminal_rows = GetTerminalSize().rows;
321
326
if (nr_terminal_rows > 0)
323
328
SetupTerminalScrollArea(nr_terminal_rows + 1);
358
363
HumanReadableAction))
361
PackageManagerFancy::TermSize size = GetTerminalSize();
366
return DrawStatusLine();
368
bool PackageManagerFancy::DrawStatusLine()
370
PackageManagerFancy::TermSize const size = GetTerminalSize();
371
if (unlikely(size.rows < 1 || size.columns < 1))
363
374
static std::string save_cursor = "\033[s";
364
375
static std::string restore_cursor = "\033[u";
390
401
float progressbar_size = size.columns - padding - progress_str.size();
391
float current_percent = (float)StepsDone/(float)TotalSteps;
402
float current_percent = percentage / 100.0;
393
404
<< GetTextProgressStr(current_percent, progressbar_size)