zsh-workers
 help / color / mirror / code / Atom feed
* Suggested improvement for sticky-note
       [not found] <1185563186.165566.1619896723304.ref@mail.yahoo.com>
@ 2021-05-01 19:18 ` vapnik spaknik
  2021-05-02 23:57   ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: vapnik spaknik @ 2021-05-01 19:18 UTC (permalink / raw)
  To: Zsh Hackers List

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

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.

Joe

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sticky-note.diff --]
[-- Type: text/x-patch, Size: 427 bytes --]

99c99
<     fc -l "${@:--1}" | while read -r sticky; do print -- "$sticky"; done
---
>     fc -l "${@:--1}" | while read -r sticky; do print -b -- "$sticky"; done
123c123
<   fc -f "$@" | while read -r sticky; do print -- "$sticky"; done
---
>   fc -f "$@" | while read -r sticky; do print -b -- "$sticky"; done
132c132
<     [[ -n "$sticky" ]] && print -s -- "$sticky"
---
>     [[ -n "$sticky" ]] && print -b -s -- "$sticky"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Suggested improvement for sticky-note
  2021-05-01 19:18 ` Suggested improvement for sticky-note vapnik spaknik
@ 2021-05-02 23:57   ` Bart Schaefer
  2021-05-04  2:06     ` vapnik spaknik
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2021-05-02 23:57 UTC (permalink / raw)
  To: vapnik spaknik; +Cc: Zsh Hackers List

[-- 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Suggested improvement for sticky-note
  2021-05-02 23:57   ` Bart Schaefer
@ 2021-05-04  2:06     ` vapnik spaknik
  2021-05-09 20:50       ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: vapnik spaknik @ 2021-05-04  2:06 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Hackers List

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


> On Monday, May 3, 2021, 12:57:46 AM GMT+1, Bart Schaefer <schaefer@brasslantern.com> wrote: 

>> 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.

> Third, this is the sort of thing that ought to be customizable.  So,
> how about the attached, which adds an "escapes" style?

I actually made some changes before reading this email, after realizing that many users might not know the correct escape codes to use. 
The attached diff (against the original) adds options for selecting a background colour &/or blinking when creating a new sticky note, and automatically adds the appropriate escape codes. It also adds a help option.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sticky-note.diff --]
[-- Type: text/x-patch, Size: 3209 bytes --]

--- /gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/share/zsh/5.8/functions/sticky-note	1970-01-01 01:00:01.000000000 +0100
+++ /home/ben/.oh-my-zsh/custom/autoload/sticky-note	2021-05-02 23:45:17.021881434 +0100
@@ -49,7 +49,7 @@
 # I encourage all you creative people to contribute enhancements ...
 
 emulate -LR zsh
-setopt nobanghist extendedhistory histignoredups
+setopt nobanghist extendedhistory histignoredups noflowcontrol extendedglob
 
 local STICKYFILE=${STICKYFILE:-$HOME/.zsticky}
 local STICKYSIZE=${STICKYSIZE:-1000}
@@ -72,19 +72,47 @@
   bindkey -M sticky-vicmd ZZ accept-line
 fi
 
-[[ "$1" == -b ]] && return 0
+if [[ "$*" == *-h* ]]; then
+    print "Usage: sticky-note [OPTION]...
+Where [OPTION]s can be:
+
+ -h      display this help and exit
+ -l      list existing sticky notes
+ -b      install keymaps & keybindings, and exit
+ -c COL  make sticky note a certain colour (ignored with -l option)
+ -B      make sticky note blink (ignored with -l option)
+
+With no option a new sticky note is prompted for, with colour specified 
+by the \"theme\" zstyle for the \":sticky-note\" context"
+    return 0
+fi
+
+[[ "$1" == *-b* ]] && return 0
 
 # Look up color theme
 local -A theme
 (($+bg && $+fg)) || { autoload -Uz colors; colors }
+
 zstyle -m :sticky-note theme '*' || {
     zstyle :sticky-note theme bg yellow fg black
 }
 zstyle -a :sticky-note theme theme
-(( ${+bg[$theme[bg]]} )) && theme[bg]=$bg[$theme[bg]]
 (( ${+fg[$theme[fg]]} )) && theme[fg]=$fg[$theme[fg]]
+(( ${+bg[$theme[bg]]} )) && theme[bg]=$bg[$theme[bg]]
 (( ${+theme[color]} )) || theme[color]=$theme[bg]$theme[fg]
 (( ${+theme[reset]} )) || theme[reset]=$reset_color
+# If -c <COL> option is supplied use <COL> as background colour
+if [[ "$*" == *-c\ [a-z]##* ]]; then
+    theme[newcolor]="$bg[${*//(#b)*-c ([a-z]#)*/$match}]${theme[fg]}"
+else
+    theme[newcolor]=$theme[color]
+fi
+# blink text if -B option supplied
+if [[ "$*" == *-B* ]]; then
+    theme[newcolor]+="$(echoti blink)"
+fi
+
+local fcopts="${${${${@//-B}//-c #[a-z]#}## #}%% #}"
 
 # If invoked as a widget, behave a bit like run-help
 if zle
@@ -96,7 +124,7 @@
     echoti sc
     echoti home
     print -nr "$theme[color]"
-    fc -l "${@:--1}" | while read -r sticky; do print -- "$sticky"; done
+    fc -l "${fcopts:--1}" | while read -r sticky; do print -b -- "$sticky"; done
     print -nr "$theme[reset]"
     echoti rc
   elif [[ $CONTEXT = (cont|select|vared) ]]
@@ -120,19 +148,20 @@
 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 "${fcopts}" | while read -r sticky; do print -b -- "$sticky"; done
   print -nr "$theme[reset]"
   return 0
 fi
 
 # Edit a new sticky note and add it to the stickyfile
-while vared -h -p "%{$theme[color]%}" -M sticky -m sticky-vicmd sticky
+while vared -h -e -p "%{$theme[newcolor]%}" -M sticky -m sticky-vicmd sticky
 do
   {
-    [[ -n "$sticky" ]] && print -s -- "$sticky"
+    [[ -n "$sticky" ]] && print -s -- "${theme[newcolor]}$sticky${theme[color]}\e[25m"
   } always {
     (( TRY_BLOCK_ERROR = 0 ))
   } && break
   echo -n -e '\a'
 done
 return 0
+

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Suggested improvement for sticky-note
  2021-05-04  2:06     ` vapnik spaknik
@ 2021-05-09 20:50       ` Bart Schaefer
  2021-05-11 10:18         ` Mikael Magnusson
                           ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Bart Schaefer @ 2021-05-09 20:50 UTC (permalink / raw)
  To: vapnik spaknik; +Cc: Zsh Hackers List

Just now getting back to this ...

On Mon, May 3, 2021 at 7:06 PM vapnik spaknik <vapniks@yahoo.com> wrote:
>
> The attached diff (against the original)

... is still a file with the ".diff" suffix instead of ".txt" ...

> adds options for selecting a background colour &/or blinking when creating a new sticky note, and automatically adds the appropriate escape codes. It also adds a help option.

There are a few reasonable suggestions here mixed with quite a number
of things that could be improved.  Adding noflowcontrol to the setopts
is probably a good idea, and passing "-e" to vared should at least be
configurable.  That also caused me to notice that interrupting
sticky-note with a keyboard interrupt (^C) can cause old notes to
disappear, so that should be fixed.  Help text is good if other new
command-line options are coming.

On the flip side:

The ad-hoc option recognition by pattern-matching "$*" is going to be
error prone.  Previously all the options were mutually exclusive so
just testing $1 was OK, but if there are going to be several options
that can appear in combination there ought to be a call to zparseopts
(or at least getopts).

Hardwiring two options for color and blink seems pretty arbitrary
(compare the "escapes" style in my patch that selects among three
variants).  What if someone wants italics or boldface or underlining
instead of blinking?

It's a bit strange to use $(echoti blink) for "on" but then hardwire
$'\e25m' for "off".  Anyway, $(echoti blink) just spits out an error
on my terminal, which the patch doesn't account for.

Having the note blink while it is being edited is rather
weird/distracting even if you want it to blink when displayed later.
(There's a reason web browsers dropped support for the HTML <blink>
tag, but we won't go there.)  Also, during editing the visual changes
are part of the vared prompt, but then are stored as raw ANSI escapes
in the text of the sticky note itself, which will have odd
side-effects when using history to access previous notes.

This is a mixing of metaphors, so to speak.  Visual changes are in the
text but the interpretation of bindkey sequences is done by "print -b"
after the text is read back from the file and is being displayed.
Even so, the raw escapes only work when combined with your -B option,
because if "print -b" is not used, the ASCII 033 are converted to "^"
"[" before being sent to the terminal.

Finally, you've embedded the definition-time theme color in the note
at the point where blink is turned off, so if the theme changes (new
zstyle applied) any notes that had color changes or blink will revert
to the previous theme's coloring.  In fact this makes me aware that it
doesn't really work to interpret prompt escapes, because (for example)
after %Bbold%b the background color reverts as well and the rest of
the note is no longer yellow.

It's going to take a bit more thought to decide what it's possible to
salvage from this, so no patch yet.

For any other zsh-workers reading this:  Does anyone know why
putpromptchar() has this?
            case 'b':
                txtchangeset(txtchangep, TXTNOBOLDFACE, TXTBOLDFACE);
                txtunset(TXTBOLDFACE);
                tsetcap(TCALLATTRSOFF, TSC_PROMPT|TSC_DIRTY);
                break;
That is, why TCALLATTRSOFF ?  That isn't done for %s or %u ... why is
there no TCBOLDFACEEND defined?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Suggested improvement for sticky-note
  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
  2023-11-12 21:10         ` Bart Schaefer
  2 siblings, 1 reply; 9+ messages in thread
From: Mikael Magnusson @ 2021-05-11 10:18 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: vapnik spaknik, Zsh Hackers List

On 5/9/21, Bart Schaefer <schaefer@brasslantern.com> wrote:
> Just now getting back to this ...
>
[...]
> Finally, you've embedded the definition-time theme color in the note
> at the point where blink is turned off, so if the theme changes (new
> zstyle applied) any notes that had color changes or blink will revert
> to the previous theme's coloring.  In fact this makes me aware that it
> doesn't really work to interpret prompt escapes, because (for example)
> after %Bbold%b the background color reverts as well and the rest of
> the note is no longer yellow.
>
> It's going to take a bit more thought to decide what it's possible to
> salvage from this, so no patch yet.
>
> For any other zsh-workers reading this:  Does anyone know why
> putpromptchar() has this?
>             case 'b':
>                 txtchangeset(txtchangep, TXTNOBOLDFACE, TXTBOLDFACE);
>                 txtunset(TXTBOLDFACE);
>                 tsetcap(TCALLATTRSOFF, TSC_PROMPT|TSC_DIRTY);
>                 break;
> That is, why TCALLATTRSOFF ?  That isn't done for %s or %u ... why is
> there no TCBOLDFACEEND defined?

I think that's a shortcoming in termcap and/or terminfo. In termcap
there is md (1m) and me (0m) that should correspond to bold, but 0m
turns off all attributes. Compare with us (4m) and ue (24m).
https://www.gnu.org/software/termutils/manual/termcap-1.3/html_chapter/termcap_4.html
also implies that there is no specific termcap sequence to only turn
off specific appearance modes.

When it comes to ANSI sequences though, there definitely are. From ctlseqs.txt,

            Ps = 2 2  -> Normal (neither bold nor faint)
            Ps = 2 4  -> Not underlined
            Ps = 2 5  -> Steady (not blinking)
            Ps = 2 7  -> Positive (not inverse)
            Ps = 2 8  -> Visible, i.e., not hidden (VT300)

Since we already assume ANSI for things like colors, I don't think we
would lose a lot of compatibility in practice if we just use 22
instead of 0 for %b, but we could potentially put it behind a setopt?

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Suggested improvement for sticky-note
  2021-05-09 20:50       ` Bart Schaefer
  2021-05-11 10:18         ` Mikael Magnusson
@ 2021-05-11 12:37         ` vapnik spaknik
  2023-11-12 21:10         ` Bart Schaefer
  2 siblings, 0 replies; 9+ messages in thread
From: vapnik spaknik @ 2021-05-11 12:37 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Hackers List

> On Sunday, May 9, 2021, 09:50:18 PM GMT+1, Bart Schaefer <schaefer@brasslantern.com> wrote:

>> On Mon, May 3, 2021 at 7:06 PM vapnik spaknik <vapniks@yahoo.com> wrote:
>>
>> The attached diff (against the original)

> ... is still a file with the ".diff" suffix instead of ".txt" ...

oops, sorry

> .....
> Hardwiring two options for color and blink seems pretty arbitrary
> (compare the "escapes" style in my patch that selects among three
> variants).  What if someone wants italics or boldface or underlining
> instead of blinking?

I thought most people would only need to differentiate different categories of notes (colours), and important ones (blinking), but I guess blinking might be a bit annoying for some.

> It's a bit strange to use $(echoti blink) for "on" but then hardwire
> $'\e25m' for "off".  Anyway, $(echoti blink) just spits out an error
> on my terminal, which the patch doesn't account for.

I thought echoti would be more portable, obviously I was wrong, but couldn't find any echoti command to turn off blinking.

> Having the note blink while it is being edited is rather
> weird/distracting even if you want it to blink when displayed later.
> (There's a reason web browsers dropped support for the HTML <blink>
> tag, but we won't go there.)  Also, during editing the visual changes
> are part of the vared prompt, but then are stored as raw ANSI escapes
> in the text of the sticky note itself, which will have odd
> side-effects when using history to access previous notes.

> This is a mixing of metaphors, so to speak.  Visual changes are in the
> text but the interpretation of bindkey sequences is done by "print -b"
> after the text is read back from the file and is being displayed.
> Even so, the raw escapes only work when combined with your -B option,
> because if "print -b" is not used, the ASCII 033 are converted to "^"
> "[" before being sent to the terminal.

> Finally, you've embedded the definition-time theme color in the note
> at the point where blink is turned off, so if the theme changes (new
> zstyle applied) any notes that had color changes or blink will revert
> to the previous theme's coloring.  In fact this makes me aware that it
> doesn't really work to interpret prompt escapes, because (for example)
> after %Bbold%b the background color reverts as well and the rest of
> the note is no longer yellow.

Seems I overlooked a few things when I hacked that up a few days ago.
It did cross my mind to use getopts, but I thought it would be better to keep 
the code short, and not make too many changes.
The patched sticky-note works for my purposes, but if I get some time at some 
point in the future (can't say when) I will have another look at it, unless you beat me to it..



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Termcap and boldface (was sticky-note)
  2021-05-11 10:18         ` Mikael Magnusson
@ 2021-05-14 23:40           ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2021-05-14 23:40 UTC (permalink / raw)
  To: Zsh Hackers List

On Tue, May 11, 2021 at 3:18 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> On 5/9/21, Bart Schaefer <schaefer@brasslantern.com> wrote:
> > That is, why TCALLATTRSOFF ?  That isn't done for %s or %u ... why is
> > there no TCBOLDFACEEND defined?
>
> I think that's a shortcoming in termcap and/or terminfo. In termcap
> there is md (1m) and me (0m) that should correspond to bold, but 0m
> turns off all attributes. Compare with us (4m) and ue (24m).

A couple of interesting things.

ANSI clumps together bold/faint/normal as 01/02/22 and
blink/fast-blink/steady as 05/06/25.  21 and 26 are for unrelated
features (double-underline and proportional).  This breaks the pattern
of all the other on/off pairs that are always 0x/2x.

Terminfo man page claims that standout is supposed to be reverse bold,
but zsh's use of termcap in prompts renders %S as reverse only.

> html_chapter/termcap_4.html
> also implies that there is no specific termcap sequence to only turn
> off specific appearance modes.

Terminfo manual says about the vt220 example, "We begin each escape
sequence by turning off any existing modes, since  there is no quick
way to determine whether they are active."  That also doesn't match
what appears to happen in prompts with combinations of %S%B etc.

> Since we already assume ANSI for things like colors, I don't think we
> would lose a lot of compatibility in practice if we just use 22
> instead of 0 for %b

That would mean special-casing whether we use symbolic termcap names,
so it's less straightforward that might be expected.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Suggested improvement for sticky-note
  2021-05-09 20:50       ` Bart Schaefer
  2021-05-11 10:18         ` Mikael Magnusson
  2021-05-11 12:37         ` Suggested improvement for sticky-note vapnik spaknik
@ 2023-11-12 21:10         ` Bart Schaefer
  2023-11-19  5:25           ` Bart Schaefer
  2 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2023-11-12 21:10 UTC (permalink / raw)
  To: vapnik spaknik; +Cc: Zsh Hackers List

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

Returning 2.5 years later ...

> On Mon, May 3, 2021 at 7:06 PM vapnik spaknik <vapniks@yahoo.com> wrote:
> >
> > adds options for selecting a background colour &/or blinking when creating a new sticky note, and automatically adds the appropriate escape codes.

The attached revision of sticky-note (which requires the current
development version of zsh for ${| code } and namespaces) implements
these in a more satisfactory way, by keeping a second file of assigned
display attributes alongside the history-formatted file that stores
the notes themselves.  The assignment of colors, blinking, etc. is now
activated by a key binding rather than a command line option, and is
customizable by a style.  I have not implemented "stacking" of styles
at this point, so if you want to change black-on-yellow to
blinking-white-on-red, you'll need a single display name for the
latter.

I'm sure there are undiscovered bugs with this, so mess around if interested.

On Sun, May 9, 2021 at 1:50 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> There are a few reasonable suggestions here mixed with quite a number
> of things that could be improved.  Adding noflowcontrol to the setopts
> is probably a good idea, and passing "-e" to vared should at least be
> configurable.

These are implemented in the attached version.  Several vared options
can now be controlled with
  zstyle :sticky-note vared-options ...

Read the large comment at the top of the file for a description of
what you can do, with some examples.  This should eventually go into
the contributions doc.

> That also caused me to notice that interrupting
> sticky-note with a keyboard interrupt (^C) can cause old notes to
> disappear, so that should be fixed.

I haven't tracked that down yet.  Also yet to be fixed is expiring
lines from the display file when the corresponding lines expire from
the history.

> Having the note blink while it is being edited is rather
> weird/distracting even if you want it to blink when displayed later.

The name of the current selected display style is displayed in the
PREDISPLAY string during editing.

As a final note, I found an error in the doc for "vared":

     ...  If the
     -e flag is given, typing ^D (Control-D) on an empty line causes
     vared to exit immediately with a non-zero return value.

This should say "in an empty note" not "empty line".  It only works if
the whole note would be blank.

[-- Attachment #2: sticky-note --]
[-- Type: application/octet-stream, Size: 10266 bytes --]

#!/bin/zsh -fi
# A zsh sticky-note ("post-it") application.  Load this file as a function:
#    autoload -Uz sticky-note
#
# It may then be bound as a widget:
#    zle -N sticky-note
# And/or run as a command:
#    sticky-note
#    sticky-note -b
#    sticky-note -l ...
# The -b option is like "zed -b": it installs keymaps/bindings only.
# Use the -l option to list previous sticky notes.  Most options of the
# "fc -l" command are supported, for selecting which notes to display.
# If "sticky-note -l" is run from inside a widget, the cursor is moved
# to the top left of the terminal before display and returned to its
# original position after display.  The -l option is implicitly added
# when sticky-note is called from zle-line-init, to avoid inadvertently
# trapping the user inside the note editor.
#
# Otherwise, invoke the line editor with the previous notes available
# 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 several zstyles, all using the context
# ":sticky-note".  The complete list of styles is and their types is:
#   notefile       string (filename)
#   maxnotes       number
#   vared-options  array
#   theme          associative array
#   display        associative array
#   list-display   boolean (string true|yes|on|1 or not set for false)

# 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:
#   zstyle :sticky-note notefile ~/.zsticky
#   zstyle :sticky-note maxnotes 1000

# 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).

# The "vared-options" style lists options passed to vared when a note
# is edited. The vared options -A, -a, -c, -M, and -m are ignored.  The
# useful options are -i, -f, -e, -p, -r, and in unusual cases -t.  The
# options -p and -r should use the same syntax as the "prompt" value of
# the "theme" style, described below, and the -r option should.  As a
# special case, to make the note history unavailable when editing,
# include +h in the vared-options style.  Example:
#   zstyle :sticky-note vared-options +h -e -r %T

# The "theme" style may be set to control the appearance of the notes.
# The style is an associative array; the current set of values (defaults
# in parens) are:
#   bg     => name or ANSI escape for background color (yellow)
#   fg     => name or ANSI escape for foreground color (black)
#   color  => ANSI escape for color scheme ($theme[bg]$theme[fg])
#   reset  => ANSI escape to restore "normal" colors
#   prompt => Passed to vared.  May refer to %{${theme[bg]}%} et al.
# Values given as names are looked up in the $bg and $fg arrays from the
# "colors" function.  If a "color" field is set, the "bg" and "fg" fields
# are not used unless referenced in "prompt".  The prompt value should
# be single-quoted and must use appropriate %{...%} wrappers around
# zero-width outputs such as color changes.  Example:
#   zstyle :sticky-note theme \
#     bg red \
#     fg $fg_bold[yellow] \
#     prompt '%{$theme[bg]$fg_bold[white]%}POST-IT:%{$theme[reset]%}'
# NOTE:  You must define either color or both fg and bg, but the values
# $theme[color] and $theme[reset] are always generated if omitted.

# The "display" style is an associative array mapping custom display
# attribute names to the ANSI codes to enable them.  The style must use
# "%s" at the position where the note should appear, and must end with
# ANSI codes to discontinue the style.  An empty value turns off the
# display formatting.  For example:
#   zstyle :sticky-note display \
#     none "" \
#     blink "$(echoti blink)%s$(echoti sgr0)" \
#     reverse $'\e[07m%s\e[00m'
# If you use this style, a file named $STICKYFILE.display is created
# to preserve the display attributes of the notes in $STICKYFILE.
# NOTE: Changing the display zstyle does not change the display of
# previously created notes.  There is no default display style.

# To set the display for a note, type ctrl-x question-mark (^X?) to
# run the widget "_sticky-display".  When a "display" style is set, this
# replaces the _complete_help binding from the default keymap.  The
# keymap named "sticky" may be modified to customize this, after running
# "sticky-note -b" to initialize.

# By default the display style is only applied when "posting" notes to
# the top of the screen via the ZLE widget, but can be applied to the
# output of "sticky-note -l" by setting the "list-display" style:
#   zstyle :sticky-note list-display true

# I encourage all you creative people to contribute enhancements ...

emulate -LR zsh

# TODO: Clean this up as notes expire from the STICKYFILE.
typeset -gA .zsticky.display

# Set up keybindings (adapted from "zed")
if ! bindkey -M sticky >& /dev/null
then
  bindkey -N sticky main
  bindkey -M sticky ^X^W accept-line
  bindkey -M sticky ^M^M accept-line	# Two quick RETs ends note
  bindkey -M sticky ^M self-insert-unmeta
fi
if ! bindkey -M sticky-vicmd >& /dev/null 
then
  bindkey -N sticky-vicmd vicmd
  bindkey -M sticky-vicmd ZZ accept-line
fi
if ! functions _sticky-display >& /dev/null &&
     zstyle -m :sticky-note display '*'
then
  function _sticky-display {
    if [[ -z $compstate[vared] ]]
    then
      local save_buffer=$BUFFER save_cursor=$CURSOR
      BUFFER=
      zle -U $'\t'
      zle recursive-edit -K sticky-display
      .zsticky.display[last]=$BUFFER
      PREDISPLAY="[ $BUFFER ] "
      BUFFER=$save_buffer CURSOR=$save_cursor
      zle reset-prompt
    else
      zstyle -a :sticky-note display sticky_displays
      compadd -x "Press TAB to choose display mode, ENTER to set:" \
	      -V nosort ${.zsticky.display[last]} \
	      ${${(ok)sticky_displays}:#${.zsticky.display[last]}}
      compstate[insert]=menu
    fi
  }
  zle -N _sticky-display
  bindkey -M sticky '^X?' _sticky-display
  zle -C sticky-display-choices menu-complete _sticky-display
  bindkey -N sticky-display
  bindkey -M sticky-display $'\t' sticky-display-choices
  bindkey -M sticky-display ^M accept-line
fi

[[ "$1" == -b ]] && return 0

setopt noflowcontrol nobanghist extendedhistory histignoredups
zmodload -i zsh/datetime

local STICKYFILE=${STICKYFILE:-$HOME/.zsticky}
local STICKYSIZE=${STICKYSIZE:-1000}
local PREDISPLAY sticky stickyfile stickysize
local -A sticky_displays vared_options

zstyle -s :sticky-note notefile stickyfile || stickyfile=$STICKYFILE
zstyle -s :sticky-note maxnotes stickysize || stickysize=$STICKYSIZE

# Populate options to vared
local -a v0
if zstyle -a :sticky-note vared-options v0
then
  v0[${v0[(i)-a]}]=()
  v0[${v0[(i)-A]}]=()
  v0[${v0[(i)-c]}]=()
  if (( ${v0[(I)+h]} ))
  then
    v0[${v0[(i)-h]}]=()
    v0[${v0[(i)+h]}]=()
  else
    v0+=(-h '')
  fi
  if (( ${v0[(I)-g]} ))
  then
    v0[${v0[(i)-g]}]=(-g '')
  fi
  if (( ${v0[(I)-e]} ))
  then
    v0[${v0[(i)-e]}]=(-e '')
  fi
  vared_options=( "$v0[@]" )
else
  vared_options=(-h '')
fi
: ${vared_options[-i]:=undefined-key}
: ${vared_options[-f]:=undefined-key}
: ${vared_options[-M]::=sticky}
: ${vared_options[-m]::=sticky-vicmd}

# Look up color theme
local -A theme
(($+bg && $+fg)) || { autoload -Uz colors; colors }
zstyle -m :sticky-note theme '*' || {
    zstyle :sticky-note theme bg yellow fg black
}
zstyle -a :sticky-note theme theme
(( ${+bg[$theme[bg]]} )) && theme[bg]=$bg[$theme[bg]]
(( ${+fg[$theme[fg]]} )) && theme[fg]=$fg[$theme[fg]]
(( ${+theme[color]} )) || theme[color]=$theme[bg]$theme[fg]
(( ${+theme[reset]} )) || theme[reset]=$reset_color
(( ${+theme[prompt]} )) || theme[prompt]=$vared_options[-p]

theme[prompt]="${(e)theme[prompt]}%{${theme[color]}%}"
vared_options[-p]=$theme[prompt]

# Load per-note display settings
if [[ -z ${.zsticky.display} && -r $stickyfile.display ]]
then
  source $stickyfile.display
fi

# If invoked as a widget, behave a bit like run-help
if zle
then
  zmodload -i zsh/parameter
  if [[ $* == -*l* || $functrace == *zle-line-init:* ]]
  then
    local num stamp ceol=${ echoti el }
    fc -ap $stickyfile $stickysize $stickysize
    echoti cup $LINES 1
    zle reset-prompt
    echoti sc
    echoti home
    print -nr "$theme[color]"
    fc -t %s -l "${@:--1}" |
      while read -r num stamp sticky
      do
	if [[ -n ${.zsticky.display[$stamp]} ]]
	then
	  printf -v sticky "${.zsticky.display[$stamp]}$theme[color]" $sticky
	fi
	printf %s\\n "$num  "${sticky//$'\\n'/$ceol$'\n'}$ceol
      done
    print -nr "$theme[reset]"
    echoti rc
  elif [[ $CONTEXT = (cont|select|vared) ]]
  then
    zle -M "No stickies during ${${(z)PREBUFFER}[1]:-$CONTEXT}, sorry"
    zle .beep
    zle -R
  else
    zle .push-line
    BUFFER=sticky-note
    zle .accept-line
  fi
  return 0
fi

# Invoked as a command, behave like zed, but write a history file
fc -ap $stickyfile $stickysize $stickysize

# With a -l option, list the existing sticky notes
if [[ "$*" == -*l* ]]
then
  local num stamp display
  print -nr "$theme[color]"
  # Use read/print loop to interpolate "\n" in history lines
  fc -t %s "$@" |
    while read -r num stamp sticky
    do
      if zstyle -t :sticky-note list-display &&
	  [[ -n ${.zsticky.display[$stamp]} ]]
      then
	printf -v sticky "${.zsticky.display[$stamp]}$theme[color]" $sticky
      fi
      print -- "${| strftime -s REPLY -n '%x %H:%M' $stamp }  $sticky"
    done
  print -nr "$theme[reset]"
  return 0
fi

# Edit a new sticky note and add it to the stickyfile
while vared ${(kv)vared_options} sticky
do
  {
    if [[ -n "$sticky" ]]
    then
      print -s -- "$sticky"
      fc -W && SAVEHIST=0
      # File is updated but internal "fc -l" is not yet.  Get the timestamp.
      stamp=${${${| local line;
		  while read line; do REPLY=$line; done <$stickyfile }#: }%%:*}
      if [[ -n $stamp && -n ${.zsticky.display[last]} && -n $sticky_displays ]]
      then
	.zsticky.display[$stamp]=${sticky_displays[${.zsticky.display[last]}]}
        typeset -p .zsticky.display >| $stickyfile.display
      fi
    fi
  } always {
    unset sticky_displays
    (( TRY_BLOCK_ERROR = 0 ))
  } && break
  echo -n -e '\a'
done
return 0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Suggested improvement for sticky-note
  2023-11-12 21:10         ` Bart Schaefer
@ 2023-11-19  5:25           ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2023-11-19  5:25 UTC (permalink / raw)
  To: Zsh Hackers List; +Cc: vapnik spaknik

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

On Sun, Nov 12, 2023 at 1:10 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> I'm sure there are undiscovered bugs with this, so mess around if interested.
>
> > That also caused me to notice that interrupting
> > sticky-note with a keyboard interrupt (^C) can cause old notes to
> > disappear, so that should be fixed.

I solved this.  It turns out that "fc -ap" removes events from the
history file if the enclosing function exits on interrupt.  This is
probably a bug of some sort, but easily worked around by addition of
an "always" block that clears the interrupt state.

> Also yet to be fixed is expiring
> lines from the display file when the corresponding lines expire from
> the history.

Fixed this too.

The attached revision also adds a "history-opts" style for changing
the localoptions used e.g. when navigating past notes and rewriting
the stickyfile.

[-- Attachment #2: sticky-note --]
[-- Type: application/octet-stream, Size: 11851 bytes --]

#!/bin/zsh -fi
# A zsh sticky-note ("post-it") application.  Load this file as a function:
#    autoload -Uz sticky-note
#
# It may then be bound as a widget:
#    zle -N sticky-note
# And/or run as a command:
#    sticky-note
#    sticky-note -b
#    sticky-note -l ...
# The -b option is like "zed -b": it installs keymaps/bindings only.
# Use the -l option to list previous sticky notes.  Most options of the
# "fc -l" command are supported, for selecting which notes to display.
# If "sticky-note -l" is run from inside a widget, the cursor is moved
# to the top left of the terminal before display and returned to its
# original position after display.  The -l option is implicitly added
# when sticky-note is called from zle-line-init, to avoid inadvertently
# trapping the user inside the note editor.
#
# Otherwise, invoke the line editor with the previous notes available
# 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 several zstyles, all using the context
# ":sticky-note".  The complete list of styles is and their types is:
#   notefile       string (filename)
#   maxnotes       number
#   history-opts   array
#   vared-options  array
#   theme          associative array
#   display        associative array
#   list-display   boolean (string true|yes|on|1 or not set for false)

# 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:
#   zstyle :sticky-note notefile ~/.zsticky
#   zstyle :sticky-note maxnotes 1000

# 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).

# The "history-opts" style gives a list of setopt names, passed to
# "setopt localoptions ...".  Note that this means you must use the "no"
# prefix to disable an option.  The extendedhistory option is always used
# regardless of the setting of this style, to record note timestamps.
# Otherwise, the default is equivalent to
#   zstyle :sticky-note history-opts \
#     noappendhistory nobanghist histignoredups
# Values that do not contain the substring "hist" are ignored, along with:
#   histlexwords histnofunctions histnostore incappendhistory sharehistory
# Useful values include:
#   histexpiredupsfirst histfindnodups histignorealldups histsavenodups
# Other setopts not related to history are reset via "emulate -R zsh".

# The "vared-options" style lists options passed to vared when a note
# is edited. The vared options -A, -a, -c, -M, and -m are ignored.  The
# useful options are -i, -f, -e, -p, -r, and in unusual cases -t.  The
# options -p and -r should use the same syntax as the "prompt" value of
# the "theme" style, described below, and the -r option should.  As a
# special case, to make the note history unavailable when editing,
# include +h in the vared-options style.  Example:
#   zstyle :sticky-note vared-options +h -e -r %T

# The "theme" style may be set to control the appearance of the notes.
# The style is an associative array; the current set of values (defaults
# in parens) are:
#   bg     => name or ANSI escape for background color (yellow)
#   fg     => name or ANSI escape for foreground color (black)
#   color  => ANSI escape for color scheme ($theme[bg]$theme[fg])
#   reset  => ANSI escape to restore "normal" colors
#   prompt => Passed to vared.  May refer to %{${theme[bg]}%} et al.
# Values given as names are looked up in the $bg and $fg arrays from the
# "colors" function.  If a "color" field is set, the "bg" and "fg" fields
# are not used unless referenced in "prompt".  The prompt value should
# be single-quoted and must use appropriate %{...%} wrappers around
# zero-width outputs such as color changes.  Example:
#   zstyle :sticky-note theme \
#     bg red \
#     fg $fg_bold[yellow] \
#     prompt '%{$theme[bg]$fg_bold[white]%}POST-IT:%{$theme[reset]%}'
# NOTE:  You must define either color or both fg and bg, but the values
# $theme[color] and $theme[reset] are always generated if omitted.

# The "display" style is an associative array mapping custom display
# attribute names to the ANSI codes to enable them.  The style must use
# "%s" at the position where the note should appear, and must end with
# ANSI codes to discontinue the style.  An empty value turns off the
# display formatting.  For example:
#   zstyle :sticky-note display \
#     none "" \
#     blink "$(echoti blink)%s$(echoti sgr0)" \
#     reverse $'\e[07m%s\e[00m'
# If you use this style, a file named $STICKYFILE.display is created
# to preserve the display attributes of the notes in $STICKYFILE.
# NOTE: Changing the display zstyle does not change the display of
# previously created notes.  There is no default display style.

# To set the display for a note, type ctrl-x question-mark (^X?) to
# run the widget "_sticky-display".  When a "display" style is set, this
# replaces the _complete_help binding from the default keymap.  The
# keymap named "sticky" may be modified to customize this, after running
# "sticky-note -b" to initialize.

# By default the display style is only applied when "posting" notes to
# the top of the screen via the ZLE widget, but can be applied to the
# output of "sticky-note -l" by setting the "list-display" style:
#   zstyle :sticky-note list-display true

# I encourage all you creative people to contribute enhancements ...

emulate -LR zsh

typeset -gA .zsticky.display

# Set up keybindings (adapted from "zed")
if ! bindkey -M sticky >& /dev/null
then
  bindkey -N sticky main
  bindkey -M sticky ^X^W accept-line
  bindkey -M sticky ^M^M accept-line	# Two quick RETs ends note
  bindkey -M sticky ^M self-insert-unmeta
fi
if ! bindkey -M sticky-vicmd >& /dev/null 
then
  bindkey -N sticky-vicmd vicmd
  bindkey -M sticky-vicmd ZZ accept-line
fi
if ! functions _sticky-display >& /dev/null &&
     zstyle -m :sticky-note display '*'
then
  function _sticky-display {
    if [[ -z $compstate[vared] ]]
    then
      local save_buffer=$BUFFER save_cursor=$CURSOR
      BUFFER=
      zle -U $'\t'
      zle recursive-edit -K sticky-display
      .zsticky.display[last]=$BUFFER
      PREDISPLAY="[ $BUFFER ] "
      BUFFER=$save_buffer CURSOR=$save_cursor
      zle reset-prompt
    else
      zstyle -a :sticky-note display sticky_displays
      compadd -x "Press TAB to choose display mode, ENTER to set:" \
	      -V nosort ${.zsticky.display[last]} \
	      ${${(ok)sticky_displays}:#${.zsticky.display[last]}}
      compstate[insert]=menu
    fi
  }
  zle -N _sticky-display
  bindkey -M sticky '^X?' _sticky-display
  zle -C sticky-display-choices menu-complete _sticky-display
  bindkey -N sticky-display
  bindkey -M sticky-display $'\t' sticky-display-choices
  bindkey -M sticky-display ^M accept-line
fi

[[ "$1" == -b ]] && return 0

setopt noflowcontrol nobanghist extendedhistory histignoredups
setopt noappendhistory nosharehistory noincappendhistory
unsetopt histlexwords histnofunctions histnostore
zmodload -i zsh/datetime

local STICKYFILE=${STICKYFILE:-$HOME/.zsticky}
local STICKYSIZE=${STICKYSIZE:-1000}
local PREDISPLAY sticky stickyfile stickysize
local -A sticky_displays vared_options

zstyle -s :sticky-note notefile stickyfile || stickyfile=$STICKYFILE
zstyle -s :sticky-note maxnotes stickysize || stickysize=$STICKYSIZE

# Populate custom history setopts
() {
  local -a h0
  if zstyle -a :sticky-note history-opts h0
  then
    h0=( ${(M)h0:#*hist*} )
    h0=( ${h0:#*(extended|lexwords|nofunctions|nostore|incappend|share)*} )
    setopt $h0
  fi
}

# Populate options to vared
() {
  local -a v0
  if zstyle -a :sticky-note vared-options v0
  then
    v0[${v0[(i)-a]}]=()
    v0[${v0[(i)-A]}]=()
    v0[${v0[(i)-c]}]=()
    if (( ${v0[(I)+h]} ))
    then
      v0[${v0[(i)-h]}]=()
      v0[${v0[(i)+h]}]=()
    else
      v0+=(-h '')
    fi
    if (( ${v0[(I)-g]} ))
    then
      v0[${v0[(i)-g]}]=(-g '')
    fi
    if (( ${v0[(I)-e]} ))
    then
      v0[${v0[(i)-e]}]=(-e '')
    fi
  vared_options=( "$v0[@]" )
  else
    vared_options=(-h '')
  fi
}
: ${vared_options[-i]:=undefined-key}
: ${vared_options[-f]:=undefined-key}
: ${vared_options[-M]::=sticky}
: ${vared_options[-m]::=sticky-vicmd}

# Look up color theme
local -A theme
(($+bg && $+fg)) || { autoload -Uz colors; colors }
zstyle -m :sticky-note theme '*' || {
    zstyle :sticky-note theme bg yellow fg black
}
zstyle -a :sticky-note theme theme
(( ${+bg[$theme[bg]]} )) && theme[bg]=$bg[$theme[bg]]
(( ${+fg[$theme[fg]]} )) && theme[fg]=$fg[$theme[fg]]
(( ${+theme[color]} )) || theme[color]=$theme[bg]$theme[fg]
(( ${+theme[reset]} )) || theme[reset]=$reset_color
(( ${+theme[prompt]} )) || theme[prompt]=$vared_options[-p]

theme[prompt]="${(e)theme[prompt]}%{${theme[color]}%}"
vared_options[-p]=$theme[prompt]

# Load per-note display settings
if [[ -z ${.zsticky.display} && -r $stickyfile.display ]]
then
  source $stickyfile.display
  # Clean up notes expired from the STICKYFILE.
  () {
    local -a display_keys=(last) d0
    while IFS=': ' read -A d0
    do
      display_keys+=( $d0[2] )
    done < $stickyfile
    d0=( ${(k).zsticky.display} )
    set -- ${d0:|display_keys}
    while [[ -n $1 ]]
    do
      unset ".zsticky.display[$1]"
      shift
    done
    typeset -p 1 .zsticky.display >| $stickyfile.display
  }
fi

# If invoked as a widget, behave a bit like run-help
if zle
then
  zmodload -i zsh/parameter
  if [[ $* == -*l* || $functrace == *zle-line-init:* ]]
  then
    local num stamp ceol=${ echoti el }
    fc -ap $stickyfile $stickysize $stickysize
    echoti cup $LINES 1
    zle reset-prompt
    echoti sc
    echoti home
    print -nr "$theme[color]"
    fc -t %s -l "${@:--1}" |
      while read -r num stamp sticky
      do
	if [[ -n ${.zsticky.display[$stamp]} ]]
	then
	  printf -v sticky "${.zsticky.display[$stamp]}$theme[color]" $sticky
	fi
	printf %s\\n "$num  "${sticky//$'\\n'/$ceol$'\n'}$ceol
      done
    print -nr "$theme[reset]"
    echoti rc
  elif [[ $CONTEXT = (cont|select|vared) ]]
  then
    zle -M "No stickies during ${${(z)PREBUFFER}[1]:-$CONTEXT}, sorry"
    zle .beep
    zle -R
  else
    zle .push-line
    BUFFER=sticky-note
    zle .accept-line
  fi
  return 0
fi

# Invoked as a command, behave like zed, but write a history file
fc -ap $stickyfile $stickysize $stickysize

# With a -l option, list the existing sticky notes
if [[ "$*" == -*l* ]]
then
  local num stamp display
  print -nr "$theme[color]"
  # Use read/print loop to interpolate "\n" in history lines
  fc -t %s "$@" |
    while read -r num stamp sticky
    do
      if zstyle -t :sticky-note list-display &&
	  [[ -n ${.zsticky.display[$stamp]} ]]
      then
	printf -v sticky "${.zsticky.display[$stamp]}$theme[color]" $sticky
      fi
      print -- "${| strftime -s REPLY -n '%x %H:%M' $stamp }  $sticky"
    done
  print -nr "$theme[reset]"
  return 0
fi

# Edit a new sticky note and add it to the stickyfile
while {
    vared ${(kv)vared_options} sticky
  } always {
    # Assure we reach "return 0" to complete fc -ap
    TRY_BLOCK_INTERRUPT=0
} do
  {
    if [[ -n "$sticky" ]]
    then
      print -s -- "$sticky"
      fc -W && SAVEHIST=0
      # File is updated but internal "fc -l" is not yet.  Get the timestamp.
      stamp=${${${| local line;
		  while read line; do REPLY=$line; done <$stickyfile }#: }%%:*}
      if [[ -n $stamp && -n ${.zsticky.display[last]} && -n $sticky_displays ]]
      then
	.zsticky.display[$stamp]=${sticky_displays[${.zsticky.display[last]}]}
        typeset -p 1 .zsticky.display >| $stickyfile.display
      fi
    fi
  } always {
    unset sticky_displays
    (( TRY_BLOCK_ERROR = 0 ))
  } && break
  echo -n -e '\a'
done
return 0

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-11-19  5:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1185563186.165566.1619896723304.ref@mail.yahoo.com>
2021-05-01 19:18 ` Suggested improvement for sticky-note vapnik spaknik
2021-05-02 23:57   ` Bart Schaefer
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
2023-11-12 21:10         ` Bart Schaefer
2023-11-19  5:25           ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).