forked from lix-project/lix
* Align the columns in the output of `nix-env -q'.
This commit is contained in:
parent
593bc23d8b
commit
8f6254e823
|
@ -460,6 +460,36 @@ static bool cmpDrvByName(const DrvInfo & a, const DrvInfo & b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef list<Strings> Table;
|
||||||
|
|
||||||
|
|
||||||
|
void printTable(Table & table)
|
||||||
|
{
|
||||||
|
int nrColumns = table.front().size();
|
||||||
|
|
||||||
|
vector<int> widths;
|
||||||
|
widths.resize(nrColumns);
|
||||||
|
|
||||||
|
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
||||||
|
assert(i->size() == nrColumns);
|
||||||
|
Strings::iterator j; int column;
|
||||||
|
for (j = i->begin(), column = 0; j != i->end(); ++j, ++column)
|
||||||
|
if (j->size() > widths[column]) widths[column] = j->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
||||||
|
Strings::iterator j; int column;
|
||||||
|
for (j = i->begin(), column = 0; j != i->end(); ++j, ++column)
|
||||||
|
{
|
||||||
|
cout << *j;
|
||||||
|
if (column < nrColumns - 1)
|
||||||
|
cout << string(widths[column] - j->size() + 2, ' ');
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opQuery(Globals & globals,
|
static void opQuery(Globals & globals,
|
||||||
Strings opFlags, Strings opArgs)
|
Strings opFlags, Strings opArgs)
|
||||||
{
|
{
|
||||||
|
@ -519,6 +549,8 @@ static void opQuery(Globals & globals,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the desired columns. */
|
/* Print the desired columns. */
|
||||||
|
Table table;
|
||||||
|
|
||||||
for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i) {
|
for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i) {
|
||||||
|
|
||||||
Strings columns;
|
Strings columns;
|
||||||
|
@ -538,10 +570,10 @@ static void opQuery(Globals & globals,
|
||||||
|
|
||||||
if (printDrvPath) columns.push_back(i->drvPath);
|
if (printDrvPath) columns.push_back(i->drvPath);
|
||||||
|
|
||||||
for (Strings::iterator j = columns.begin(); j != columns.end(); ++j)
|
table.push_back(columns);
|
||||||
cout << *j << " ";
|
|
||||||
cout << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printTable(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue