Enhancements - Context integration

- Context now gathers messages and footnotes.
- task now calls into the new 1.8.0 code (via Context), then calls
  into the old 1.7.0 code.  Two for the price of one.
This commit is contained in:
Paul Beckingham 2009-06-04 22:14:03 -04:00
parent 024986fe88
commit 54f155f439
4 changed files with 62 additions and 19 deletions

View file

@ -25,6 +25,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
@ -127,18 +128,53 @@ void Context::initialize (int argc, char** argv)
////////////////////////////////////////////////////////////////////////////////
int Context::run ()
{
// TODO Dispatch to command handlers.
// TODO Auto shadow update.
// TODO Auto gc.
// TODO tdb.load (Filter);
std::cout << "--- start 1.8.0 ---" << std::endl;
try
{
parse ();
throw std::string ("unimplemented Context::run");
// TODO Dispatch to command handlers.
// TODO Auto shadow update.
// TODO Auto gc.
// TODO tdb.load (Filter);
}
catch (const std::string& error)
{
messages.push_back (error);
}
catch (...)
{
messages.push_back (stringtable.get (100, "Unknown error."));
}
// Dump all messages.
foreach (m, messages)
std::cout << *m << std::endl;
if (footnotes.size ())
{
std::cout << std::endl;
foreach (f, footnotes)
std::cout << *f << std::endl;
}
std::cout << "--- end 1.8.0 ---" << std::endl;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int Context::interactive ()
{
// TODO init ncurses
// TODO create worker thread
// TODO create refresh thread
// TODO join refresh thread
// TODO join worker thread
// TODO take down ncurses
throw std::string ("unimplemented Context::interactive");
return 0;
}
@ -172,3 +208,10 @@ void Context::loadCorrectConfigFile (int argc, char** argv)
}
////////////////////////////////////////////////////////////////////////////////
void Context::parse ()
{
// TODO Replace parse.cpp:parse
throw std::string ("unimplemented Context::parse");
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -43,12 +43,16 @@ public:
Context& operator= (const Context&); // Assignment operator
~Context (); // Destructor
void initialize (int, char**);
int run ();
int interactive ();
void initialize (int, char**); // all startup
int run (); // task classic
int interactive (); // task interactive (not implemented)
void message (const std::string&); // Message sink
void footnote (const std::string&); // Footnote sink
private:
void loadCorrectConfigFile (int, char**);
void parse ();
public:
Config config;
@ -60,6 +64,8 @@ public:
StringTable stringtable;
private:
std::vector <std::string> messages;
std::vector <std::string> footnotes;
};
#endif

View file

@ -297,16 +297,9 @@ int main (int argc, char** argv)
try
{
context.initialize (argc, argv);
/* return */ context.run ();
// When redirecting output to a file, do not use color, curses.
if (!isatty (fileno (stdout)))
{
context.config.set ("curses", "off");
if (! context.config.get (std::string ("_forcecolor"), false))
context.config.set ("color", "off");
}
// start OBSOLETE
TDB tdb;
std::string dataLocation = expandPath (context.config.get ("data.location"));
tdb.dataDirectory (dataLocation);
@ -342,6 +335,7 @@ int main (int argc, char** argv)
std::cerr << context.stringtable.get (100, "Unknown error.") << std::endl;
return -2;
}
// end OBSOLETE
return 0;
}

View file

@ -37,10 +37,10 @@ int main (int argc, char** argv)
T2 t;
t.addTag ("tag1");
t.addTag ("tag2");
test.is (t.composeF4 (), "[tag:\"tag1&commatag2\" uuid:\"...\"]", "T2::addTag");
test.is (t.composeF4 (), "[tags:\"tag1&comma;tag2\" uuid:\"...\"]", "T2::addTag");
T2 t2 (t.composeF4 ());
test.is (t2.composeF4 (), "[tag:\"tag1&commatag2\" uuid:\"...\"]", "T2::composeF4 -> parse round trip");
test.is (t2.composeF4 (), "[tags:\"tag1&comma;tag2\" uuid:\"...\"]", "T2::composeF4 -> parse round trip");
// Round-trip testing.
T2 t3;