From 4ec8fa5f7d1ffb836514f730d1a717fe269c4a94 Mon Sep 17 00:00:00 2001 From: Tiziano Zito Date: Fri, 16 Nov 2018 12:49:33 +0100 Subject: [PATCH 1/2] add highlighting of dates, item numbers, and metadata --- todo.cfg | 9 ++++++++- todo.sh | 25 +++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/todo.cfg b/todo.cfg index 6c6f8673..886a5335 100644 --- a/todo.cfg +++ b/todo.cfg @@ -62,10 +62,17 @@ export REPORT_FILE="$TODO_DIR/report.txt" # # export COLOR_DONE=$LIGHT_GREY -# There is highlighting for projects and contexts. +# There is highlighting for projects, contexts, dates, and item numbers. # # export COLOR_PROJECT=$RED # export COLOR_CONTEXT=$RED +# export COLOR_DATE=$BLUE +# export COLOR_NUMBER=$LIGHT_GRAY + +# There is highlighting for metadata key:value pairs e.g. +# DUE:2006-08-01 or note:MYNOTE +# +# export COLOR_META=$CYAN # === BEHAVIOR === diff --git a/todo.sh b/todo.sh index df566407..d46db5e1 100755 --- a/todo.sh +++ b/todo.sh @@ -644,9 +644,12 @@ export PRI_B=$GREEN # color for B priority export PRI_C=$LIGHT_BLUE # color for C priority export PRI_X=$WHITE # color unless explicitly defined -# Default project and context colors. +# Default project, context, date, item number, and metadata key:value pairs colors. export COLOR_PROJECT=$NONE export COLOR_CONTEXT=$NONE +export COLOR_DATE=$NONE +export COLOR_NUMBER=$NONE +export COLOR_META=$NONE # Default highlight colors. export COLOR_DONE=$LIGHT_GREY # color for done (but not yet archived) tasks @@ -789,6 +792,9 @@ if [ $TODOTXT_PLAIN = 1 ]; then COLOR_DONE=$NONE COLOR_PROJECT=$NONE COLOR_CONTEXT=$NONE + COLOR_DATE=$NONE + COLOR_NUMBER=$NONE + COLOR_META=$NONE fi [[ "$HIDE_PROJECTS_SUBSTITUTION" ]] && COLOR_PROJECT="$NONE" @@ -964,15 +970,30 @@ _format() ctx_beg = highlight("COLOR_CONTEXT") ctx_end = (ctx_beg ? (highlight("DEFAULT") clr) : "") + dat_beg = highlight("COLOR_DATE") + dat_end = (dat_beg ? (highlight("DEFAULT") clr) : "") + + num_beg = highlight("COLOR_NUMBER") + num_end = (num_beg ? (highlight("DEFAULT") clr) : "") + + met_beg = highlight("COLOR_META") + met_end = (met_beg ? (highlight("DEFAULT") clr) : "") + gsub(/[ \t][ \t]*/, "\n&\n") len = split($0, words, /\n/) printf "%s", clr for (i = 1; i <= len; ++i) { - if (words[i] ~ /^[+].*[A-Za-z0-9_]$/) { + if (i == 1 && words[i] ~ /^[0-9]+$/ ) { + printf "%s", num_beg words[i] num_end + } else if (words[i] ~ /^[+].*[A-Za-z0-9_]$/) { printf "%s", prj_beg words[i] prj_end } else if (words[i] ~ /^[@].*[A-Za-z0-9_]$/) { printf "%s", ctx_beg words[i] ctx_end + } else if (words[i] ~ /^(19|20)[0-9]{2}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/) { + printf "%s", dat_beg words[i] dat_end + } else if (words[i] ~ /^[[:alnum:]]+:[^ ]+$/) { + printf "%s", met_beg words[i] met_end } else { printf "%s", words[i] } From 4aedf4eb3bc70e3504670c2363fd1bd911e36c6f Mon Sep 17 00:00:00 2001 From: Tiziano Zito Date: Fri, 16 Nov 2018 13:45:04 +0100 Subject: [PATCH 2/2] add test for highlighting of dates, item numbers, and metadata --- ...80-ls-date-number-metadata-highlighting.sh | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 tests/t1380-ls-date-number-metadata-highlighting.sh diff --git a/tests/t1380-ls-date-number-metadata-highlighting.sh b/tests/t1380-ls-date-number-metadata-highlighting.sh new file mode 100755 index 00000000..dcfc4938 --- /dev/null +++ b/tests/t1380-ls-date-number-metadata-highlighting.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# + +test_description='highlighting date, item numbers and metadata + +This test checks the highlighting (with colors) of dates, item numbers and metadata +' +. ./test-lib.sh + +# Tasks with dates and metadata +cat > todo.txt < "$TEST_TODO_LABEL_COLORS" + +echo "export COLOR_DATE='\\\\033[0;31m'" >>"$TEST_TODO_LABEL_COLORS" +echo "export COLOR_META='\\\\033[0;32m'" >>"$TEST_TODO_LABEL_COLORS" +echo "export COLOR_NUMBER='\\\\033[0;34m'" >>"$TEST_TODO_LABEL_COLORS" + +test_todo_session 'highlighting for date, item numbers and metadata' <<'EOF' +>>> todo.sh -d "$TEST_TODO_LABEL_COLORS" ls +1 2018-11-11 task with date +2 task with metadata due:2018-12-31 +3 task without date and without metadata +-- +TODO: 3 of 3 tasks shown +EOF + + +test_todo_session 'suppressing highlighting for date, item numbers and metadata' <<'EOF' +>>> todo.sh -p -d "$TEST_TODO_LABEL_COLORS" ls +1 2018-11-11 task with date +2 task with metadata due:2018-12-31 +3 task without date and without metadata +-- +TODO: 3 of 3 tasks shown +EOF + +test_done