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:
45
tests/t1380-ls-date-number-metadata-highlighting.sh
Executable file
45
tests/t1380-ls-date-number-metadata-highlighting.sh
Executable file
@@ -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 <<EOF
|
||||
2018-11-11 task with date
|
||||
task with metadata due:2018-12-31
|
||||
task without date and without metadata
|
||||
EOF
|
||||
|
||||
# config file specifying COLOR_PROJECT and COLOR_CONTEXT
|
||||
#
|
||||
TEST_TODO_LABEL_COLORS=todo-colors.cfg
|
||||
cat todo.cfg > "$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
|
||||
[0;34m1[0m [0;31m2018-11-11[0m task with date
|
||||
[0;34m2[0m task with metadata [0;32mdue:2018-12-31[0m
|
||||
[0;34m3[0m 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
|
||||
9
todo.cfg
9
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 ===
|
||||
|
||||
|
||||
25
todo.sh
25
todo.sh
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user