From ce501c5362963a98a8d26fa0d4309e9c166a2958 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 21 Oct 2010 11:30:31 +0200 Subject: [PATCH] BUG: interpretation of \033 escape sequences in task The global substitution in the AWK highlighting of prioritized and done tasks also affected the task text itself, not just the inserted color definitions. Factored out the evaluation of the color variables and interpretation of \033 into a highlight() AWK function. Added test cases which check that \a, \t, \n, \x.. and \0.. escape characters in the task text are listed as-is, without interpretation. --- tests/t1340-listescapes.sh | 36 ++++++++++++++++++++++++++++++++++++ todo.sh | 27 ++++++++++++++++----------- 2 files changed, 52 insertions(+), 11 deletions(-) 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