Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Suggested improvement for sticky-note



On Sat, May 1, 2021 at 12:19 PM vapnik spaknik <vapniks@xxxxxxxxx> wrote:
>
> Hi,
>     it's fun & useful to be able to display sticky notes in blinking text, or different colours, to make them stand out or colour code them.
> The attached diff implements that feature by adding the -b option to print.

First, thanks for the suggestion, the comment inviting improvements
was written in 2008 and I think this is the first time anyone actually
sent one.

Second, a couple of meta-notes:
* Please send patches in unified diff (diff -u) format, or use "git
diff" or "git send-email" if you have a checked-out source tree.
* Attached patches should be content-type text/plain and preferably
use a ".txt" file extension so they can easily be read in the email
itself, rather than fed to an external viewer (which in the case of
".diff" might attempt to apply the patch).

Third, this is the sort of thing that ought to be customizable.  So,
how about the attached, which adds an "escapes" style?
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


Messages sorted by: Reverse Date, Date, Thread, Author