Created
January 12, 2023 09:42
-
-
Save TwistingTwists/c932c862b82f48f469b95435f217fb64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Helpers.ColorIO do | |
| # random comments - garbage collector | |
| # {:purge_logical_names_after_every, "PURGE_LOGICAL_NAMES_AFTER_EVERY", | |
| # required: false, map: &String.to_integer/1}, | |
| @the_types [ | |
| :number, | |
| :atom, | |
| :string, | |
| :boolean, | |
| :binary, | |
| :bitstring, | |
| :list, | |
| :map, | |
| :regex, | |
| :tuple, | |
| :function, | |
| :struct, | |
| :pid, | |
| :port, | |
| :reference, | |
| :date, | |
| :datetime, | |
| nil | |
| ] | |
| @green Enum.map(@the_types, fn t -> {t, :green} end) | |
| @red Enum.map(@the_types, fn t -> {t, :red} end) | |
| @yellow Enum.map(@the_types, fn t -> {t, :yellow} end) | |
| @blue Enum.map(@the_types, fn t -> {t, :cyan} end) | |
| @purple Enum.map(@the_types, fn t -> {t, IO.ANSI.color(4, 2, 5)} end) | |
| @orange Enum.map(@the_types, fn t -> {t, IO.ANSI.color(4, 2, 0)} end) | |
| @multi Enum.map(@the_types, fn t -> | |
| case t do | |
| :number -> {t, :yellow} | |
| :pid -> {t, :red} | |
| :bitstring -> {t, :cyan} | |
| :map -> {t, :green} | |
| :atom -> {t, IO.ANSI.color(4, 2, 0)} | |
| :date -> {t, :blue} | |
| :datetime -> {t, :blue} | |
| :list -> {t, IO.ANSI.color(1, 5, 0)} | |
| # :string -> {t, IO.ANSI.color(4,2,5)} | |
| # :binary -> {t, IO.ANSI.color(0,2,5)} | |
| _ -> {t, IO.ANSI.color(4, 2, 5)} | |
| end | |
| end) | |
| def green(data, label \\ ""), do: prnt(data, @green, label) | |
| def red(data, label \\ ""), do: prnt(data, @red, label) | |
| def yellow(data, label \\ ""), do: prnt(data, @yellow, label) | |
| def blue(data, label \\ ""), do: prnt(data, @blue, label) | |
| def orange(data, label \\ ""), do: prnt(data, @orange, label) | |
| def purple(data, label \\ ""), do: prnt(data, @purple, label) | |
| def log(data, label \\ ""), do: prnt(data, @multi, label) | |
| defp prnt(data, colors, label) do | |
| IO.inspect("========= #{label} ========") | |
| IO.inspect(data, syntax_colors: colors, pretty: true) | |
| data | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment