-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtui-util-ui.el
More file actions
62 lines (55 loc) · 1.95 KB
/
tui-util-ui.el
File metadata and controls
62 lines (55 loc) · 1.95 KB
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
(eval-when-compile
(require 'cl-lib))
(require 'edebug)
(require 'tui-defun)
(require 'tui-util)
(defun tui-element-label (element)
""
(prin1-to-string (tui--type element)))
(defun tui--prin1-to-string (value)
""
(let* ((print-level nil)
(print-length nil))
(with-temp-buffer
(insert (edebug-safe-prin1-to-string value))
(goto-char (point-min))
(ignore-errors
(lispy-alt-multiline t))
(buffer-substring (point-min) (point-max)))))
(tui-defun tui--plist-summary (plist)
""
(let* ((edebug-print-length 200)
(edebug-print-level 50))
(cl-loop for (key value) on plist by 'cddr
collect
(tui-line (prin1-to-string (keyword->symbol key)) ": " (tui--prin1-to-string value)))))
(tui-defun tui-element-summary (element)
"Information summary about ELEMENT."
(declare (wip TODO "abbreviate state and prop values"
TODO "put props and state in expanders"))
(let* ((props (tui-element-props element))
(state (tui-component-state element)))
(list
(tui-heading (tui-element-label element))
(tui-line "Mount point: " (edebug-safe-prin1-to-string (tui-element-start element)))
(tui-line "Source definition: ")
(tui-line (format "Properties (%d): "
(length (tui--plist-keys props))))
(tui-prefix-lines
:prefix " "
(tui--plist-summary :plist props))
(tui-line
(format "State (%d): "
(length (tui--plist-keys state))))
(tui-prefix-lines
:prefix " "
(tui--plist-summary :plist state)))))
(cl-defmacro tui-with-feature (feature &rest body)
"Evaluate BODY if FEATURE is available. Otherwise display an error indicating FEATURE is not available."
(declare (indent 1))
`(or (condition-case with-feature-err
(not (require ,feature))
(t (format "Error requiring feature '%s': %s" ,feature with-feature-err)))
(list
,@body)))
(provide 'tui-util-ui)