Highlighting of dates, metadata and item numbers (#264)

* add highlighting of dates, item numbers, and metadata

* add test for highlighting of dates, item numbers, and metadata

Co-authored-by: Ali Karbassi <ali@karbassi.com>
This commit is contained in:
Tiziano Zito
2020-03-29 21:20:06 +02:00
committed by GitHub
parent 20317b6321
commit 355166da67
3 changed files with 76 additions and 3 deletions

25
todo.sh
View File

@@ -650,9 +650,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
@@ -795,6 +798,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"
@@ -971,15 +977,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]
}