-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelfos-feedback.el
55 lines (44 loc) · 2.07 KB
/
delfos-feedback.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
;;; delfos-feedback.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 namespace
;;
;; Author: namespace <src.namespace@gmail.com>
;; Maintainer: namespace <src.namespace@gmail.com>
;;; Commentary:
;; This library implements different feedback mechanisms like spinners, sounds, etc.
;;; Code:
(require 'spinner)
(defvar delfos-feedback-alarm-sound (expand-file-name ".media/alarm.wav" (file-name-directory load-file-name)))
(defvar delfos-feedback-spinner (spinner-create 'progress-bar-filled))
(defvar delfos-feedback-spinner-overlay nil)
(defvar delfos-feedback-spinner-timer nil)
(defun delfos-feedback-play-bell ()
"Play the bell sound using the alarm sound file specified in `delfos-feedback-alarm-sound`."
(condition-case _err
(play-sound-file delfos-feedback-alarm-sound)
(error (message "Failed to play sound"))))
(defun delfos-feedback-show-spinner ()
"Display a spinner at the end of the current buffer to indicate ongoing activity."
(if delfos-feedback-spinner-timer
(cancel-timer delfos-feedback-spinner-timer))
(let ((buffer (current-buffer)))
(setq delfos-feedback-spinner-overlay (make-overlay (point-max) (point-max)))
(spinner-start delfos-feedback-spinner)
(overlay-put delfos-feedback-spinner-overlay 'before-string (spinner-print delfos-feedback-spinner))
(setq delfos-feedback-spinner-timer
(run-with-timer
0 0.1
(lambda ()
(with-current-buffer buffer
(when (overlay-buffer delfos-feedback-spinner-overlay)
(overlay-put delfos-feedback-spinner-overlay 'before-string (spinner-print delfos-feedback-spinner)))))))))
(defun delfos-feedback-hide-spinner ()
"Hide the spinner previously displayed by `delfos-feedback-show-spinner`."
(when delfos-feedback-spinner-timer
(cancel-timer delfos-feedback-spinner-timer))
(when delfos-feedback-spinner
(spinner-stop delfos-feedback-spinner))
(when delfos-feedback-spinner-overlay
(delete-overlay delfos-feedback-spinner-overlay)))
(provide 'delfos-feedback)
;;; delfos-feedback.el ends here