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