@@ -49,91 +49,34 @@ function _truncate_at_width_or_chars(str, width, chars="", truncmark="…")
4949end
5050
5151function show {K,V} (io:: IO , t:: Associative{K,V} )
52- recur_io = IOContext (io, SHOWN_SET= t, multiline = false )
52+ recur_io = IOContext (io, : SHOWN_SET => t )
5353 limit:: Bool = get (io, :limit , false )
54- compact = ! get (io, :multiline , false )
5554 if ! haskey (io, :compact )
56- recur_io = IOContext (recur_io, compact= true )
55+ recur_io = IOContext (recur_io, : compact => true )
5756 end
58- if compact
59- # show in a Julia-syntax-like form: Dict(k=>v, ...)
60- if isempty (t)
61- print (io, typeof (t), " ()" )
62- else
63- if isleaftype (K) && isleaftype (V)
64- print (io, typeof (t). name)
65- else
66- print (io, typeof (t))
67- end
68- print (io, ' (' )
69- if ! show_circular (io, t)
70- first = true
71- n = 0
72- for pair in t
73- first || print (io, ' ,' )
74- first = false
75- show (recur_io, pair)
76- n+= 1
77- limit && n >= 10 && (print (io, " …" ); break )
78- end
79- end
80- print (io, ' )' )
81- end
82- return
83- end
84-
85- # Otherwise show more descriptively, with one line per key/value pair
86- print (io, summary (t))
87- isempty (t) && return
88- print (io, " :\n " )
89- show_circular (io, t) && return
90- if limit
91- sz = displaysize (io)
92- rows, cols = sz[1 ] - 3 , sz[2 ]
93- rows < 2 && (print (io, " …" ); return )
94- cols < 12 && (cols = 12 ) # Minimum widths of 2 for key, 4 for value
95- cols -= 6 # Subtract the widths of prefix " " separator " => "
96- rows -= 2 # Subtract the summary and final ⋮ continuation lines
97-
98- # determine max key width to align the output, caching the strings
99- ks = Array {AbstractString} (min (rows, length (t)))
100- vs = Array {AbstractString} (min (rows, length (t)))
101- keylen = 0
102- vallen = 0
103- for (i, (k, v)) in enumerate (t)
104- i > rows && break
105- ks[i] = sprint (0 , show, k, env= recur_io)
106- vs[i] = sprint (0 , show, v, env= recur_io)
107- keylen = clamp (length (ks[i]), keylen, cols)
108- vallen = clamp (length (vs[i]), vallen, cols)
109- end
110- if keylen > max (div (cols, 2 ), cols - vallen)
111- keylen = max (cld (cols, 3 ), cols - vallen)
112- end
113- else
114- rows = cols = 0
115- end
116-
117- first = true
118- for (i, (k, v)) in enumerate (t)
119- first || print (io, " \n " )
120- first = false
121- limit && i > rows && (print (io, rpad (" ⋮" , keylen), " => ⋮" ); break )
12257
123- if limit
124- key = rpad (_truncate_at_width_or_chars (ks[i], keylen, " \r\n " ), keylen)
58+ # show in a Julia-syntax-like form: Dict(k=>v, ...)
59+ if isempty (t)
60+ print (io, typeof (t), " ()" )
61+ else
62+ if isleaftype (K) && isleaftype (V)
63+ print (io, typeof (t). name)
12564 else
126- key = sprint ( 0 , show, k, env = recur_io )
65+ print (io, typeof (t) )
12766 end
128- print (recur_io, key)
129- print (io, " => " )
130-
131- if limit
132- val = _truncate_at_width_or_chars (vs[i], cols - keylen, " \r\n " )
133- print (io, val)
134- else
135- show (recur_io, v)
67+ print (io, ' (' )
68+ if ! show_circular (io, t)
69+ first = true
70+ n = 0
71+ for pair in t
72+ first || print (io, ' ,' )
73+ first = false
74+ show (recur_io, pair)
75+ n+= 1
76+ limit && n >= 10 && (print (io, " …" ); break )
77+ end
13678 end
79+ print (io, ' )' )
13780 end
13881end
13982
14790summary {T<:Union{KeyIterator,ValueIterator}} (iter:: T ) =
14891 string (T. name, " for a " , summary (iter. dict))
14992
150- function show (io:: IO , iter:: Union{KeyIterator,ValueIterator} )
151- if ! get (io, :multiline , false )
152- return show (io, collect (iter))
153- end
154- print (io, summary (iter))
155- isempty (iter) && return
156- print (io, " . " , isa (iter,KeyIterator) ? " Keys" : " Values" , " :" )
157- limit:: Bool = get (io, :limit , false )
158- if limit
159- sz = displaysize (io)
160- rows, cols = sz[1 ] - 3 , sz[2 ]
161- rows < 2 && (print (io, " …" ); return )
162- cols < 4 && (cols = 4 )
163- cols -= 2 # For prefix " "
164- rows -= 2 # For summary and final ⋮ continuation lines
165- else
166- rows = cols = 0
167- end
168-
169- for (i, v) in enumerate (iter)
170- print (io, " \n " )
171- limit && i >= rows && (print (io, " ⋮" ); break )
172-
173- if limit
174- str = sprint (0 , show, v, env= io)
175- str = _truncate_at_width_or_chars (str, cols, " \r\n " )
176- print (io, str)
177- else
178- show (io, v)
179- end
180- end
181- end
93+ show (io:: IO , iter:: Union{KeyIterator,ValueIterator} ) = show (io, collect (iter))
18294
18395length (v:: Union{KeyIterator,ValueIterator} ) = length (v. dict)
18496isempty (v:: Union{KeyIterator,ValueIterator} ) = isempty (v. dict)
0 commit comments