Revision f4c4c33c762f86db72cc7a7bcf2639cb8fbf3395 authored by Jerry Ling on 20 October 2022, 13:14:25 UTC, committed by GitHub on 20 October 2022, 13:14:25 UTC
1 parent 82bd71b
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
Computing file changes ...