Skip to content

Commit

Permalink
removed zenity and therefore also the -i and --interface arguments, r…
Browse files Browse the repository at this point in the history
…emoved zenity dependency and updated documentation, fixes #5
  • Loading branch information
phisch committed Jun 5, 2019
1 parent b9006b2 commit f94c1e9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 88 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Optionally, install the following dependencies:

- slop (`--select`)
- libnotify (`--notify`)
- zenity (`--interface zenity`)

Clone the giph repository:

Expand Down
10 changes: 0 additions & 10 deletions man/giph.1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ giph \- record gif from desktop, window or selection
[\fB-g\fR \fIGEOMETRY\fR |
\fB-w\fR \fIINT\fR |
\fB-s\fR [\fB-l\fR] [\fB-c\fR \fIFLOAT,FLOAT,FLOAT,FLOAT\fR] [\fB-p\fR \fIFLOAT\fR] [\fB-b\fR \fIFLOAT\fR]]
[\fB-i\fR \fIINTERFACE\fR]
[\fB-d\fR \fIINT\fR]
[\fB-t\fR \fIINT\fR]
[\fB-f\fR \fIINT\fR]
Expand Down Expand Up @@ -77,15 +76,6 @@ Sets a fixed time to record. The format is a timeduration as described in the ff
.BR \-f ", " \-\-framerate " \fIINT\fR (default: \fI15\fR)"
Sets the desired framerate of the recorded gif. A higher framerate will result in a larger filesize.
.TP
.BR \-i ", " \-\-interface " \fISTRING\fR (default: \fIcli\fR)"
Selects the user interface method that is used for countdown, timer and to stop the recording. The possible values are:
.in +2
\(bu
.IR cli ": uses the terminal as a user interface"
.br
\(bu
.IR zenity ": displays control-windows using zenity"
.TP
.BR \-y ", " \-\-notify
Uses notify-send to send an urgent notification if an error happens, or a normal notification when the final gif was saved successfully.
.SH SLOP OPTIONS
Expand Down
80 changes: 3 additions & 77 deletions src/giph
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ VERBOSITY=0
SLOP=0
DELAY=0
FRAMERATE=15
INTERFACE="cli"

function print_version() {
echo $VERSION
Expand All @@ -37,7 +36,6 @@ OPTIONS
-d, --delay=INT Time in seconds before the recording starts.
-t, --timer=TIMEDURATION Time of the recording. (e.g. 10 for 10 seconds or 1:30 for 1 minute 30 seconds)
-f, --framerate=INT Set the framerate.
-i, --interface=STRING Set the user interface that should be used. ("cli" or "zenity")
-y, --notify Send notification on error or success.
SLOP OPTIONS
Expand Down Expand Up @@ -140,10 +138,6 @@ while [[ "$1" == -* ]]; do
shift
FRAMERATE="$1"
;;
-i|--interface)
shift
INTERFACE="$1"
;;
-y|--notify)
NOTIFY=1
;;
Expand Down Expand Up @@ -312,7 +306,7 @@ function start_video_recording() {

ffmpeg+=("$TEMP_DIRECTORY/recording.mkv")

[ -n "$DELAY" ] && [ "$DELAY" -gt 0 ] && delay "$DELAY"
[ -n "$DELAY" ] && [ "$DELAY" -gt 0 ] && countdown_cli "$DELAY" "recording starts in"

ffmpeg_command=${ffmpeg[*]}
log "ffmpeg command: '$ffmpeg_command'" 2 true
Expand All @@ -323,9 +317,9 @@ function start_video_recording() {
log "started recording video with ffmpeg" 1 true

if [ -n "$TIMER" ] && [ "$TIMER" -gt 0 ]; then
timer "$TIMER"
countdown_cli "$TIMER" "recording stops in"
else
stop_video_recording_handler
stop_recording_handler_cli
fi

wait $FFMPEG_PID
Expand All @@ -334,17 +328,6 @@ function start_video_recording() {
log "completed ffmpeg video recording" 1 true
}

function delay() {
case "$INTERFACE" in
"cli")
countdown_cli "$1" "recording starts in"
;;
"zenity")
delay_zenity "$1"
;;
esac
}

function countdown_cli() {
seconds=$1
while [ "$seconds" -ge 0 ]; do
Expand All @@ -358,68 +341,11 @@ function countdown_cli() {
done
}

function delay_zenity() {
counter=$1
while [ "$counter" -ge "0" ]; do
percent=$((100-100*counter/$1))
echo "#recording will start in $counter"
echo $percent
((counter-=1))
sleep 1
done | zenity --progress "$1" --no-cancel --extra-button="Cancel" --auto-close &> /dev/null
[ $? = 1 ] && log_error "recording canceled by user"
}

function timer() {
case "$INTERFACE" in
"cli")
countdown_cli "$1" "recording stops in"
;;
"zenity")
timer_zenity "$1"
;;
esac
}

function timer_zenity() {
counter=$1
while [ "$counter" -ge "0" ]; do
percent=$((100-100*counter/$1))
echo "#recording stops in $counter"
echo $percent
((counter-=1))
sleep 1
done | zenity --progress "$1" --no-cancel --auto-close &> /dev/null
}

function stop_video_recording_handler() {
case "$INTERFACE" in
"cli")
stop_recording_handler_cli
;;
"zenity")
stop_recording_handler_zenity
;;
esac
}

function stop_recording_handler_cli() {
log_info "stop recording with \033[1;36mctrl+c\033[0m or send INT SIGNAL to this process \033[1;36mkillall -int -g giph\033[0m"
trap '' INT
}

function stop_recording_handler_zenity() {
zenity --question --cancel-label "Cancel" --ok-label "Stop" --text "\n<big>recording...</big>" --icon-name media-record &> /dev/null
zenity_return=$?

kill -INT $FFMPEG_PID

if [ $zenity_return = 1 ]; then
wait $FFMPEG_PID
log_error "video recording canceled by user"
fi
}

function encode_gif_ffmpeg() {
log "encoding gif using ffmpeg encoder" 1 true
ffmpeg_generate_palette=(ffmpeg -i "$TEMP_DIRECTORY/recording.mkv" -vf palettegen "$TEMP_DIRECTORY/palette.png")
Expand Down

0 comments on commit f94c1e9

Please sign in to comment.