mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 22:46:16 +02:00
parent
57aeef0b6a
commit
8a2f5f0607
1 changed files with 36 additions and 32 deletions
68
nix-repl.cc
68
nix-repl.cc
|
@ -87,8 +87,8 @@ void NixRepl::mainLoop(const Strings & files)
|
||||||
{
|
{
|
||||||
std::cout << "Welcome to Nix version " << NIX_VERSION << ". Type :? for help." << std::endl << std::endl;
|
std::cout << "Welcome to Nix version " << NIX_VERSION << ". Type :? for help." << std::endl << std::endl;
|
||||||
|
|
||||||
foreach (Strings::const_iterator, i, files)
|
for (auto & i : files)
|
||||||
loadedFiles.push_back(*i);
|
loadedFiles.push_back(i);
|
||||||
|
|
||||||
reloadFiles();
|
reloadFiles();
|
||||||
if (!loadedFiles.empty()) std::cout << std::endl;
|
if (!loadedFiles.empty()) std::cout << std::endl;
|
||||||
|
@ -210,8 +210,8 @@ void NixRepl::completePrefix(string prefix)
|
||||||
e->eval(state, *env, v);
|
e->eval(state, *env, v);
|
||||||
state.forceAttrs(v);
|
state.forceAttrs(v);
|
||||||
|
|
||||||
foreach (Bindings::iterator, i, *v.attrs) {
|
for (auto & i : *v.attrs) {
|
||||||
string name = i->name;
|
string name = i.name;
|
||||||
if (string(name, 0, prefix2.size()) != prefix2) continue;
|
if (string(name, 0, prefix2.size()) != prefix2) continue;
|
||||||
completions.insert(expr + "." + name);
|
completions.insert(expr + "." + name);
|
||||||
}
|
}
|
||||||
|
@ -251,11 +251,11 @@ static int runProgram(const string & program, const Strings & args)
|
||||||
bool isVarName(const string & s)
|
bool isVarName(const string & s)
|
||||||
{
|
{
|
||||||
// FIXME: not quite correct.
|
// FIXME: not quite correct.
|
||||||
foreach (string::const_iterator, i, s)
|
for (auto & i : s)
|
||||||
if (!((*i >= 'a' && *i <= 'z') ||
|
if (!((i >= 'a' && i <= 'z') ||
|
||||||
(*i >= 'A' && *i <= 'Z') ||
|
(i >= 'A' && i <= 'Z') ||
|
||||||
(*i >= '0' && *i <= '9') ||
|
(i >= '0' && i <= '9') ||
|
||||||
*i == '_' || *i == '\''))
|
i == '_' || i == '\''))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -329,8 +329,8 @@ bool NixRepl::processLine(string line)
|
||||||
if (runProgram("nix-store", Strings{"-r", drvPath}) == 0) {
|
if (runProgram("nix-store", Strings{"-r", drvPath}) == 0) {
|
||||||
Derivation drv = readDerivation(drvPath);
|
Derivation drv = readDerivation(drvPath);
|
||||||
std::cout << std::endl << "this derivation produced the following outputs:" << std::endl;
|
std::cout << std::endl << "this derivation produced the following outputs:" << std::endl;
|
||||||
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
for (auto & i : drv.outputs)
|
||||||
std::cout << format(" %1% -> %2%") % i->first % i->second.path << std::endl;
|
std::cout << format(" %1% -> %2%") % i.first % i.second.path << std::endl;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
runProgram("nix-shell", Strings{drvPath});
|
runProgram("nix-shell", Strings{drvPath});
|
||||||
|
@ -393,8 +393,8 @@ void NixRepl::initEnv()
|
||||||
staticEnv.vars.clear();
|
staticEnv.vars.clear();
|
||||||
|
|
||||||
varNames.clear();
|
varNames.clear();
|
||||||
foreach (StaticEnv::Vars::iterator, i, state.staticBaseEnv.vars)
|
for (auto & i : state.staticBaseEnv.vars)
|
||||||
varNames.insert(i->first);
|
varNames.insert(i.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -405,10 +405,12 @@ void NixRepl::reloadFiles()
|
||||||
Strings old = loadedFiles;
|
Strings old = loadedFiles;
|
||||||
loadedFiles.clear();
|
loadedFiles.clear();
|
||||||
|
|
||||||
foreach (Strings::iterator, i, old) {
|
bool first = true;
|
||||||
if (i != old.begin()) std::cout << std::endl;
|
for (auto & i : old) {
|
||||||
std::cout << format("Loading ‘%1%’...") % *i << std::endl;
|
if (!first) std::cout << std::endl;
|
||||||
loadFile(*i);
|
first = false;
|
||||||
|
std::cout << format("Loading ‘%1%’...") % i << std::endl;
|
||||||
|
loadFile(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,8 +418,8 @@ void NixRepl::reloadFiles()
|
||||||
void NixRepl::addAttrsToScope(Value & attrs)
|
void NixRepl::addAttrsToScope(Value & attrs)
|
||||||
{
|
{
|
||||||
state.forceAttrs(attrs);
|
state.forceAttrs(attrs);
|
||||||
foreach (Bindings::iterator, i, *attrs.attrs)
|
for (auto & i : *attrs.attrs)
|
||||||
addVarToScope(i->name, *i->value);
|
addVarToScope(i.name, *i.value);
|
||||||
std::cout << format("Added %1% variables.") % attrs.attrs->size() << std::endl;
|
std::cout << format("Added %1% variables.") % attrs.attrs->size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,8 +511,8 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
|
|
||||||
typedef std::map<string, Value *> Sorted;
|
typedef std::map<string, Value *> Sorted;
|
||||||
Sorted sorted;
|
Sorted sorted;
|
||||||
foreach (Bindings::iterator, i, *v.attrs)
|
for (auto & i : *v.attrs)
|
||||||
sorted[i->name] = i->value;
|
sorted[i.name] = i.value;
|
||||||
|
|
||||||
/* If this is a derivation, then don't show the
|
/* If this is a derivation, then don't show the
|
||||||
self-references ("all", "out", etc.). */
|
self-references ("all", "out", etc.). */
|
||||||
|
@ -522,20 +524,20 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
hidden.insert("out");
|
hidden.insert("out");
|
||||||
else {
|
else {
|
||||||
state.forceList(*i->value);
|
state.forceList(*i->value);
|
||||||
for (unsigned int j = 0; j < i->value->list.length; ++j)
|
for (unsigned int j = 0; j < i->value->listSize(); ++j)
|
||||||
hidden.insert(state.forceStringNoCtx(*i->value->list.elems[j]));
|
hidden.insert(state.forceStringNoCtx(*i->value->listElems()[j]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Sorted::iterator, i, sorted) {
|
for (auto & i : sorted) {
|
||||||
str << i->first << " = ";
|
str << i.first << " = ";
|
||||||
if (hidden.find(i->first) != hidden.end())
|
if (hidden.find(i.first) != hidden.end())
|
||||||
str << "«...»";
|
str << "«...»";
|
||||||
else if (seen.find(i->second) != seen.end())
|
else if (seen.find(i.second) != seen.end())
|
||||||
str << "«repeated»";
|
str << "«repeated»";
|
||||||
else
|
else
|
||||||
try {
|
try {
|
||||||
printValue(str, *i->second, maxDepth - 1, seen);
|
printValue(str, *i.second, maxDepth - 1, seen);
|
||||||
} catch (AssertionError & e) {
|
} catch (AssertionError & e) {
|
||||||
str << "«error: " << e.msg() << "»";
|
str << "«error: " << e.msg() << "»";
|
||||||
}
|
}
|
||||||
|
@ -549,17 +551,19 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case tList:
|
case tList1:
|
||||||
|
case tList2:
|
||||||
|
case tListN:
|
||||||
seen.insert(&v);
|
seen.insert(&v);
|
||||||
|
|
||||||
str << "[ ";
|
str << "[ ";
|
||||||
if (maxDepth > 0)
|
if (maxDepth > 0)
|
||||||
for (unsigned int n = 0; n < v.list.length; ++n) {
|
for (unsigned int n = 0; n < v.listSize(); ++n) {
|
||||||
if (seen.find(v.list.elems[n]) != seen.end())
|
if (seen.find(v.listElems()[n]) != seen.end())
|
||||||
str << "«repeated»";
|
str << "«repeated»";
|
||||||
else
|
else
|
||||||
try {
|
try {
|
||||||
printValue(str, *v.list.elems[n], maxDepth - 1, seen);
|
printValue(str, *v.listElems()[n], maxDepth - 1, seen);
|
||||||
} catch (AssertionError & e) {
|
} catch (AssertionError & e) {
|
||||||
str << "«error: " << e.msg() << "»";
|
str << "«error: " << e.msg() << "»";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue