-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharei-spinner.el
57 lines (42 loc) · 1.91 KB
/
arei-spinner.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;; arei-spinner.el --- Evaluation Spinner for Arei -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Nikita Domnitskii
;; Author: Andrew Tropin <[email protected]>
;; Nikita Domnitskii <[email protected]>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Evaluation Spinner for Arei
;;; Code:
(require 'ring)
(defvar arei-spinner--symbol nil)
(defvar arei-spinner--timer (timer-create))
(defvar arei-spinner--ring
(ring-convert-sequence-to-ring
;; TODO: [Nikita Domnitskii, 2024-05-06] should be a custom
'("⣷" "⣯" "⣟" "⡿" "⢿" "⣻" "⣽" "⣾")))
(defun arei-spinner--tick ()
(setq arei-spinner--symbol
(ring-next arei-spinner--ring arei-spinner--symbol))
(force-mode-line-update t))
(defun arei-spinner-start ()
(let* ((repeat 0.1)
(time (timer-next-integral-multiple-of-time (current-time) repeat)))
(setq arei-spinner--symbol (ring-ref arei-spinner--ring 0))
(timer-set-time arei-spinner--timer time repeat)
(timer-set-function arei-spinner--timer #'arei-spinner--tick)
(timer-activate arei-spinner--timer)))
(defun arei-spinner-stop ()
(cancel-timer-internal arei-spinner--timer)
(setq arei-spinner--symbol nil))
(defun arei-spinner-modeline ()
(and arei-spinner--symbol (list arei-spinner--symbol)))
(provide 'arei-spinner)
;;; arei-spinner.el ends here