slurp icon indicating copy to clipboard operation
slurp copied to clipboard

Add a debug msg to distinguish cancellation by ESC and click

Open cjacker opened this issue 1 year ago • 2 comments

As mentioned in https://github.com/emersion/slurp/pull/126, I bind a script to 'Print' key and intend to use 'ESC' to cancel and 'click' to take a whole screenshot.

Currently, both ESC and click print out same msg 'selection cancelled', and I need a different msg to distinguish cancellation by ESC from click.

The previous try in https://github.com/emersion/slurp/pull/126 is stupid. What I need is just a different msg, one more fprintf is enough for that.

The script I use:

#!/usr/bin/bash

IMG_VIEWER=pqiv

FILENAME=screenshot-$(LANG=C LC_ALL=C date "+%Y-%m-%d-%H-%M-%S").png

SELECT=$(LANG=en_US slurp 2>&1)

if [ "$SELECT""x" == "ESC pressed selection cancelled""x" ]; then
  true
elif [ "$SELECT""x" == "selection cancelled""x" ]; then
  grim "$HOME"/"$FILENAME" && $IMG_VIEWER "$HOME"/"$FILENAME"
else
  grim -g "$SELECT" "$HOME"/"$FILENAME" && $IMG_VIEWER "$HOME"/"$FILENAME"
fi

cjacker avatar Apr 07 '23 14:04 cjacker

Error messages should not be relied upon. They might change, be localized, etc. They are for human consumption only.

emersion avatar Apr 07 '23 14:04 emersion

Error messages should not be relied upon. They might change, be localized, etc. They are for human consumption only.

I am not sure which is your prefer way, and took a look at hacksaw, 'click' print 'global cursor pos 0x0' and 'ESC' report a cancellation msg, it can be used to:

  • distinguish 'click' from 'ESC'.
  • take a screenshot of window at global cursor pos if screenshot utility support it.

cjacker avatar Apr 08 '23 01:04 cjacker