From d2ddbd130344787975c84684cf3a0479d1ab3e1a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 15 Nov 2016 19:26:14 +0000 Subject: [PATCH] Consistent colour printing of headings, task descriptions and IDs. --- todo_list.ml | 31 ++++++++++++++++++++----------- todo_tag.ml | 6 +++--- todo_utils.ml | 12 ++++++++++++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/todo_list.ml b/todo_list.ml index 0ba1a1a..93d7b85 100644 --- a/todo_list.ml +++ b/todo_list.ml @@ -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 ) diff --git a/todo_tag.ml b/todo_tag.ml index a4ab5a5..8d3ae9c 100644 --- a/todo_tag.ml +++ b/todo_tag.ml @@ -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) diff --git a/todo_utils.ml b/todo_utils.ml index 27f13dd..872cfc7 100644 --- a/todo_utils.ml +++ b/todo_utils.ml @@ -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 -- 1.8.3.1