zsh-workers
 help / color / mirror / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: vapnik spaknik <vapniks@yahoo.com>
Cc: Zsh Hackers List <zsh-workers@zsh.org>
Subject: Re: Suggested improvement for sticky-note
Date: Sun, 2 May 2021 16:57:34 -0700
Message-ID: <CAH+w=7YSJwPwsA1D7xyVi_PoCvpVdB0Ng3OBdF+2UfAd2JeRDw@mail.gmail.com> (raw)
In-Reply-To: <1185563186.165566.1619896723304@mail.yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 991 bytes --]

On Sat, May 1, 2021 at 12:19 PM vapnik spaknik <vapniks@yahoo.com> 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?

[-- Attachment #2: sticky-note.txt --]
[-- Type: text/plain, Size: 2949 bytes --]

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

  reply	other threads:[~2021-05-02 23:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1185563186.165566.1619896723304.ref@mail.yahoo.com>
2021-05-01 19:18 ` vapnik spaknik
2021-05-02 23:57   ` Bart Schaefer [this message]
2021-05-04  2:06     ` vapnik spaknik
2021-05-09 20:50       ` Bart Schaefer
2021-05-11 10:18         ` Mikael Magnusson
2021-05-14 23:40           ` Termcap and boldface (was sticky-note) Bart Schaefer
2021-05-11 12:37         ` Suggested improvement for sticky-note vapnik spaknik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7YSJwPwsA1D7xyVi_PoCvpVdB0Ng3OBdF+2UfAd2JeRDw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=vapniks@yahoo.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git