Skip to content

Commit 58507e5

Browse files
KristofferCtecosaur
authored andcommitted
Fully qualify method overloads, avoid importing
Avoid importing bindings that are not extended, and use explicit module prefixes for those that we do extend. This make it clearer when and where overloads are occurring.
1 parent fc686f3 commit 58507e5

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/StyledStrings.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
module StyledStrings
44

5-
import Base: AnnotatedString, AnnotatedChar, annotations, annotate!,
6-
annotatedstring, convert, merge, show, print, write,
7-
ScopedValue, with, @with
5+
using Base: AnnotatedString, AnnotatedChar, annotations, annotate!, annotatedstring,
6+
ScopedValue, with, @with
87

98
export @styled_str
109
public Face, addface!, withfaces, styled, SimpleColor

src/faces.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ end
2727
SimpleColor(r::Integer, g::Integer, b::Integer) = SimpleColor((; r=UInt8(r), g=UInt8(g), b=UInt8(b)))
2828
SimpleColor(rgb::UInt32) = SimpleColor(reverse(reinterpret(UInt8, [rgb]))[2:end]...)
2929

30-
convert(::Type{SimpleColor}, (; r, g, b)::RGBTuple) = SimpleColor((; r, g, b))
31-
convert(::Type{SimpleColor}, namedcolor::Symbol) = SimpleColor(namedcolor)
32-
convert(::Type{SimpleColor}, rgb::UInt32) = SimpleColor(rgb)
30+
Base.convert(::Type{SimpleColor}, (; r, g, b)::RGBTuple) = SimpleColor((; r, g, b))
31+
Base.convert(::Type{SimpleColor}, namedcolor::Symbol) = SimpleColor(namedcolor)
32+
Base.convert(::Type{SimpleColor}, rgb::UInt32) = SimpleColor(rgb)
3333

3434
"""
3535
tryparse(::Type{SimpleColor}, rgb::String)
@@ -175,7 +175,7 @@ Base.copy(f::Face) =
175175
f.foreground, f.background, f.underline,
176176
f.strikethrough, f.inverse, copy(f.inherit))
177177

178-
function show(io::IO, ::MIME"text/plain", color::SimpleColor)
178+
function Base.show(io::IO, ::MIME"text/plain", color::SimpleColor)
179179
skiptype = get(io, :typeinfo, nothing) === SimpleColor
180180
skiptype || show(io, SimpleColor)
181181
skiptype || print(io, '(')
@@ -195,7 +195,7 @@ function show(io::IO, ::MIME"text/plain", color::SimpleColor)
195195
nothing
196196
end
197197

198-
function show(io::IO, color::SimpleColor)
198+
function Base.show(io::IO, color::SimpleColor)
199199
show(io, SimpleColor)
200200
print(io, '(')
201201
if color.value isa RGBTuple
@@ -210,7 +210,7 @@ function show(io::IO, color::SimpleColor)
210210
print(io, ')')
211211
end
212212

213-
function show(io::IO, ::MIME"text/plain", face::Face)
213+
function Base.show(io::IO, ::MIME"text/plain", face::Face)
214214
if get(io, :compact, false)::Bool
215215
show(io, Face)
216216
if get(io, :color, false)::Bool
@@ -285,7 +285,7 @@ function show(io::IO, ::MIME"text/plain", face::Face)
285285
end
286286
end
287287

288-
function show(io::IO, face::Face)
288+
function Base.show(io::IO, face::Face)
289289
show(IOContext(io, :compact => true), MIME("text/plain"), face)
290290
end
291291

@@ -489,7 +489,7 @@ withfaces(f) = f()
489489
Merge the properties of the `initial` face and `others`, with
490490
later faces taking priority.
491491
"""
492-
function merge(a::Face, b::Face)
492+
function Base.merge(a::Face, b::Face)
493493
if isempty(b.inherit)
494494
Face(ifelse(isnothing(b.font), a.font, b.font),
495495
if isnothing(b.height) a.height
@@ -515,7 +515,7 @@ function merge(a::Face, b::Face)
515515
end
516516
end
517517

518-
merge(a::Face, b::Face, others::Face...) = merge(merge(a, b), others...)
518+
Base.merge(a::Face, b::Face, others::Face...) = merge(merge(a, b), others...)
519519

520520
## Getting the combined face from a set of properties ##
521521

@@ -647,7 +647,7 @@ Load all faces declared in the Faces.toml file `tomlfile`.
647647
"""
648648
loaduserfaces!(tomlfile::String) = loaduserfaces!(Base.parsed_toml(tomlfile))
649649

650-
function convert(::Type{Face}, spec::Dict)
650+
function Base.convert(::Type{Face}, spec::Dict)
651651
Face(if haskey(spec, "font") && spec["font"] isa String
652652
spec["font"] end,
653653
if haskey(spec, "height") && (spec["height"] isa Int || spec["height"] isa Float64)

src/io.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,22 @@ function _ansi_writer(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedS
250250
end
251251
end
252252

253-
write(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
253+
Base.write(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
254254
_ansi_writer(io, s, write)::Int
255255

256-
print(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
256+
Base.print(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
257257
(_ansi_writer(io, s, print); nothing)
258258

259259
# We need to make sure that printing to an `AnnotatedIOBuffer` calls `write` not `print`
260260
# so we get the specialised handling that `_ansi_writer` doesn't provide.
261-
print(io::Base.AnnotatedIOBuffer, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
261+
Base.print(io::Base.AnnotatedIOBuffer, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
262262
(write(io, s); nothing)
263263

264264
escape_string(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}},
265265
esc = ""; keep = ()) =
266266
(_ansi_writer(io, s, (io, s) -> escape_string(io, s, esc; keep)); nothing)
267267

268-
function write(io::IO, c::AnnotatedChar)
268+
function Base.write(io::IO, c::AnnotatedChar)
269269
if get(io, :color, false) == true
270270
termstyle(io, getface(c), getface())
271271
bytes = write(io, c.char)
@@ -276,9 +276,9 @@ function write(io::IO, c::AnnotatedChar)
276276
end
277277
end
278278

279-
print(io::IO, c::AnnotatedChar) = (write(io, c); nothing)
279+
Base.print(io::IO, c::AnnotatedChar) = (write(io, c); nothing)
280280

281-
function show(io::IO, c::AnnotatedChar)
281+
function Base.show(io::IO, c::AnnotatedChar)
282282
if get(io, :color, false) == true
283283
out = IOBuffer()
284284
show(out, c.char)
@@ -288,7 +288,7 @@ function show(io::IO, c::AnnotatedChar)
288288
end
289289
end
290290

291-
function write(io::IO, aio::Base.AnnotatedIOBuffer)
291+
function Base.write(io::IO, aio::Base.AnnotatedIOBuffer)
292292
if get(io, :color, false) == true
293293
# This does introduce an overhead that technically
294294
# could be avoided, but I'm not sure that it's currently
@@ -430,7 +430,7 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
430430
print(io, "\">")
431431
end
432432

433-
function show(io::IO, ::MIME"text/html", s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}; wrap::Symbol=:pre)
433+
function Base.show(io::IO, ::MIME"text/html", s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}; wrap::Symbol=:pre)
434434
htmlescape(str) = replace(str, '&' => "&amp;", '<' => "&lt;", '>' => "&gt;")
435435
buf = IOBuffer() # Avoid potential overhead in repeatadly printing a more complex IO
436436
wrap == :none ||

0 commit comments

Comments
 (0)