diff --git a/ChangeLog b/ChangeLog index 8b6ef544f..b13666b5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,11 @@ ------ reality ----------------------------------- +0.9.7 + 5/17/2008 + + Task offers to create a sample ~/.taskrc file if one is not found. + + Task offers to create a ~/.task directory if one is not found. + 0.9.6 5/13/208 + Replaced color management code. diff --git a/src/.deps/Config.Po b/src/.deps/Config.Po index 2ded9a7ad..063845fc7 100644 --- a/src/.deps/Config.Po +++ b/src/.deps/Config.Po @@ -91,7 +91,7 @@ Config.o Config.o: Config.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/istream.tcc /usr/include/c++/4.0.0/fstream \ /usr/include/c++/4.0.0/i686-apple-darwin9/bits/basic_file.h \ /usr/include/c++/4.0.0/bits/fstream.tcc /usr/include/c++/4.0.0/sstream \ - /usr/include/c++/4.0.0/bits/sstream.tcc task.h \ + /usr/include/c++/4.0.0/bits/sstream.tcc /usr/include/sys/stat.h task.h \ /usr/include/c++/4.0.0/vector /usr/include/c++/4.0.0/bits/stl_vector.h \ /usr/include/c++/4.0.0/bits/stl_bvector.h \ /usr/include/c++/4.0.0/bits/vector.tcc /usr/include/c++/4.0.0/map \ @@ -366,6 +366,8 @@ Config.o Config.o: Config.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/sstream.tcc: +/usr/include/sys/stat.h: + task.h: /usr/include/c++/4.0.0/vector: diff --git a/src/Config.cpp b/src/Config.cpp index 4cf08d31a..38dcbe2ad 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "task.h" #include "Config.h" @@ -60,6 +61,67 @@ bool Config::load (const std::string& file) return false; } +//////////////////////////////////////////////////////////////////////////////// +void Config::createDefault (const std::string& file) +{ + if (confirm ( + "A configuration file could not be found in " + + file + + "\n\n" + + "Would you like a sample .taskrc created, so task can proceed?")) + { + // Determine a path to the task directory. + std::string taskDir = ""; + for (int i = file.length () - 1; i >= 0; --i) + { + if (file[i] == '/') + { + taskDir = file.substr (0, i) + "/.task"; + if (-1 == access (taskDir.c_str (), F_OK)) + mkdir (taskDir.c_str (), S_IRWXU); + break; + } + } + + if (taskDir != "") + { + FILE* out; + if (out = fopen (file.c_str (), "w")) + { + fprintf (out, "data.location=%s\n", taskDir.c_str ()); + fprintf (out, "command.logging=off\n"); + fprintf (out, "confirmation=yes\n"); + fprintf (out, "#nag=Note: try to stick to high priority tasks. See \"task next\".\n"); + fprintf (out, "next=2\n"); + fprintf (out, "curses=on\n"); + fprintf (out, "color=on\n"); + + fprintf (out, "color.overdue=red\n"); + fprintf (out, "#color.due=on yellow\n"); + fprintf (out, "#color.pri.H=on_red\n"); + fprintf (out, "#color.pri.M=on_yellow\n"); + fprintf (out, "#color.pri.L=on_green\n"); + fprintf (out, "color.active=cyan\n"); + fprintf (out, "color.tagged=yellow\n"); + + fclose (out); + + set ("data.location", taskDir); + set ("command.logging", "off"); + set ("confirmation", "yes"); + set ("next", 2); + set ("curses", "on"); + set ("color", "on"); + set ("color.overdue", "red"); + set ("color.active", "cyan"); + set ("color.tagged", "yellow"); + + std::cout << "Done." << std::endl; + } + } + } +} + //////////////////////////////////////////////////////////////////////////////// // Return the configuration value given the specified key. const std::string& Config::get (const char* key) diff --git a/src/Config.h b/src/Config.h index 8d9be30cc..82bc4ff99 100644 --- a/src/Config.h +++ b/src/Config.h @@ -17,6 +17,8 @@ public: Config (const std::string&); bool load (const std::string&); + void createDefault (const std::string&); + const std::string& get (const char*); const std::string& get (const char*, const char*); const std::string& get (const std::string&); diff --git a/src/task.cpp b/src/task.cpp index 54e55618b..517b6e699 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////////////// -// Copyright 2006 - 2008 Paul Beckingham. +// Copyright 2006 - 2008, Paul Beckingham. // All rights reserved. // // @@ -38,9 +38,9 @@ void usage (Config& conf) } #endif - table.addColumn (""); - table.addColumn (""); - table.addColumn (""); + table.addColumn (" "); + table.addColumn (" "); + table.addColumn (" "); table.setColumnJustification (0, Table::left); table.setColumnJustification (1, Table::left); @@ -180,11 +180,13 @@ void usage (Config& conf) //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { +// TODO Find out what this is, and either promote it to live code, or remove it. // std::set_terminate (__gnu_cxx::__verbose_terminate_handler); try { - // Load the config file from the home directory. + // Load the config file from the home directory. If the file cannot be + // found, offer to create a sample one. Config conf; struct passwd* pw = getpwuid (getuid ()); if (!pw) @@ -192,7 +194,8 @@ int main (int argc, char** argv) std::string home = pw->pw_dir; home += "/.taskrc"; - conf.load (home); + if (!conf.load (home)) + conf.createDefault (home); TDB tdb; tdb.dataDirectory (conf.get ("data.location"));