diff --git a/Functions/Misc/sticky-note b/Functions/Misc/sticky-note index efe5ec1eb..ad4fc30e5 100644 --- a/Functions/Misc/sticky-note +++ b/Functions/Misc/sticky-note @@ -21,7 +21,7 @@ # as an editor history. Two quick taps on the return/enter key finish # the note, or you can use ^X^W as usual (ZZ in vicmd mode). -# The application is configured by three zstyles, all using the context +# The application is configured by four zstyles, all using the context # ":sticky-note". The first two styles are "notefile" and "maxnotes" # to name the file in which notes are stored and the maximum number of # notes to retain: @@ -42,6 +42,17 @@ # bg red \ # fg $fg_bold[yellow] +# Finally the "escapes" style may be used to control the intepretation of +# of character sequences such as '\Cx' and '%B' in the content of each +# note. The style may be set to either one or two strings: +# none => no interpretation, other strings in the value are ignored +# echo => escape sequences of the "echo" command are interpreted +# bindkey => escapes of the "bindkey" command are interpreted +# prompt => interpret prompt escapes, may be paired with echo or bindkey +# The default is "echo" for compatibility with previous versions. Note +# that use of some escape sequences may garble the display, or clash +# with the "theme" style. + # For backwards compatibility with an earlier version, the notefile may # also be named by the STICKYFILE variable (defaults to $HOME/.zsticky). # The number of notes stored may be given by STICKYSIZE (1000). @@ -74,6 +85,21 @@ fi [[ "$1" == -b ]] && return 0 +# Set escape handling +local -a escapes prop +if zstyle -a :sticky-note escapes escapes +then + prop=(-r) + if [[ $escapes != *none* ]] + then + case $escapes in + (*bindkey*) prop=({$prop/-r/-b});; + (*echo*) prop=(${prop/-r/});; + esac + [[ $escapes = *prompt* ]] && prop+=(-P) + fi +fi + # Look up color theme local -A theme (($+bg && $+fg)) || { autoload -Uz colors; colors } @@ -96,7 +122,7 @@ then echoti sc echoti home print -nr "$theme[color]" - fc -l "${@:--1}" | while read -r sticky; do print -- "$sticky"; done + fc -l "${@:--1}" | while read -r sticky; do print $prop -- "$sticky"; done print -nr "$theme[reset]" echoti rc elif [[ $CONTEXT = (cont|select|vared) ]] @@ -120,7 +146,7 @@ if [[ "$*" == -*l* ]] then print -nr "$theme[color]" # Use read/print loop to interpolate "\n" in history lines - fc -f "$@" | while read -r sticky; do print -- "$sticky"; done + fc -f "$@" | while read -r sticky; do print $prop -- "$sticky"; done print -nr "$theme[reset]" return 0 fi @@ -129,7 +155,7 @@ fi while vared -h -p "%{$theme[color]%}" -M sticky -m sticky-vicmd sticky do { - [[ -n "$sticky" ]] && print -s -- "$sticky" + [[ -n "$sticky" ]] && print -rs -- "$sticky" } always { (( TRY_BLOCK_ERROR = 0 )) } && break