Skip to content

Commit 7968dab

Browse files
authored
Merge pull request #781 from jishnub/compactshow
Define compact show for operators to simplify display for containers
2 parents f9b508f + d2678ac commit 7968dab

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFun"
22
uuid = "28f2ccd6-bb30-5033-b560-165f7b14dc2f"
3-
version = "0.13.3"
3+
version = "0.13.4"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Extras/show.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ function show(io::IO,ss::PiecewiseSpace)
132132
end
133133
end
134134

135-
summary(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")
135+
summarystr(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")
136+
summary(io::IO, ss::ArraySpace) = print(io, summarystr(ss))
136137
function show(io::IO,ss::ArraySpace;header::Bool=true)
137-
header && print(io,summary(ss)*":\n")
138+
header && print(io,summarystr(ss)*":\n")
138139
show(io, ss.spaces)
139140
end
140141

@@ -182,17 +183,18 @@ end
182183

183184
## Operator
184185

185-
summary(B::Operator) =
186-
string(typeof(B).name.name)*" : "*string(domainspace(B))*""*string(rangespace(B))
186+
summarystr(B::Operator) = string(typeof(B).name.name, " : ", domainspace(B), "", rangespace(B))
187+
summary(io::IO, B::Operator) = print(io, summarystr(B))
187188

188189
struct PrintShow
189190
str
190191
end
191192
Base.show(io::IO,N::PrintShow) = print(io,N.str)
192193

194+
show(io::IO, B::Operator) = summary(io, B)
193195

194-
function show(io::IO,B::Operator;header::Bool=true)
195-
header && println(io,summary(B))
196+
function show(io::IO, ::MIME"text/plain", B::Operator;header::Bool=true)
197+
header && println(io, summarystr(B))
196198
dsp=domainspace(B)
197199

198200
if !isambiguous(domainspace(B)) && (eltype(B) <: Number)

test/runtests.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,16 @@ end
215215
N = u -> [u'(0), u(0)-1, x*u'' + 2*u' + x*u^n]
216216
u = newton(N, u₀) # perform Newton iteration in function space
217217
@test u(0.1) 0.9983370741307388
218-
end
218+
end
219+
220+
@testset "show" begin
221+
op = Derivative(Chebyshev())
222+
io = IOBuffer()
223+
@test summary(io, op) isa Nothing
224+
@test contains(String(take!(io)), " : $(domainspace(op))$(rangespace(op))")
225+
show(io, op)
226+
@test contains(String(take!(io)), " : $(domainspace(op))$(rangespace(op))")
227+
228+
@test summary(io, ApproxFun.ArraySpace(Chebyshev(), 2)) isa Nothing
229+
@test contains(String(take!(io)), "ArraySpace")
230+
end

0 commit comments

Comments
 (0)