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.
This commit is contained in:
@@ -7,6 +7,10 @@ This test checks listing of tasks that have embedded escape sequences in them.
|
|||||||
'
|
'
|
||||||
. ./test-lib.sh
|
. ./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
|
# check aborted list output on \c escape sequence
|
||||||
#
|
#
|
||||||
@@ -30,4 +34,36 @@ TODO: 3 of 3 tasks shown
|
|||||||
TODO: 1 of 3 tasks shown
|
TODO: 1 of 3 tasks shown
|
||||||
EOF
|
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 [0;31m actual color [0;30m
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'embedding of actual color sequence' <<'EOF'
|
||||||
|
>>> todo.sh ls
|
||||||
|
1 A task with [0;31m actual color [0;30m
|
||||||
|
--
|
||||||
|
TODO: 1 of 1 tasks shown
|
||||||
|
EOF
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
27
todo.sh
27
todo.sh
@@ -636,17 +636,22 @@ _list() {
|
|||||||
s/^ /0/;
|
s/^ /0/;
|
||||||
''' \
|
''' \
|
||||||
| eval ${TODOTXT_SORT_COMMAND} \
|
| eval ${TODOTXT_SORT_COMMAND} \
|
||||||
| awk '''{
|
| awk '''
|
||||||
pos = match($0, /\([A-Z]\)/)
|
function highlight(colorVar, color) {
|
||||||
if (match($0, /^[0-9]+ x /)) {
|
color = ENVIRON[colorVar]
|
||||||
str = ENVIRON["COLOR_DONE"] $0 ENVIRON["DEFAULT"]
|
gsub(/\\+033/, "\033", color)
|
||||||
gsub(/\\+033/, "\033", str); print str
|
return color
|
||||||
} else if (pos > 0) {
|
}
|
||||||
clr = ENVIRON["PRI_" substr($0, pos+1, 1)]
|
{
|
||||||
str = ( clr ? clr : ENVIRON["PRI_X"] ) $0 ENVIRON["DEFAULT"]
|
pos = match($0, /\([A-Z]\)/)
|
||||||
gsub(/\\+033/, "\033", str); print str
|
if (match($0, /^[0-9]+ x /)) {
|
||||||
} else { print }
|
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 '''
|
| sed '''
|
||||||
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
|
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
|
||||||
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||||
|
|||||||
Reference in New Issue
Block a user