@@ -140,6 +140,33 @@ function Base.map(f, tangent::StructuralTangent{P}) where {P}
140
140
end
141
141
end
142
142
143
+
144
+ function Base. show (io:: IO , tangent:: StructuralTangent{P} ) where {P}
145
+ if tangent isa MutableTangent
146
+ print (io, " Mutable" )
147
+ end
148
+ print (io, " Tangent{" )
149
+ str = sprint (show, P, context = io)
150
+ i = findfirst (' {' , str)
151
+ if isnothing (i)
152
+ print (io, str)
153
+ else # for Tangent{T{A,B,C}}(stuff), print {A,B,C} in grey, and trim this part if longer than a line:
154
+ print (io, str[1 : prevind (str, i)])
155
+ if length (str) < 80
156
+ printstyled (io, str[i: end ], color= :light_black )
157
+ else
158
+ printstyled (io, str[i: prevind (str, 80 )], " ..." , color= :light_black )
159
+ end
160
+ end
161
+ print (io, " }" )
162
+ if isempty (backing (tangent))
163
+ print (io, " ()" ) # so it doesn't show `NamedTuple()`
164
+ else
165
+ # allow Tuple or NamedTuple `show` to do the rendering of brackets etc
166
+ show (io, backing (tangent))
167
+ end
168
+ end
169
+
143
170
"""
144
171
backing(x)
145
172
@@ -334,32 +361,6 @@ Base.:(==)(a::Tangent{P}, b::Tangent{Q}) where {P,Q} = false
334
361
335
362
Base. hash (a:: Tangent , h:: UInt ) = Base. hash (backing (canonicalize (a)), h)
336
363
337
- function Base. show (io:: IO , tangent:: StructuralTangent{P} ) where {P}
338
- if tangent isa MutableTangent
339
- print (io, " Mutable" )
340
- end
341
- print (io, " Tangent{" )
342
- str = sprint (show, P, context = io)
343
- i = findfirst (' {' , str)
344
- if isnothing (i)
345
- print (io, str)
346
- else # for Tangent{T{A,B,C}}(stuff), print {A,B,C} in grey, and trim this part if longer than a line:
347
- print (io, str[1 : prevind (str, i)])
348
- if length (str) < 80
349
- printstyled (io, str[i: end ], color= :light_black )
350
- else
351
- printstyled (io, str[i: prevind (str, 80 )], " ..." , color= :light_black )
352
- end
353
- end
354
- print (io, " }" )
355
- if isempty (backing (tangent))
356
- print (io, " ()" ) # so it doesn't show `NamedTuple()`
357
- else
358
- # allow Tuple or NamedTuple `show` to do the rendering of brackets etc
359
- show (io, backing (tangent))
360
- end
361
- end
362
-
363
364
Base. iszero (:: Tangent{<:,NamedTuple{}} ) = true
364
365
Base. iszero (:: Tangent{<:,Tuple{}} ) = true
365
366
0 commit comments