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

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

  reply	other threads:[~2021-05-04  2:06 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
2021-05-04  2:06     ` vapnik spaknik [this message]
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=1293997275.666259.1620093977494@mail.yahoo.com \
    --to=vapniks@yahoo.com \
    --cc=schaefer@brasslantern.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