Packages
io_ansi_plus
0.1.16
0.1.84
0.1.83
0.1.82
0.1.81
0.1.80
0.1.79
0.1.78
0.1.77
0.1.76
0.1.73
0.1.72
0.1.71
0.1.70
0.1.69
0.1.68
0.1.67
0.1.66
0.1.65
0.1.63
0.1.62
0.1.61
0.1.60
0.1.59
0.1.58
0.1.57
0.1.56
0.1.55
0.1.54
0.1.53
0.1.52
0.1.51
0.1.50
0.1.49
0.1.48
0.1.47
0.1.46
0.1.45
0.1.44
0.1.43
0.1.41
0.1.40
0.1.39
0.1.38
0.1.37
0.1.36
0.1.35
0.1.34
0.1.33
0.1.32
0.1.31
0.1.30
0.1.29
0.1.28
0.1.27
0.1.26
0.1.25
0.1.24
0.1.23
0.1.22
0.1.21
0.1.20
0.1.19
0.1.18
0.1.17
0.1.16
0.1.15
0.1.14
0.1.13
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Functionality to render ANSI escape sequences. Clone of module IO.ANSI but supporting named xterm colors.
Current section
Files
Jump to
Current section
Files
lib/io/ansi/plus/ie.ex
defmodule IO.ANSI.Plus.IE do
alias IO.ANSI.Plus, as: ANSI
def list do
map =
:io_ansi_plus
|> Application.get_env(:color_codes)
|> Map.new(fn {name, code} -> {code, name} end)
blacks =
[7, 10, 11, 14, 15] ++
Enum.to_list(34..51) ++
Enum.to_list(70..87) ++
Enum.to_list(106..123) ++
Enum.to_list(142..159) ++
Enum.to_list(178..195) ++
Enum.to_list(214..231) ++ Enum.to_list(244..255)
IO.write("\n")
# Print 8 standard colors...
[:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
|> Enum.each(fn name ->
[
:"#{name}_background",
if(name == :white, do: :black, else: :light_white),
String.pad_trailing("#{inspect(name)}", 14 + 1)
]
|> ANSI.write()
end)
IO.write("\n")
# Print 8 "light" standard colors...
[:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
|> Enum.each(fn name ->
name = :"light_#{name}"
[
:"#{name}_background",
if(name in [:light_white, :light_yellow, :light_green, :light_cyan],
do: :black,
else: :light_white
),
String.pad_trailing("#{inspect(name)}", 14 + 1)
]
|> ANSI.write()
end)
IO.write("\n\n")
keyword =
for i <- 0..15 do
if map[i], do: {map[i], i}, else: {:"color#{i}", i}
end
keywords = Enum.chunk_every(keyword, 8)
# Print first 16 Xterm colors...
for keyword <- keywords do
Enum.each(keyword, fn {name, code} ->
[
:"#{name}_background",
if(code in blacks, do: :black, else: :light_white),
String.pad_trailing("#{inspect(name)} (#{code})", 14 + 1)
]
|> ANSI.write()
end)
IO.write("\n")
end
IO.write("\n")
keyword =
for i <- 16..255 do
# for i <- 16..96 do
if map[i], do: {map[i], i}, else: {:"color#{i}", i}
end
except = [
49,
165,
126,
184,
190,
107,
162,
19,
103,
147,
124,
168,
50,
80,
129,
204,
28,
130,
136,
42,
108,
97,
211,
56,
164,
69,
93,
225,
247
]
max =
keyword
|> Enum.map(fn {name, code} ->
if code in except do
"#{inspect(name)}" |> String.length()
else
"#{inspect(name)} (#{code})" |> String.length()
end
end)
|> Enum.max()
keywords = Enum.chunk_every(keyword, 6)
# Print next 240 Xterm colors...
for keyword <- keywords do
Enum.each(keyword, fn {name, code} ->
[
:"#{name}_background",
if(code in blacks, do: :black, else: :light_white),
if code in except do
String.pad_trailing("#{inspect(name)}", max + 1)
else
String.pad_trailing("#{inspect(name)} (#{code})", max + 1)
end
]
|> ANSI.write()
end)
IO.write("\n")
end
IO.write("\n")
:ok
end
end