(* Implement 'list' subcommand. *) open CalendarLib open Todo_types open Todo_utils open Todo_tag_utils open Printf 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 = $taskid and tags_tasks.tagid = tags.id order by tags.name" in 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 error "extra parameters to 'list' subcommand"; let show_unretired, show_retired = match list_retired, list_all with | _, true -> true, true | false, false -> true, false | true, false -> false, true in if show_unretired then ( 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, rhbz, desc) -> print_task dbh id ?rhbz desc ) rows; let rows = PGSQL(dbh) "select todo.taskid, todo.deadline, todo.estimate, tasks.rhbz, tasks.description from todo, tasks where todo.taskid = tasks.id order by todo.deadline, tasks.description" in if rows <> [] then heading "To-do list"; List.iter ( fun (id, deadline, estimate, rhbz, desc) -> print_task dbh id ?rhbz ~deadline ?estimate desc ) rows; let rows = PGSQL(dbh) " 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) 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 heading "Unsorted (use 'todo move' to move these)"; List.iter ( fun (id, rhbz, desc) -> print_task dbh id ?rhbz desc ) rows; 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, rhbz, desc) -> print_task dbh id ?rhbz desc ) rows ); (* unretired *) if show_retired then ( 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, rhbz, desc) -> print_task dbh id ?rhbz desc ) rows )