@@ -9,12 +9,12 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
99 if force_unknown_rows
1010 rows = nothing
1111 data = Iterators. take (source, 10 ) |> collect
12- elseif Base. IteratorSize (source) isa Union{Base. HasLength, Base. HasShape{1 }}
12+ elseif Base. IteratorSize (source) isa Union{Base. HasLength,Base. HasShape{1 }}
1313 rows = length (source)
1414 data = Iterators. take (source, 10 ) |> collect
1515 else
1616 data_plus_one = Iterators. take (source, 11 ) |> collect
17- if length (data_plus_one)< 11
17+ if length (data_plus_one) < 11
1818 rows = length (data_plus_one)
1919 data = data_plus_one
2020 else
@@ -29,14 +29,14 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
2929
3030 colnames = String .(fieldnames (eltype (source)))
3131
32- NAvalues = [r== 0 ? false : DataValues. isna (data[r][c]) for r in 0 : length (data), c in 1 : cols]
32+ NAvalues = [r == 0 ? false : DataValues. isna (data[r][c]) for r in 0 : length (data), c in 1 : cols]
3333
34- data = [r== 0 ? colnames[c] : isa (data[r][c], AbstractString) ? data[r][c] : sprint (io-> show (IOContext (io, :compact => true ), data[r][c])) for r in 0 : length (data), c in 1 : cols]
34+ data = [r == 0 ? colnames[c] : isa (data[r][c], AbstractString) ? data[r][c] : sprint (io -> show (IOContext (io, :compact => true ), data[r][c])) for r in 0 : length (data), c in 1 : cols]
3535
36- maxwidth = [maximum (Unicode. textwidth .(data[:,c])) for c in 1 : cols]
36+ maxwidth = [maximum (Unicode. textwidth .(data[:, c])) for c in 1 : cols]
3737
3838 available_heigth, available_width = displaysize (io)
39- available_width -= 1
39+ available_width -= 1
4040
4141 shortened_rows = Set {Int} ()
4242
@@ -47,67 +47,67 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
4747 return string (s, ' ' ^ m)
4848 end
4949
50- while sum (maxwidth) + (size (data,2 ) - 1 ) * 3 > available_width
51- if size (data,2 ) == 1
52- for r in 1 : size (data,1 )
53- if length (data[r,1 ])> available_width
54- data[r,1 ] = data[r,1 ][1 : nextind (data[r,1 ], 0 , available_width- 2 )] * " \" "
50+ while sum (maxwidth) + (size (data, 2 ) - 1 ) * 3 > available_width
51+ if size (data, 2 ) == 1
52+ for r in 1 : size (data, 1 )
53+ if length (data[r, 1 ]) > available_width
54+ data[r, 1 ] = data[r, 1 ][1 : nextind (data[r, 1 ], 0 , available_width - 2 )] * " \" "
5555 push! (shortened_rows, r)
5656 end
5757 end
5858 maxwidth[1 ] = available_width
5959 break
6060 else
61- data = data[:,1 : end - 1 ]
61+ data = data[:, 1 : end - 1 ]
6262
63- maxwidth = [maximum (length .(data[:,c])) for c in 1 : size (data,2 )]
63+ maxwidth = [maximum (length .(data[:, c])) for c in 1 : size (data, 2 )]
6464 end
6565 end
6666
67- for c in 1 : size (data,2 )
67+ for c in 1 : size (data, 2 )
6868 print (io, rpad (colnames[c], maxwidth[c]))
69- if c< size (data,2 )
69+ if c < size (data, 2 )
7070 print (io, " │ " )
7171 end
7272 end
7373 println (io)
74- for c in 1 : size (data,2 )
74+ for c in 1 : size (data, 2 )
7575 print (io, repeat (" ─" , maxwidth[c]))
76- if c< size (data,2 )
76+ if c < size (data, 2 )
7777 print (io, " ─┼─" )
7878 end
7979 end
80- for r in 2 : size (data,1 )
80+ for r in 2 : size (data, 1 )
8181 println (io)
82- for c in 1 : size (data,2 )
82+ for c in 1 : size (data, 2 )
8383
8484 if r in shortened_rows
85- print (io, data[r,c],)
85+ print (io, data[r, c],)
8686 print (io, " …" )
8787 else
88- if NAvalues[r,c]
89- printstyled (io, rpad (data[r,c], maxwidth[c]), color= :light_black )
88+ if NAvalues[r, c]
89+ printstyled (io, rpad (data[r, c], maxwidth[c]), color= :light_black )
9090 else
91- print (io, textwidth_based_rpad (data[r,c], maxwidth[c]))
91+ print (io, textwidth_based_rpad (data[r, c], maxwidth[c]))
9292 end
9393 end
94- if c< size (data,2 )
94+ if c < size (data, 2 )
9595 print (io, " │ " )
9696 end
9797 end
9898 end
9999
100- if rows=== nothing
100+ if rows === nothing
101101 row_post_text = " more rows"
102- elseif rows > size (data,1 ) - 1
102+ elseif rows > size (data, 1 ) - 1
103103 extra_rows = rows - 10
104104 row_post_text = " $extra_rows more $(extra_rows== 1 ? " row" : " rows" ) "
105105 else
106106 row_post_text = " "
107107 end
108108
109- if size (data,2 ) != cols
110- extra_cols = cols- size (data,2 )
109+ if size (data, 2 ) != cols
110+ extra_cols = cols - size (data, 2 )
111111 col_post_text = " $extra_cols more $(extra_cols== 1 ? " column" : " columns" ) : "
112112 col_post_text *= Base. join ([colnames[cols- extra_cols+ 1 : end ]. .. ], " , " )
113113 else
@@ -116,7 +116,7 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
116116
117117 if ! isempty (row_post_text) || ! isempty (col_post_text)
118118 println (io)
119- print (io," ... with " )
119+ print (io, " ... with " )
120120 if ! isempty (row_post_text)
121121 print (io, row_post_text)
122122 end
@@ -136,11 +136,11 @@ function printHTMLtable(io, source; force_unknown_rows=false)
136136
137137 if force_unknown_rows
138138 rows = nothing
139- elseif Base. IteratorSize (source) isa Union{Base. HasLength, Base. HasShape{1 }}
139+ elseif Base. IteratorSize (source) isa Union{Base. HasLength,Base. HasShape{1 }}
140140 rows = length (source)
141141 else
142- count_needed_plus_one = Iterators. count (i-> true , Iterators. take (source, max_elements+ 1 ))
143- rows = count_needed_plus_one< max_elements+ 1 ? count_needed_plus_one : nothing
142+ count_needed_plus_one = Iterators. count (i -> true , Iterators. take (source, max_elements + 1 ))
143+ rows = count_needed_plus_one < max_elements + 1 ? count_needed_plus_one : nothing
144144 end
145145
146146 haslimit = get (io, :limit , true )
@@ -166,18 +166,18 @@ function printHTMLtable(io, source; force_unknown_rows=false)
166166 for c in values (r)
167167 print (io, " <td>" )
168168 if c isa Dates. AbstractTime
169- Markdown. htmlesc (io, sprint (io-> print (IOContext (io, :compact => true ),c)))
169+ Markdown. htmlesc (io, sprint (io -> print (IOContext (io, :compact => true ), c)))
170170 elseif c isa DataValues. DataValue && DataValues. hasvalue (c) && c[] isa Dates. AbstractDateTime
171- Markdown. htmlesc (io, sprint (io-> print (IOContext (io, :compact => true ),c[])))
171+ Markdown. htmlesc (io, sprint (io -> print (IOContext (io, :compact => true ), c[])))
172172 else
173- Markdown. htmlesc (io, sprint (io-> show (IOContext (io, :compact => true ),c)))
173+ Markdown. htmlesc (io, sprint (io -> show (IOContext (io, :compact => true ), c)))
174174 end
175175 print (io, " </td>" )
176176 end
177177 print (io, " </tr>" )
178178 end
179179
180- if rows== nothing
180+ if rows == nothing
181181 row_post_text = " ... with more rows."
182182 elseif rows > max_elements
183183 extra_rows = rows - max_elements
@@ -215,38 +215,38 @@ julia_type_to_schema_type(::Type{T}) where {T<:Dates.Time} = "time"
215215julia_type_to_schema_type (:: Type{T} ) where {T<: Dates.Date } = " date"
216216julia_type_to_schema_type (:: Type{T} ) where {T<: Dates.DateTime } = " datetime"
217217julia_type_to_schema_type (:: Type{T} ) where {T<: AbstractString } = " string"
218- julia_type_to_schema_type (:: Type{T} ) where {S, T<: DataValues.DataValue{S} } = julia_type_to_schema_type (S)
218+ julia_type_to_schema_type (:: Type{T} ) where {S,T<: DataValues.DataValue{S} } = julia_type_to_schema_type (S)
219219
220220own_json_formatter (io, x) = JSON. print (io, x)
221- own_json_formatter (io, x:: DataValues.DataValue ) = DataValues. isna (x) ? JSON. print (io,nothing ) : own_json_formatter (io, x[])
221+ own_json_formatter (io, x:: DataValues.DataValue ) = DataValues. isna (x) ? JSON. print (io, nothing ) : own_json_formatter (io, x[])
222222
223223function printdataresource (io:: IO , source)
224224 if Base. IteratorEltype (source) isa Base. EltypeUnknown
225225 first_el = first (source)
226226 col_names = String .(propertynames (first_el))
227- col_types = [fieldtype (typeof (first_el), i) for i= 1 : length (col_names)]
227+ col_types = [fieldtype (typeof (first_el), i) for i = 1 : length (col_names)]
228228 else
229229 col_names = String .(fieldnames (eltype (source)))
230- col_types = [fieldtype (eltype (source), i) for i= 1 : length (col_names)]
230+ col_types = [fieldtype (eltype (source), i) for i = 1 : length (col_names)]
231231 end
232- schema = Dict (" fields" => [Dict (" name" => string (i[1 ]), " type" => julia_type_to_schema_type (i[2 ])) for i in zip (col_names, col_types)])
232+ schema = Dict (" fields" => [Dict (" name" => string (i[1 ]), " type" => julia_type_to_schema_type (i[2 ])) for i in zip (col_names, col_types)])
233233
234234 print (io, " {" )
235235 JSON. print (io, " schema" )
236236 print (io, " :" )
237- JSON. print (io,schema)
238- print (io," ," )
237+ JSON. print (io, schema)
238+ print (io, " ," )
239239 JSON. print (io, " data" )
240240 print (io, " :[" )
241241
242242 for (row_i, row) in enumerate (source)
243- if row_i> 1
243+ if row_i > 1
244244 print (io, " ," )
245245 end
246246
247247 print (io, " {" )
248248 for col in 1 : length (col_names)
249- if col> 1
249+ if col > 1
250250 print (io, " ," )
251251 end
252252 JSON. print (io, col_names[col])
0 commit comments