getTaskContext: Allow getting context info for a non-active context
This commit is contained in:
@@ -604,9 +604,10 @@ void CLI2::addContext (bool readable, bool writeable)
|
|||||||
// Detect if any context is set, and bail out if not
|
// Detect if any context is set, and bail out if not
|
||||||
std::string contextString;
|
std::string contextString;
|
||||||
if (readable)
|
if (readable)
|
||||||
contextString = Context::getContext ().getTaskContext("read");
|
// Empty string is treated as "currently selected context"
|
||||||
|
contextString = Context::getContext ().getTaskContext("read", "");
|
||||||
else if (writeable)
|
else if (writeable)
|
||||||
contextString = Context::getContext ().getTaskContext("write");
|
contextString = Context::getContext ().getTaskContext("write", "");
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -923,12 +923,15 @@ int Context::getHeight ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Context::getTaskContext (const std::string& kind, bool fallback /* = true */)
|
std::string Context::getTaskContext (const std::string& kind, std::string name, bool fallback /* = true */)
|
||||||
{
|
{
|
||||||
|
// Consider currently selected context, if none specified
|
||||||
|
if (name.empty ())
|
||||||
|
name = config.get ("context");
|
||||||
|
|
||||||
// Detect if any context is set, and bail out if not
|
// Detect if any context is set, and bail out if not
|
||||||
std::string contextName = config.get ("context");
|
if (! name.empty ())
|
||||||
if (! contextName.empty ())
|
debug (format ("Applying context '{1}'", name));
|
||||||
debug (format ("Applying context '{1}'", contextName));
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug ("No context set");
|
debug ("No context set");
|
||||||
@@ -936,14 +939,14 @@ std::string Context::getTaskContext (const std::string& kind, bool fallback /* =
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Figure out the context string for this kind (read/write)
|
// Figure out the context string for this kind (read/write)
|
||||||
std::string contextString = config.get ("context." + contextName + "." + kind);
|
std::string contextString = config.get ("context." + name + "." + kind);
|
||||||
if (contextString.empty ())
|
if (contextString.empty ())
|
||||||
{
|
{
|
||||||
debug ("Specific " + kind + " context for '" + contextName + "' not defined. ");
|
debug ("Specific " + kind + " context for '" + name + "' not defined. ");
|
||||||
if (fallback)
|
if (fallback)
|
||||||
{
|
{
|
||||||
debug ("Falling back on generic.");
|
debug ("Falling back on generic.");
|
||||||
contextString = config.get ("context." + contextName);
|
contextString = config.get ("context." + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
int getWidth (); // determine terminal width
|
int getWidth (); // determine terminal width
|
||||||
int getHeight (); // determine terminal height
|
int getHeight (); // determine terminal height
|
||||||
|
|
||||||
std::string getTaskContext (const std::string&, bool fallback=true);
|
std::string getTaskContext (const std::string&, std::string, bool fallback=true);
|
||||||
|
|
||||||
const std::vector <std::string> getColumns () const;
|
const std::vector <std::string> getColumns () const;
|
||||||
void getLimits (int&, int&);
|
void getLimits (int&, int&);
|
||||||
|
|||||||
Reference in New Issue
Block a user