emersion / slurp

Select a region in a Wayland compositor
https://wayland.emersion.fr/slurp
MIT License
956 stars 57 forks source link

Add a debug msg to distinguish cancellation by ESC and click #127

Open cjacker opened 1 year ago

cjacker commented 1 year ago

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
emersion commented 1 year ago

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

cjacker commented 1 year ago

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: