@@ -5,71 +5,81 @@ using BackendSelection: @Backend_str, AbstractBackend, Backend
55export @visualize , visualize
66
77macro visualize (x, kwargs... )
8- all (kwarg -> Meta. isexpr (kwarg, :(= )), kwargs) ||
9- throw (ArgumentError (" All keyword arguments must be of the form `kw=value`." ))
10- kwargs′ = if all (kwarg -> kwarg. args[1 ] ≠ :name , kwargs)
11- (kwargs... , :(name= $ (string (x))))
12- else
13- kwargs
14- end
15- return :(visualize ($ (esc (x)); $ (esc .(kwargs′)... )); $ (esc (x)))
8+ all (kwarg -> Meta. isexpr (kwarg, :(= )), kwargs) ||
9+ throw (ArgumentError (" All keyword arguments must be of the form `kw=value`." ))
10+ kwargs′ = if all (kwarg -> kwarg. args[1 ] ≠ :name , kwargs)
11+ (kwargs... , :(name = $ (string (x))))
12+ else
13+ kwargs
14+ end
15+ return :(visualize ($ (esc (x)); $ (esc .(kwargs′)... )); $ (esc (x)))
1616end
1717
18- function visualize (io:: IO , x; backend= Backend " Default" , name= nothing , kwargs... )
19- return visualize (io, to_backend (backend; kwargs... ), x; name)
18+ function visualize (io:: IO , x; backend = Backend " Default" , name = nothing , kwargs... )
19+ return visualize (io, to_backend (backend; kwargs... ), x; name)
2020end
2121
22- function visualize (x; backend= Backend " Default" , name= nothing , io:: IO = stdout , kwargs... )
23- return visualize (io, to_backend (backend; kwargs... ), x; name)
22+ function visualize (
23+ x;
24+ backend = Backend " Default" ,
25+ name = nothing ,
26+ io:: IO = stdout ,
27+ kwargs... ,
28+ )
29+ return visualize (io, to_backend (backend; kwargs... ), x; name)
2430end
2531
26- function visualize (io:: IO , backend:: AbstractBackend , x; name= nothing )
27- name = get (backend, :name , name)
28- if isnothing (name)
29- visualize_unnamed (io, backend, x)
32+ function visualize (io:: IO , backend:: AbstractBackend , x; name = nothing )
33+ name = get (backend, :name , name)
34+ if isnothing (name)
35+ visualize_unnamed (io, backend, x)
36+ return nothing
37+ end
38+ visualize_named (io, backend, name, x)
3039 return nothing
31- end
32- visualize_named (io, backend, name, x)
33- return nothing
3440end
3541
36- function visualize (backend:: Backend"Default" , x; name= nothing )
37- io = get (backend, :io , stdout )
38- visualize (io, backend, x; name)
39- return nothing
42+ function visualize (backend:: Backend"Default" , x; name = nothing )
43+ io = get (backend, :io , stdout )
44+ visualize (io, backend, x; name)
45+ return nothing
4046end
4147
4248function visualize_named (io:: IO , backend:: Backend"Default" , name, x)
43- mime = get (backend, :mime , MIME " text/plain" ())
44- println (io, name, " = " )
45- show_indented (io, mime, x)
46- println (io)
47- return nothing
49+ mime = get (backend, :mime , MIME " text/plain" ())
50+ println (io, name, " = " )
51+ show_indented (io, mime, x)
52+ println (io)
53+ return nothing
4854end
4955
5056function visualize_unnamed (io:: IO , :: Backend"Default" , x)
51- show (io, MIME " text/plain" (), x)
52- println (io)
53- return nothing
57+ show (io, MIME " text/plain" (), x)
58+ println (io)
59+ return nothing
5460end
5561
56- function show_indented (io:: IO , mime:: MIME , x; indent= " " )
57- str = sprint (show, mime, x)
58- str = join ((indent * s for s in split (str, ' \n ' )), ' \n ' )
59- print (io, str)
60- return nothing
62+ function show_indented (io:: IO , mime:: MIME , x; indent = " " )
63+ str = sprint (show, mime, x)
64+ str = join ((indent * s for s in split (str, ' \n ' )), ' \n ' )
65+ print (io, str)
66+ return nothing
6167end
6268
6369function to_backend (:: Type{B} ; kwargs... ) where {B}
64- return B (; kwargs... )
70+ return B (; kwargs... )
6571end
66- function to_backend (backend:: Union{Symbol,String} ; kwargs... )
67- return Backend (backend; kwargs... )
72+ function to_backend (backend:: Union{Symbol, String} ; kwargs... )
73+ return Backend (backend; kwargs... )
6874end
6975function to_backend (backend:: AbstractBackend ; kwargs... )
70- isempty (kwargs) ||
71- throw (ArgumentError (" Keyword arguments must be passed as part of the backend object." ))
72- return backend
76+ isempty (kwargs) ||
77+ throw (
78+ ArgumentError (
79+ " Keyword arguments must be passed as part of the backend object." ,
80+ ),
81+ )
82+ return backend
7383end
7484
7585end
0 commit comments