4358148e |
1 | (in-package :lisp-on-lines) |
2 | |
3 | (define-description T () |
4 | ((identity :label nil :function #'identity) |
e8d4fa45 |
5 | (type :label "Type of" :function #'type-of) |
6de8d300 |
6 | (class :label "Class" :function #'class-of) |
7 | (active-attributes :label "Attributes" |
8 | :value nil |
9 | :activep nil |
b7657b86 |
10 | :keyword :attributes) |
11 | (attribute-delimiter :label "Attribute Delimiter" |
12 | :value "~%" |
13 | :activep nil |
14 | :keyword :delimter) |
15 | (active-descriptions :label "Active Descriptions" |
16 | :value nil |
17 | :activep nil |
18 | :keyword :activate) |
19 | (inactive-descriptions :label "Inactive Descriptions" |
20 | :value nil |
21 | :activep nil |
22 | :keyword :deactivate) |
23 | (label-formatter :value (curry #'format nil "~A ")) |
24 | (value-formatter :value (curry #'format nil "~A")))) |
4358148e |
25 | |
26 | (define-layered-method description-of (any-lisp-object) |
27 | (find-description 't)) |
28 | |
b7657b86 |
29 | (define-layered-function display-attribute (attribute) |
30 | (:method (attribute) |
31 | (display-using-description attribute *display* (attribute-object attribute)))) |
e8d4fa45 |
32 | |
b7657b86 |
33 | (define-layered-function display-attribute-label (attribute) |
34 | (:method (attribute) |
35 | (princ (funcall (attribute-label-formatter attribute) (attribute-label attribute)) |
36 | *display*))) |
e8d4fa45 |
37 | |
b7657b86 |
38 | |
39 | (define-layered-function display-attribute-value (attribute) |
40 | (:method (attribute) |
41 | (flet ((disp (val &rest args) |
42 | (apply #'display *display* val |
43 | :activate (attribute-active-descriptions attribute) |
44 | :deactivate (attribute-inactive-descriptions attribute) |
45 | args))) |
46 | |
e8d4fa45 |
47 | (let ((val (attribute-value attribute))) |
b7657b86 |
48 | (if (eql val (attribute-object attribute)) |
49 | (generic-format *display* (funcall (attribute-value-formatter attribute) val)) |
e8d4fa45 |
50 | (with-active-descriptions (inline) |
b7657b86 |
51 | (if (slot-boundp attribute 'active-attributes) |
52 | (disp val :attributes (slot-value attribute 'active-attributes)) |
53 | (disp val)))))))) |
e8d4fa45 |
54 | |
55 | (define-layered-method display-using-description |
56 | ((attribute standard-attribute) display object &rest args) |
57 | (declare (ignore args)) |
58 | (when (attribute-label attribute) |
b7657b86 |
59 | (display-attribute-label attribute)) |
60 | (display-attribute-value attribute)) |
e8d4fa45 |
61 | |
4358148e |
62 | (define-display ((description t)) |
b7657b86 |
63 | (let ((attributes (attributes description))) |
64 | (display-attribute (first attributes)) |
65 | (dolist (attribute (rest attributes)) |
66 | (generic-format *display* |
67 | (attribute-value |
68 | (find-attribute description 'attribute-delimiter))) |
69 | (display-attribute attribute)))) |
70 | |
71 | |
72 | (define-display :around ((description t) (display null)) |
73 | (with-output-to-string (*display*) |
74 | (print (call-next-method) *display*))) |
75 | |
4358148e |
76 | |
6de8d300 |
77 | |
78 | |