Enhancement - debug support

- Added debug=on support.
- Added color.debug= support.
This commit is contained in:
Paul Beckingham 2009-06-20 10:54:01 -04:00
parent 173b3f6828
commit 02518e0223
7 changed files with 56 additions and 30 deletions

View file

@ -63,21 +63,17 @@ static const char* modifiableNames[] =
"until",
};
// Synonyms on the same line.
static const char* modifierNames[] =
{
"before",
"after",
"under",
"over",
"below",
"above",
"before", "under", "below",
"after", "over", "above",
"none",
"any",
"is",
"isnt",
"has",
"isnt", "not",
"has", "contains",
"hasnt",
"contains",
"startswith",
"endswith",
};
@ -486,7 +482,7 @@ bool Att::match (const Att& other) const
}
// isnt = not equal.
else if (mMod == "isnt") // TODO i18n
else if (mMod == "isnt" || mMod == "not") // TODO i18n
{
if (mValue == other.mValue)
return false;

View file

@ -146,6 +146,11 @@ int Context::run ()
message (stringtable.get (100, "Unknown error."));
}
// Dump all debug messages.
if (config.get ("debug", true))
foreach (d, debugMessages)
std::cout << colorizeDebug (*d) << std::endl;
// Dump all headers.
foreach (h, headers)
std::cout << colorizeHeader (*h) << std::endl;
@ -367,7 +372,7 @@ void Context::parse (
// The '--' argument shuts off all parsing - everything is an argument.
if (*arg == "--")
{
header ("parse terminator '" + *arg + "'");
debug ("parse terminator '" + *arg + "'");
terminated = true;
}
@ -377,7 +382,7 @@ void Context::parse (
! foundSomethingAfterSequence &&
parseSequence.valid (*arg))
{
header ("parse sequence '" + *arg + "'");
debug ("parse sequence '" + *arg + "'");
parseSequence.parse (*arg);
foundSequence = true;
}
@ -387,7 +392,7 @@ void Context::parse (
(*arg)[0] == '+' &&
validTag (*arg))
{
header ("parse tag addition '" + *arg + "'");
debug ("parse tag addition '" + *arg + "'");
if (foundSequence)
foundSomethingAfterSequence = true;
@ -404,7 +409,7 @@ void Context::parse (
(*arg)[0] == '-' &&
validTag (*arg))
{
header ("parse tag removal '" + *arg + "'");
debug ("parse tag removal '" + *arg + "'");
if (foundSequence)
foundSomethingAfterSequence = true;
@ -418,7 +423,7 @@ void Context::parse (
// Atributes - name[.mod]:[value]
else if (attribute.valid (*arg))
{
header ("parse attribute '" + *arg + "'");
debug ("parse attribute '" + *arg + "'");
if (foundSequence)
foundSomethingAfterSequence = true;
@ -456,7 +461,7 @@ void Context::parse (
if (foundSequence)
foundSomethingAfterSequence = true;
header ("parse subst '" + *arg + "'");
debug ("parse subst '" + *arg + "'");
parseSubst.parse (*arg);
}
@ -464,7 +469,7 @@ void Context::parse (
else if (parseCmd.command == "" &&
parseCmd.valid (*arg))
{
header ("parse cmd '" + *arg + "'");
debug ("parse cmd '" + *arg + "'");
parseCmd.parse (*arg);
if (foundSequence)
@ -486,7 +491,7 @@ void Context::parse (
// terminated, therefore everything subsequently is a description.
else
{
header ("parse post-termination description '" + *arg + "'");
debug ("parse post-termination description '" + *arg + "'");
if (foundSequence)
foundSomethingAfterSequence = true;
@ -498,7 +503,7 @@ void Context::parse (
if (descCandidate != "" && noVerticalSpace (descCandidate))
{
header ("parse description '" + descCandidate + "'");
debug ("parse description '" + descCandidate + "'");
parseTask.set ("description", descCandidate);
}
@ -603,6 +608,12 @@ void Context::footnote (const std::string& input)
footnotes.push_back (input);
}
////////////////////////////////////////////////////////////////////////////////
void Context::debug (const std::string& input)
{
debugMessages.push_back (input);
}
////////////////////////////////////////////////////////////////////////////////
void Context::clearMessages ()
{

View file

@ -55,6 +55,7 @@ public:
void header (const std::string&); // Header sink
void message (const std::string&); // Message sink
void footnote (const std::string&); // Footnote sink
void debug (const std::string&); // Debug message sink
void clearMessages ();
void parse ();
@ -83,6 +84,7 @@ private:
std::vector <std::string> headers;
std::vector <std::string> messages;
std::vector <std::string> footnotes;
std::vector <std::string> debugMessages;
bool inShadow;
};

View file

@ -389,8 +389,6 @@ int TDB::gc ()
{
int count = 0;
context.header ("gc");
// Set up a second TDB.
Filter filter;
TDB tdb;
@ -443,6 +441,9 @@ int TDB::gc ()
// Close files.
tdb.unlock ();
std::stringstream s;
s << "gc " << count << " tasks";
context.debug (s.str ());
return count;
}

View file

@ -380,15 +380,15 @@ std::string handleVersion ()
std::string recognized =
" blanklines color color.active color.due color.overdue color.pri.H "
"color.pri.L color.pri.M color.pri.none color.recurring color.tagged "
"color.footnote color.message confirmation curses data.location dateformat "
"default.command default.priority defaultwidth displayweeknumber due "
"echo.command locale locking monthsperline nag next project shadow.command "
"shadow.file shadow.notify weekstart editor import.synonym.id "
"import.synonym.uuid import.synonym.status import.synonym.tags "
"import.synonym.entry import.synonym.start import.synonym.due "
"import.synonym.recur import.synonym.end import.synonym.project "
"import.synonym.priority import.synonym.fg import.synonym.bg "
"import.synonym.description ";
"color.footnote color.header color.message color.debug confirmation curses "
"data.location dateformat default.command default.priority defaultwidth "
"displayweeknumber due echo.command locale locking monthsperline nag next "
"project shadow.command shadow.file shadow.notify weekstart editor "
"import.synonym.id import.synonym.uuid import.synonym.status "
"import.synonym.tags import.synonym.entry import.synonym.start "
"import.synonym.due import.synonym.recur import.synonym.end "
"import.synonym.project import.synonym.priority import.synonym.fg "
"import.synonym.bg import.synonym.description ";
// This configuration variable is supported, but not documented. It exists
// so that unit tests can force color to be on even when the output from task

View file

@ -105,6 +105,7 @@ void autoColorize (Task&, Text::color&, Text::color&);
std::string colorizeHeader (const std::string&);
std::string colorizeMessage (const std::string&);
std::string colorizeFootnote (const std::string&);
std::string colorizeDebug (const std::string&);
// import.cpp
std::string handleImport ();

View file

@ -281,4 +281,19 @@ std::string colorizeFootnote (const std::string& input)
}
////////////////////////////////////////////////////////////////////////////////
std::string colorizeDebug (const std::string& input)
{
if (gsFg["debug.footnote"] != Text::nocolor ||
gsBg["debug.footnote"] != Text::nocolor)
{
return Text::colorize (
gsFg["debug.footnote"],
gsBg["debug.footnote"],
input);
}
return input;
}
////////////////////////////////////////////////////////////////////////////////