diff --git a/tests/t1340-listescapes.sh b/tests/t1340-listescapes.sh index b4be9db..e0682c3 100755 --- a/tests/t1340-listescapes.sh +++ b/tests/t1340-listescapes.sh @@ -7,6 +7,10 @@ This test checks listing of tasks that have embedded escape sequences in them. ' . ./test-lib.sh +# Note: The quadrupled escaped backslashes (even 8-fold for the escape color +# code) in the expected output are necessary due to (superfluous?!) +# interpretation of the expected output in the test library itself. + # # check aborted list output on \c escape sequence # @@ -30,4 +34,36 @@ TODO: 3 of 3 tasks shown TODO: 1 of 3 tasks shown EOF +# +# check various escape sequences +# +cat > todo.txt <<'EOF' +first todo with \\, \a and \t +second todo with \r\n line break +third todo with \x42\x55\x47 and \033[0;31m color codes \033[0;30m +EOF + +test_todo_session 'various escape sequences' <<'EOF' +>>> todo.sh ls +1 first todo with \\\\\\\\, \\\\a and \\\\t +2 second todo with \\\\r\\\\n line break +3 third todo with \\\\x42\\\\x55\\\\x47 and \\\\\\\\033[0;31m color codes \\\\\\\\033[0;30m +-- +TODO: 3 of 3 tasks shown +EOF + +# +# check embedding of actual color sequence +# +cat > todo.txt <<'EOF' +A task with  actual color  +EOF + +test_todo_session 'embedding of actual color sequence' <<'EOF' +>>> todo.sh ls +1 A task with  actual color  +-- +TODO: 1 of 1 tasks shown +EOF + test_done diff --git a/todo.sh b/todo.sh index c47b9a1..99320c9 100755 --- a/todo.sh +++ b/todo.sh @@ -636,17 +636,22 @@ _list() { s/^ /0/; ''' \ | eval ${TODOTXT_SORT_COMMAND} \ - | awk '''{ - pos = match($0, /\([A-Z]\)/) - if (match($0, /^[0-9]+ x /)) { - str = ENVIRON["COLOR_DONE"] $0 ENVIRON["DEFAULT"] - gsub(/\\+033/, "\033", str); print str - } else if (pos > 0) { - clr = ENVIRON["PRI_" substr($0, pos+1, 1)] - str = ( clr ? clr : ENVIRON["PRI_X"] ) $0 ENVIRON["DEFAULT"] - gsub(/\\+033/, "\033", str); print str - } else { print } - }''' \ + | awk ''' + function highlight(colorVar, color) { + color = ENVIRON[colorVar] + gsub(/\\+033/, "\033", color) + return color + } + { + pos = match($0, /\([A-Z]\)/) + if (match($0, /^[0-9]+ x /)) { + print highlight("COLOR_DONE") $0 highlight("DEFAULT") + } else if (pos > 0) { + clr = highlight("PRI_" substr($0, pos+1, 1)) + print ( clr ? clr : highlight("PRI_X") ) $0 highlight("DEFAULT") + } else { print } + } + ''' \ | sed ''' s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g