https://github.com/JuliaLang/julia
Raw File
Tip revision: 7401b2efcec18d90a31b66526e4b81ae7008da50 authored by Jeff Bezanson on 05 May 2021, 17:21:15 UTC
represent length of short strings using 1 byte instead of a full word
Tip revision: 7401b2e
ttyhascolor.jl
# This file is a part of Julia. License is MIT: https://julialang.org/license

if Sys.iswindows()
    ttyhascolor(term_type = nothing) = true
else
    function ttyhascolor(term_type = get(ENV, "TERM", ""))
        startswith(term_type, "xterm") && return true
        try
            @static if Sys.KERNEL === :FreeBSD
                return success(`tput AF 0`)
            else
                return success(`tput setaf 0`)
            end
        catch e
            return false
        end
    end
end
function get_have_color()
    global have_color
    have_color === nothing && (have_color = ttyhascolor())
    return have_color::Bool
end
in(key_value::Pair{Symbol,Bool}, ::TTY) = key_value.first === :color && key_value.second === get_have_color()
haskey(::TTY, key::Symbol) = key === :color
getindex(::TTY, key::Symbol) = key === :color ? get_have_color() : throw(KeyError(key))
get(::TTY, key::Symbol, default) = key === :color ? get_have_color() : default
back to top