Skip to content

Purity of low level functions / performance #107

@t-bltg

Description

@t-bltg

Some low level StyledStrings functions are not pure, they depend on global states e.g. Base.have_truecolor, ...

E.g.:

StyledStrings.jl/src/io.jl

Lines 116 to 120 in 8985a37

if Base.get_have_truecolor()
termcolor24bit(io, color.value, category)
else
termcolor8bit(io, color.value, category)
end

which induces annoying workarounds such as
prev_terminfo = getglobal(Base, :current_terminfo)
prev_truecolor = getglobal(Base, :have_truecolor)
try
setglobal!(Base, :current_terminfo, tinfo)
setglobal!(Base, :have_truecolor, haskey(tinfo, :setrgbf))
fn()
finally
setglobal!(Base, :current_terminfo, prev_terminfo)
setglobal!(Base, :have_truecolor, prev_truecolor)
end

This is currently blocking in my trial PR to transition from Crayons.jl to the StyledsStrings stdlib, for UnicodePlots.jl.

Also, I'm not sure transitioning will lead to a performance statu quo or gain in terms of performance / allocations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions