open Printf
-let tags_of_task dbh id =
+let print_task dbh taskid ?rhbz ?deadline ?estimate description =
+ let cols = ref 0 in
+ printf " •";
+ cols := !cols + 3;
+
+ (match deadline with
+ | None -> ()
+ | Some deadline ->
+ let deadline =
+ if Time.equal (Time.midnight ()) (Calendar.to_time deadline) then
+ Printer.Calendar.sprint "%F" deadline
+ else
+ Printer.Calendar.to_string deadline in
+ let deadline = " " ^ deadline in
+ printf "%s" deadline;
+ cols := !cols + String.length deadline
+ );
+
+ (match estimate with
+ | None -> ()
+ | Some period ->
+ let estimate = " " ^ string_of_estimate period in
+ printf "%s" estimate;
+ cols := !cols + String.length estimate
+ );
+
+ (match rhbz with
+ | None -> ()
+ | Some rhbz ->
+ printf " https://bugzilla.redhat.com/%ld\n " rhbz;
+ cols := 3
+ );
+
+ printf " %s" (string_of_task_desc description);
+ cols := !cols + String.length description + 1;
+
+ let taskid_len = String.length (sprintf "#%ld" taskid) in
+ if !cols + taskid_len >= 78 then (
+ printf "\n ";
+ cols := 3
+ );
+ printf " %s" (string_of_taskid taskid);
+ cols := !cols + taskid_len + 1;
+
let rows = PGSQL(dbh) "select tags.name, tags.colour
from tags_tasks, tags
- where tags_tasks.taskid = $id
+ where tags_tasks.taskid = $taskid
and tags_tasks.tagid = tags.id
order by tags.name" in
- if rows = [] then ""
- else
- " " ^
- String.concat " "
- (List.map (
- fun (name, colour) ->
- string_of_tag name colour
- ) rows)
+ List.iter (
+ fun (name, colour) ->
+ let len = String.length name + 2 in
+ if !cols + len >= 78 then (
+ printf "\n ";
+ cols := 3
+ );
+ printf " %s" (string_of_tag name colour);
+ cols := !cols + len + 1;
+ ) rows;
+ printf "\n"
let cmd_list dbh anon_params list_retired list_all =
if anon_params <> [] then
| true, false -> false, true in
if show_unretired then (
- let rows = PGSQL(dbh) "select imminent.taskid, tasks.description
+ let rows = PGSQL(dbh) "select imminent.taskid, tasks.rhbz, tasks.description
from imminent, tasks
where imminent.taskid = tasks.id
order by tasks.description" in
if rows <> [] then heading "Today";
List.iter (
- fun (id, desc) ->
- printf " %s %s%s\n"
- (string_of_task_desc desc) (string_of_taskid id)
- (tags_of_task dbh id)
+ fun (id, rhbz, desc) ->
+ print_task dbh id ?rhbz desc
) rows;
let rows = PGSQL(dbh) "select todo.taskid, todo.deadline, todo.estimate,
- tasks.description
+ tasks.rhbz, tasks.description
from todo, tasks
where todo.taskid = tasks.id
- order by todo.deadline" in
+ order by todo.deadline, tasks.description" in
if rows <> [] then heading "To-do list";
List.iter (
- fun (id, deadline, estimate, desc) ->
- let deadline =
- if Time.equal (Time.midnight ()) (Calendar.to_time deadline) then
- Printer.Calendar.sprint "%F" deadline
- else
- Printer.Calendar.to_string deadline in
- let estimate =
- match estimate with
- | None -> ""
- | Some period -> string_of_estimate period ^ " " in
- printf " %s %s%s %s%s\n"
- deadline estimate (string_of_task_desc desc)
- (string_of_taskid id) (tags_of_task dbh id)
+ fun (id, deadline, estimate, rhbz, desc) ->
+ print_task dbh id ?rhbz ~deadline ?estimate desc
) rows;
let rows = PGSQL(dbh) "
- select tasks.id, tasks.description
+ select tasks.id, tasks.rhbz, tasks.description
from tasks
where not exists (select 1 from imminent where taskid = tasks.id)
and not exists (select 1 from todo where taskid = tasks.id)
order by tasks.description" in
if rows <> [] then heading "Unsorted (use 'todo move' to move these)";
List.iter (
- fun (id, desc) ->
- printf " %s %s%s\n"
- (string_of_task_desc desc) (string_of_taskid id)
- (tags_of_task dbh id)
+ fun (id, rhbz, desc) ->
+ print_task dbh id ?rhbz desc
) rows;
- let rows = PGSQL(dbh) "select ideas.taskid, tasks.description
+ let rows = PGSQL(dbh) "select ideas.taskid, tasks.rhbz, tasks.description
from ideas, tasks
where ideas.taskid = tasks.id
order by tasks.description" in
if rows <> [] then heading "Ideas";
List.iter (
- fun (id, desc) ->
- printf " %s %s%s\n"
- (string_of_task_desc desc) (string_of_taskid id)
- (tags_of_task dbh id)
+ fun (id, rhbz, desc) ->
+ print_task dbh id ?rhbz desc
) rows
); (* unretired *)
if show_retired then (
- let rows = PGSQL(dbh) "select retired.taskid, tasks.description
+ let rows = PGSQL(dbh) "select retired.taskid, tasks.rhbz, tasks.description
from retired, tasks
where retired.taskid = tasks.id
order by tasks.description" in
if rows <> [] then heading "Retired";
List.iter (
- fun (id, desc) ->
- printf " %s %s%s\n"
- (string_of_task_desc desc) (string_of_taskid id)
- (tags_of_task dbh id)
+ fun (id, rhbz, desc) ->
+ print_task dbh id ?rhbz desc
) rows
)