4358148e |
1 | (in-package :lisp-on-lines) |
2 | |
e7444a93 |
3 | (defmethod described-object ((attribute standard-attribute)) |
4 | (described-object (attribute-description attribute))) |
5 | |
4358148e |
6 | (define-description T () |
bd9c9c31 |
7 | ((label :label nil |
8 | :function (lambda (object) |
9 | (format nil "~@(~A~)" |
10 | (substitute #\Space #\- |
11 | (symbol-name |
12 | (class-name (class-of |
13 | object))))))) |
14 | (identity :label nil :function #'identity) |
b1c8f43b |
15 | (type :label "Type" :function #'type-of) |
6de8d300 |
16 | (class :label "Class" :function #'class-of) |
17 | (active-attributes :label "Attributes" |
18 | :value nil |
19 | :activep nil |
b7657b86 |
20 | :keyword :attributes) |
21 | (attribute-delimiter :label "Attribute Delimiter" |
22 | :value "~%" |
23 | :activep nil |
24 | :keyword :delimter) |
25 | (active-descriptions :label "Active Descriptions" |
26 | :value nil |
27 | :activep nil |
28 | :keyword :activate) |
29 | (inactive-descriptions :label "Inactive Descriptions" |
bd9c9c31 |
30 | :value nil |
31 | :activep nil |
32 | :keyword :deactivate) |
f4efa7ff |
33 | (label-formatter :value (lambda (label) |
b1c8f43b |
34 | (generic-format *display* "~A:" label)) |
f4efa7ff |
35 | :activep nil) |
36 | (value-formatter :value (curry #'format nil "~A") |
37 | :activep nil))) |
4358148e |
38 | |
39 | (define-layered-method description-of (any-lisp-object) |
40 | (find-description 't)) |
41 | |
b7657b86 |
42 | (define-layered-function display-attribute (attribute) |
43 | (:method (attribute) |
44 | (display-using-description attribute *display* (attribute-object attribute)))) |
e8d4fa45 |
45 | |
2548f054 |
46 | |
b7657b86 |
47 | (define-layered-function display-attribute-label (attribute) |
48 | (:method (attribute) |
f4efa7ff |
49 | (funcall (attribute-label-formatter attribute) (attribute-label attribute)))) |
50 | |
b7657b86 |
51 | (define-layered-function display-attribute-value (attribute) |
f56d6e7e |
52 | (:method-combination arnesi:wrapping-standard) |
b7657b86 |
53 | (:method (attribute) |
54 | (flet ((disp (val &rest args) |
55 | (apply #'display *display* val |
56 | :activate (attribute-active-descriptions attribute) |
57 | :deactivate (attribute-inactive-descriptions attribute) |
58 | args))) |
46440824 |
59 | |
60 | |
e8d4fa45 |
61 | (let ((val (attribute-value attribute))) |
46440824 |
62 | #+nil (break "display Attribute value: ~A with object ~A ~% Description ~A att-d ~A ~% VALUE ~A display on ~A" |
63 | attribute |
64 | (attribute-object attribute) |
65 | *description* |
66 | (attribute-description attribute) |
67 | val |
68 | *display* |
69 | ) |
2548f054 |
70 | (if (and (not (slot-boundp attribute 'active-attributes)) |
46440824 |
71 | (equal val (attribute-object attribute))) |
72 | (progn (generic-format *display* "~A"(funcall (attribute-value-formatter attribute) val)) |
73 | #+nil(break "using generic format because val is object and there is no active attributes.")) |
74 | |
e8d4fa45 |
75 | (with-active-descriptions (inline) |
2548f054 |
76 | (cond ((slot-value attribute 'value-formatter) |
46440824 |
77 | (generic-format *display* "~A"(funcall (attribute-value-formatter attribute) val))) |
2548f054 |
78 | ((slot-boundp attribute 'active-attributes) |
79 | (disp val :attributes (slot-value attribute 'active-attributes))) |
80 | (t |
81 | (disp val))))))))) |
e8d4fa45 |
82 | |
83 | (define-layered-method display-using-description |
84 | ((attribute standard-attribute) display object &rest args) |
85 | (declare (ignore args)) |
86 | (when (attribute-label attribute) |
b7657b86 |
87 | (display-attribute-label attribute)) |
88 | (display-attribute-value attribute)) |
e8d4fa45 |
89 | |
2548f054 |
90 | (define-layered-method display-attribute :around |
91 | ((attribute standard-attribute)) |
92 | (funcall-with-layer-context |
93 | (modify-layer-context (current-layer-context) |
94 | :activate (attribute-active-descriptions attribute) |
95 | :deactivate (attribute-inactive-descriptions attribute)) |
96 | (lambda () |
97 | (call-next-method)))) |
98 | |
99 | (define-layered-method display-attribute :before |
100 | ((attribute standard-attribute)) |
46440824 |
101 | #+nil (break "Attribute : ~A with object ~A ~% Description ~A att-d ~A" |
102 | attribute |
103 | (attribute-object attribute) |
104 | *description* |
105 | (attribute-description attribute) |
106 | )) |
2548f054 |
107 | |
4358148e |
108 | (define-display ((description t)) |
b7657b86 |
109 | (let ((attributes (attributes description))) |
f56d6e7e |
110 | (when (first attributes)(display-attribute (first attributes))) |
f4efa7ff |
111 | (dolist (attribute (rest attributes) (values)) |
b7657b86 |
112 | (generic-format *display* |
113 | (attribute-value |
114 | (find-attribute description 'attribute-delimiter))) |
115 | (display-attribute attribute)))) |
116 | |
117 | |
f4efa7ff |
118 | (define-display :around ((description t) (display null) object) |
119 | (with-output-to-string (*standard-output*) |
b1c8f43b |
120 | (call-next-layered-method description t object)) |
121 | ) |
b7657b86 |
122 | |
4358148e |
123 | |
6de8d300 |
124 | |
125 | |