Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting of dates, metadata and item numbers #264

Merged
merged 3 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/t1380-ls-date-number-metadata-highlighting.sh
Original file line number Diff line number Diff line change
@@ -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
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
9 changes: 8 additions & 1 deletion todo.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===

Expand Down
25 changes: 23 additions & 2 deletions todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]
}
Expand Down