Consistent colour printing of headings, task descriptions and IDs.
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 15 Nov 2016 19:26:14 +0000 (19:26 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 15 Nov 2016 19:26:14 +0000 (19:26 +0000)
todo_list.ml
todo_tag.ml
todo_utils.ml

index 0ba1a1a..93d7b85 100644 (file)
@@ -38,10 +38,12 @@ let cmd_list dbh anon_params list_retired list_all =
                              from imminent, tasks
                             where imminent.taskid = tasks.id
                          order by tasks.description" in
-    if rows <> [] then printf "Today:\n";
+    if rows <> [] then heading "Today";
     List.iter (
       fun (id, desc) ->
-        printf "    %s #%ld%s\n" desc id (tags_of_task dbh id)
+        printf "    %s %s%s\n"
+               (string_of_task_desc desc) (string_of_taskid id)
+               (tags_of_task dbh id)
     ) rows;
 
     let rows = PGSQL(dbh) "select todo.taskid, todo.deadline, todo.estimate,
@@ -49,7 +51,7 @@ let cmd_list dbh anon_params list_retired list_all =
                              from todo, tasks
                             where todo.taskid = tasks.id
                          order by todo.deadline" in
-    if rows <> [] then printf "To-do list:\n";
+    if rows <> [] then heading "To-do list";
     List.iter (
       fun (id, deadline, estimate, desc) ->
         let deadline =
@@ -61,8 +63,9 @@ let cmd_list dbh anon_params list_retired list_all =
           match estimate with
           | None -> ""
           | Some period -> string_of_estimate period ^ " " in
-        printf "    %s %s%s #%ld%s\n"
-               deadline estimate desc id (tags_of_task dbh id)
+        printf "    %s %s%s %s%s\n"
+               deadline estimate (string_of_task_desc desc)
+               (string_of_taskid id) (tags_of_task dbh id)
     ) rows;
 
     let rows = PGSQL(dbh) "
@@ -73,20 +76,24 @@ let cmd_list dbh anon_params list_retired list_all =
            and not exists (select 1 from ideas where taskid = tasks.id)
            and not exists (select 1 from retired where taskid = tasks.id)
       order by tasks.description" in
-    if rows <> [] then printf "Unsorted (use 'todo move' to move these):\n";
+    if rows <> [] then heading "Unsorted (use 'todo move' to move these)";
     List.iter (
       fun (id, desc) ->
-        printf "    %s #%ld%s\n" desc id (tags_of_task dbh id)
+        printf "    %s %s%s\n"
+               (string_of_task_desc desc) (string_of_taskid id)
+               (tags_of_task dbh id)
     ) rows;
 
     let rows = PGSQL(dbh) "select ideas.taskid, tasks.description
                              from ideas, tasks
                             where ideas.taskid = tasks.id
                          order by tasks.description" in
-    if rows <> [] then printf "Ideas:\n";
+    if rows <> [] then heading "Ideas";
     List.iter (
       fun (id, desc) ->
-        printf "    %s #%ld%s\n" desc id (tags_of_task dbh id)
+        printf "    %s %s%s\n"
+               (string_of_task_desc desc) (string_of_taskid id)
+               (tags_of_task dbh id)
     ) rows
   ); (* unretired *)
 
@@ -95,9 +102,11 @@ let cmd_list dbh anon_params list_retired list_all =
                              from retired, tasks
                             where retired.taskid = tasks.id
                          order by tasks.description" in
-    if rows <> [] then printf "Retired:\n";
+    if rows <> [] then heading "Retired";
     List.iter (
       fun (id, desc) ->
-        printf "    %s #%ld%s\n" desc id (tags_of_task dbh id)
+        printf "    %s %s%s\n"
+               (string_of_task_desc desc) (string_of_taskid id)
+               (tags_of_task dbh id)
     ) rows
   )
index a4ab5a5..8d3ae9c 100644 (file)
@@ -19,7 +19,7 @@ let cmd_tag_list dbh anon_params =
         where tags_tasks.tagid = tags.id
           and tags_tasks.taskid = tasks.id
      order by tags.name, tasks.id" in
-  if rows <> [] then printf "Tags used:\n";
+  if rows <> [] then heading "Tags used";
   let prev = ref None in
   List.iter (
     fun (name, colour, taskid) ->
@@ -31,7 +31,7 @@ let cmd_tag_list dbh anon_params =
       | Some _ -> ()
       );
       prev := Some cur;
-      printf " #%ld" taskid
+      printf " %s" (string_of_taskid taskid)
   ) rows;
   if !prev <> None then printf "\n";
 
@@ -41,7 +41,7 @@ let cmd_tag_list dbh anon_params =
          from tags
         where not exists (select 1 from tags_tasks where tagid = tags.id)
      order by tags.name" in
-  if rows <> [] then printf "Tags not used (delete with 'todo tag-del'):\n";
+  if rows <> [] then heading "Tags not used (delete with 'todo tag-del')";
   List.iter (
     fun (name, colour) ->
       printf "    %s\n" (string_of_tag name colour)
index 27f13dd..872cfc7 100644 (file)
@@ -59,3 +59,15 @@ let string_of_estimate period =
   else if days = 1 then append "1 day";
   let str = Buffer.contents buf in
   if str <> "" then str else "-"
+
+let heading fs =
+  let display str =
+    printf "\x1b[%d;%dm%s:\x1b[0m\n" 0 35 str
+  in
+  ksprintf display fs
+
+let string_of_taskid id =
+  sprintf "\x1b[%d;%dm#%ld\x1b[0m" 1 34 id
+
+let string_of_task_desc desc =
+  sprintf "\x1b[1m%s\x1b[0m" desc