Commit fb8f7546 authored by Lukas Appelhans's avatar Lukas Appelhans

Make use of full terminal and better output

parent b4a763a7
......@@ -22,6 +22,17 @@
#include <akabeioperationrunner.h>
#include <iostream>
#include <kdebug.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdio.h>
int getcols()
{
struct winsize ws;
ioctl(1, TIOCGWINSZ, &ws);
return ws.ws_col;
}
QueueOperation::QueueOperation(QList<APM::Operation> operations, QMultiHash< APM::Operation, QString > options, QObject * parent)
: QObject(parent),
......@@ -142,49 +153,65 @@ void QueueOperation::validationFinished(bool valid)
void QueueOperation::showProgress()
{
int progress = AkabeiClient::Backend::instance()->transactionHandler()->progress();
unsigned int hashlen = getcols();
QTextStream out(stdout);
out.reset();
QString status;
switch (AkabeiClient::Backend::instance()->transactionHandler()->phase()) {
case AkabeiClient::TransactionHandler::Validating:
out << i18n("Validating");
status = i18n("Validating...");
break;
case AkabeiClient::TransactionHandler::RunningPreHooks:
out << i18n("Running PreHooks");
status = i18n("Running PreHooks...");
break;
case AkabeiClient::TransactionHandler::Downloading:
out << i18n("Downloading");
status = i18n("Downloading...");
break;
case AkabeiClient::TransactionHandler::Processing:
out << i18n("Processing");
status = i18n("Processing...");
break;
case AkabeiClient::TransactionHandler::RunningScriptlets:
out << i18n("Running Scriplets");
status = i18n("Running Scriplets...");
break;
case AkabeiClient::TransactionHandler::RunningPostHooks:
out << i18n("Running PostHooks");
status = i18n("Running PostHooks...");
break;
case AkabeiClient::TransactionHandler::Cleaning:
out << i18n("Cleaning");
status = i18n("Cleaning...");
break;
default:
out << i18n("Finished");
status = i18n("Finished!");
break;
};
hashlen = hashlen - status.length();
out << status;
QHash<Akabei::Package*, int>::iterator i = m_progresses.begin();
QHash<Akabei::Package*, int>::iterator end = m_progresses.end();
for (; i != end; i++) {
out << ' ' << i.key()->name() << " (" << i.value() << "%)";
QString output = " | " + i.key()->name() + " (" + QString::number(i.value()) + "%)";
hashlen = hashlen - output.length();
out << output;
}
out << ' ' << i18n("Total progress:") << " [";
int columns = 20;
for (int i = 1; i != columns + 1; i++) {
if (progress / i >= 100 / columns) {
QString totalOut = " | " + i18n("Total progress:") + " [";
out << totalOut;
QString endOut = "] " + QString::number(progress) + "%";
hashlen = hashlen - totalOut.length() - endOut.length();
const unsigned int hash = progress * hashlen / 100;
for (unsigned int i = hashlen; i > 1; --i) {
/* if special progress bar enabled */
if (i > hashlen - hash) {
out << "#";
} else {
out << "-";
}
}
out << "] " << progress << "%";//FIXME
out << endOut;//FIXME
if (progress == 100) {
out << endl;
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment