forked from kubernetes-el/kubernetes-el
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes-loading-container.el
84 lines (67 loc) · 2.43 KB
/
kubernetes-loading-container.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;;; kubernetes-loading-container.el --- Component for resources that are loaded asynchronously. -*- lexical-binding: t; -*-
;;; Commentary:
;; A loading container displays placeholder text while a resource is loading in
;; the background.
;;
;; Other components build on this functionality to render differently depending
;; on the loaded state of some resource.
;;; Code:
(require 'kubernetes-ast)
(require 'kubernetes-vars)
(require 'magit-section)
(kubernetes-ast-define-component membership-loading-discriminator (elem vector &key on-loading on-found on-not-found)
(cond
((null vector)
on-loading)
((and vector
(if
(fboundp 'seq-contains-p)
(seq-contains-p vector elem)
(with-no-warnings (seq-contains vector elem))))
on-found)
(t
on-not-found)))
(kubernetes-ast-define-component membership-loading-container (elem vector &rest loaded-content)
`(membership-loading-discriminator
,elem ,vector
:on-loading
(line (propertize (face kubernetes-progress-indicator) (line "Fetching...")))
:on-found
,loaded-content
:on-not-found
(line (propertize (face kubernetes-progress-indicator) "Not found."))))
(kubernetes-ast-define-component emptiness-loading-discriminator (vector &key on-loading on-empty on-populated)
(cond
((and (vectorp vector) (equal 0 (length vector)))
on-empty)
(vector
on-populated)
(t
on-loading)))
(kubernetes-ast-define-component columnar-loading-container (resource-vector column-header &rest loaded-content)
`(emptiness-loading-discriminator
,resource-vector
:on-loading
(,@(when column-header
(list (cons 'line (list column-header))))
(propertize (face kubernetes-progress-indicator)
(line "Fetching...")))
:on-empty
(propertize (face kubernetes-dimmed) (line "None."))
:on-populated
(,@(when column-header
(list (cons 'line (list column-header))))
,@loaded-content)))
(kubernetes-ast-define-component header-with-count (header resource-vector)
(let ((header (propertize header 'face 'magit-section-heading)))
`(heading
(emptiness-loading-discriminator
,resource-vector
:on-loading
,header
:on-empty
,(concat header " (0)")
:on-populated
,(concat header (format " (%s)" (length resource-vector)))))))
(provide 'kubernetes-loading-container)
;;; kubernetes-loading-container.el ends here