about summary refs log tree commit diff
path: root/Functions/Zftp/zftp_progress
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-09-02 16:44:59 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-09-02 16:44:59 +0000
commit6e1759433b3d8e861e6146fcf9bd7a70735ec675 (patch)
tree8e736c83a6a4b0a314af123aa8660f8cdeefe3d0 /Functions/Zftp/zftp_progress
parent8b3e5404ce0fad4ebe457eb521b0b487221faf6a (diff)
downloadzsh-6e1759433b3d8e861e6146fcf9bd7a70735ec675.tar.gz
zsh-6e1759433b3d8e861e6146fcf9bd7a70735ec675.tar.xz
zsh-6e1759433b3d8e861e6146fcf9bd7a70735ec675.zip
zsh-workers/7632
Diffstat (limited to 'Functions/Zftp/zftp_progress')
-rw-r--r--Functions/Zftp/zftp_progress45
1 files changed, 39 insertions, 6 deletions
diff --git a/Functions/Zftp/zftp_progress b/Functions/Zftp/zftp_progress
index e2b5084c4..344d1c9c1 100644
--- a/Functions/Zftp/zftp_progress
+++ b/Functions/Zftp/zftp_progress
@@ -1,18 +1,51 @@
 # function zftp_progress {
 # Basic progress metre, showing the percent of the file transferred.
-# You want growing bars?  You gotta write growing bars.
+# You want growing bars?  You gottem.
+# zfconfig keys:
+#   progress
+#       empty or `none'                  no progress meter
+#       `bar'                            use a growing bar of inverse video
+#       `percent' or other non-blank     show the percentage transferred
+#     If size of remote file is not available, `bar' or `percent' just show
+#     bytes.
+#   update
+#       Minimum time in seconds between updates of the progress display.
 
 # Don't show progress unless stderr is a terminal
-[[ ! -t 2 ]] && return 0
+[[ ! -t 2 || ${zfconfig[progress]} = (|none) ]] && return 0
 
-if [[ $ZFTP_TRANSFER = *F ]]; then
-  print 1>&2
-elif [[ -n $ZFTP_TRANSFER ]]; then
+# Tunable parameters.
+# How many seconds to wait before printing an updated progress report.
+integer update=${zfconfig[update]:-1}
+# What style: either bar for growing bars, or anything else for simple
+# percentage.  For bar we need to have the terminal width in COLUMNS,
+# which is often set automatically, but you never know.
+local style=${zfconfig[progress]}
+
+if [[ -n $ZFTP_TRANSFER ]]; then
+  # avoid a `parameter unset' message
+  [[ $ZFTP_TRANSFER != *F ]] &&
+    (( ${+zftpseconds} )) && (( SECONDS - zftpseconds < update )) && return
   if [[ -n $ZFTP_SIZE ]]; then
     local frac="$(( ZFTP_COUNT * 100 / ZFTP_SIZE ))%"
-    print -n "\r$ZFTP_FILE ($ZFTP_SIZE bytes): $ZFTP_TRANSFER $frac" 1>&2
+    if [[ $style = bar && ${+COLUMNS} = 1 && $COLUMNS -gt 0 ]]; then
+      if (( ! ${+zftpseconds} )); then
+	print "$ZFTP_FILE ($ZFTP_SIZE bytes): $ZFTP_TRANSFER" 1>&2
+      fi
+      integer maxwidth=$(( COLUMNS - 7 ))
+      local width="$(( ZFTP_COUNT * maxwidth / ZFTP_SIZE ))"
+      print -nP "\r%S${(l:width:):-}%s${(l:maxwidth-width:):-}: ${frac}%%" 1>&2
+    else
+      print -n "\r$ZFTP_FILE ($ZFTP_SIZE bytes): $ZFTP_TRANSFER $frac" 1>&2
+    fi
   else
     print -n "\r$ZFTP_FILE: $ZFTP_TRANSFER $ZFTP_COUNT" 1>&2
   fi
+  if [[ $ZFTP_TRANSFER = *F && ${+zftpseconds} = 1 ]]; then
+    unset zftpseconds
+    print 1>&2
+  else
+    zftpseconds=$SECONDS
+  fi
 fi
 # }