51 lines
1.8 KiB
Julia
51 lines
1.8 KiB
Julia
module DoomThemes
|
|
|
|
using StyledStrings: Face, getface, resetfaces!, loadface!,
|
|
withfaces, SimpleColor, RGBTuple, @styled_str
|
|
|
|
const THEMES = Dict{Symbol, Vector{Pair{Symbol, Face}}}()
|
|
|
|
function load(theme::Symbol, term::Bool=true)
|
|
faces = get(THEMES, theme, nothing)
|
|
isnothing(faces) && throw(ArgumentError("The doom theme $theme is not defined."))
|
|
resetfaces!()
|
|
foreach(loadface!, faces)
|
|
term || return
|
|
setcolor(id::String, ::Nothing) = print(stdout, "\e]", id, ";\a")
|
|
setcolor(id::String, color::SimpleColor) = if color.value isa RGBTuple
|
|
print(stdout, "\e]", id, ";rgb:", join(string.(values(color.value), base=16), '/'), "\a")
|
|
else
|
|
print(stdout, "\e]", id, ";", string(color.value), "\a")
|
|
end
|
|
(; foreground, background) = getface()
|
|
setcolor("10", if foreground.value isa RGBTuple foreground end)
|
|
setcolor("11", if background.value isa RGBTuple background end)
|
|
cursor = getface(:cursor)
|
|
setcolor("12", if cursor.background.value isa RGBTuple && cursor.background != background
|
|
cursor.background end)
|
|
end
|
|
|
|
function reset(term::Bool=true)
|
|
resetfaces!()
|
|
term || return
|
|
print(stdout, "\e]10;\a\e]11;\a\e]12;\a")
|
|
end
|
|
|
|
function list()
|
|
for theme in sort(keys(THEMES) |> collect)
|
|
withfaces(Dict(THEMES[theme])) do
|
|
print("\e[0m")
|
|
println(styled" $(rpad(theme, 30)) \
|
|
{emphasis:■} {julia_funcall:■} {julia_symbol:■} {julia_type:■} {julia_string:■} \
|
|
{(fg=red):■} {(fg=green):■} {(fg=yellow):■} {(fg=blue):■} \
|
|
{(fg=magenta):■} {(fg=cyan):■} {(fg=white):■} {(fg=black):■}")
|
|
end
|
|
end
|
|
end
|
|
|
|
@eval for theme in readdir(joinpath(@__DIR__, "themes"))
|
|
include("themes/$theme")
|
|
end
|
|
|
|
end
|