Skip to content

Commit 75014c5

Browse files
committed
Make terminfo easier to compile
1 parent 481af56 commit 75014c5

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

base/terminfo.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ function read(data::IO, ::Type{TermInfoRaw})
9595
throw(ArgumentError("Terminfo did not contain a null byte after the flag section, expected to position the start of the numbers section on an even byte"))
9696
end
9797
# Numbers, Strings, Table
98-
numbers = reinterpret(NumInt, read(data, numbers_count * sizeof(NumInt))) .|> ltoh
99-
string_indices = reinterpret(UInt16, read(data, string_count * sizeof(UInt16))) .|> ltoh
98+
numbers = map(ltoh, reinterpret(NumInt, read(data, numbers_count * sizeof(NumInt))))
99+
string_indices = map(ltoh, reinterpret(UInt16, read(data, string_count * sizeof(UInt16))))
100100
strings_table = read(data, table_bytes)
101101
strings = map(string_indices) do idx
102102
if idx (0xffff, 0xfffe)
@@ -107,7 +107,7 @@ function read(data::IO, ::Type{TermInfoRaw})
107107
end
108108
end
109109
TermInfoRaw(term_names, flags, numbers, strings,
110-
if !eof(data) extendedterminfo(data; NumInt) end)
110+
if !eof(data) extendedterminfo(data, NumInt) end)
111111
end
112112

113113
"""
@@ -119,7 +119,7 @@ This will accept any terminfo content that conforms with `term(5)`.
119119
120120
See also: `read(::IO, ::Type{TermInfoRaw})`
121121
"""
122-
function extendedterminfo(data::IO; NumInt::Union{Type{UInt16}, Type{UInt32}})
122+
function extendedterminfo(data::IO, NumInt::Union{Type{UInt16}, Type{UInt32}})
123123
# Extended info
124124
if position(data) % 2 != 0
125125
0x00 == read(data, UInt8) ||
@@ -138,12 +138,15 @@ function extendedterminfo(data::IO; NumInt::Union{Type{UInt16}, Type{UInt32}})
138138
throw(ArgumentError("Terminfo did not contain a null byte after the extended flag section, expected to position the start of the numbers section on an even byte"))
139139
end
140140
numbers = map(n -> Int(ltoh(n)), reinterpret(NumInt, read(data, numbers_count * sizeof(NumInt))))
141-
table_indices = reinterpret(UInt16, read(data, table_count * sizeof(UInt16))) .|> ltoh
141+
table_indices = map(ltoh, reinterpret(UInt16, read(data, table_count * sizeof(UInt16))))
142142
table_strings = [String(readuntil(data, 0x00)) for _ in 1:length(table_indices)]
143+
info = Dict{Symbol, Union{Bool, Int, String}}()
143144
strings = table_strings[1:string_count]
144-
labels = Symbol.(table_strings[string_count+1:end])
145-
Dict{Symbol, Union{Bool, Int, String}}(
146-
labels .=> vcat(flags, numbers, strings))
145+
labels = table_strings[string_count+1:end]
146+
for (label, val) in zip(labels, vcat(flags, numbers, strings))
147+
info[Symbol(label)] = val
148+
end
149+
return info
147150
end
148151

149152
"""
@@ -178,7 +181,7 @@ function TermInfo(raw::TermInfoRaw)
178181
Symbol[]
179182
end
180183
TermInfo(raw.names, length(raw.flags),
181-
raw.numbers .!= typemax(eltype(raw.numbers)),
184+
map(n-> n != typemax(typeof(n)), raw.numbers),
182185
map(!isnothing, raw.strings),
183186
extensions, capabilities)
184187
end

0 commit comments

Comments
 (0)