]> code.delx.au - gnu-emacs-elpa/blobdiff - spinner.el
Require cl-lib
[gnu-emacs-elpa] / spinner.el
index ec6a17c0866aac4fff7344b94be210ffafe14c54..0132bf718fa5fe6a6ebfed4d0d9e37e026fdd1aa 100644 (file)
@@ -1,9 +1,11 @@
-;;; spinner.el --- Mode-line spinner for operations in progress  -*- lexical-binding: t; -*-
+;;; spinner.el --- Add spinners and progress-bars to the mode-line for ongoing operations -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2015  Artur Malabarba
 
 ;; Author: Artur Malabarba <bruce.connor.am@gmail.com>
 ;; Version: 1.0
+;; Package-Requires: ((cl-lib "0.5"))
+;; URL: https://github.com/Bruce-Connor/spinner.el
 ;; Keywords: processes mode-line
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
-
-;; Run `(spinner-start)' to see the effect.
+;; 1 Usage
+;; ═══════
+;;
+;; 1. Add `(spinner "1.0")' to your package’s dependencies.
+;;
+;; 2. Call `(spinner-start)' and a spinner will be added to the
+;; mode-line.
+;;
+;; 3. Call `(spinner-stop)' on the same buffer when you want to remove
+;; it.
+;;
+;;
+;; 2 Behavior
+;; ══════════
+;;
+;; The default spinner is a line drawing that rotates. You can pass an
+;; argument to `spinner-start' to specify which spinner you want. All
+;; possibilities are listed in the `spinner-types' variable, but here are
+;; a few examples for you to try:
+;;
+;; • `(spinner-start 'vertical-breathing 10)'
+;; • `(spinner-start 'minibox)'
+;; • `(spinner-start 'moon)'
+;; • `(spinner-start 'triangle)'
 
 \f
 ;;; Code:
+(require 'cl-lib)
 
 (defconst spinner-types
   '((3-line-clock . ["┤" "┘" "┴" "└" "├" "┌" "┬" "┐"])
     (2-line-clock . ["┘" "└" "┌" "┐"])
+    (flipping-line . ["_" "\\" "|" "/"])
+    (rotating-line . ["-" "\\" "|" "/"])
     (progress-bar . ["[    ]" "[=   ]" "[==  ]" "[=== ]" "[====]" "[ ===]" "[  ==]" "[   =]"])
     (progress-bar-filled . ["|    |" "|█   |" "|██  |" "|███ |" "|████|" "| ███|" "|  ██|" "|   █|"])
     (vertical-breathing . ["▁" "▂" "▃" "▄" "▅" "▆" "▇" "█" "▇" "▆" "▅" "▄" "▃" "▂" "▁" " "])
@@ -109,10 +136,10 @@ is chosen as the spinner type."
          ((symbolp type) (cdr (assq type spinner-types)))
          (t (error "Unknown spinner type: %s" type))))
   (setq spinner--counter 0)
-  
+
   ;; Maybe add to mode-line.
   (unless (memq 'spinner--mode-line-construct mode-line-format)
-    (setq mode-line-format (copy-list mode-line-format))
+    (setq mode-line-format (cl-copy-list mode-line-format))
     (let ((cell (memq 'mode-line-buffer-identification mode-line-format)))
       (if cell
           (setcdr cell (cons 'spinner--mode-line-construct (cdr cell)))