bjro / apex Goto Github PK
View Code? Open in Web Editor NEWAwesome printing for Elixir
Awesome printing for Elixir
I sometimes launch iex
in a CMD shell and there the colors do absolutely nothing, they even make it worse because CMD is happy to parse the codes without interpreting them.
Maybe an option inside the user's mix.exs
file could address that? Say, enable_colors
which is by default true
but can be set to false
if desired?
Passing Elixir AST (for instance, the output of quote
) triggers the "Elixir record" behavior here.
Example:
iex(3)> ast = quote do
...(3)> foo[1].bar
...(3)> end
{{:., [], [{{:., [], [Access, :get]}, [], [{:foo, [], Elixir}, 1]}, :bar]}, [],
[]}
iex(4)> Apex.ap(ast)
{
[0] .{
[0] []
[1] [
[0] {
[0] .{
[0] []
[1] [
[0] :Elixir.Access
[1] :get
]
}
[1] []
[2] [
[0] foo{
[0] []
[1] :Elixir
}
[1] 1
]
}
[1] :bar
]
}
[1] []
[2] []
}
Would a "no srsly I don't have records here" option make sense? Something like the numbers: false
setting.
Hi, can you tag the latest release? :)
As far as I can tell this isn't possible yet with Apex. The color choices appear to be hardcoded in lib/apex/format/color.ex
, but it would be fantastic if we could tweak them the way we can in AwesomePrint
.
Apex v0.2.0 currently throws compilation warnings and errors.
➜ dmr-watch git:(master) ✗ mix deps.compile
==> idna (compile)
==> apex
warning: the dependency apex requires Elixir "~> 0.14.0" but you are running on v0.15.0
== Compilation error on file lib/apex/format/color.ex ==
** (CompileError) lib/apex/format/color.ex:46: undefined function binary_to_atom/1
(stdlib) lists.erl:1352: :lists.mapfoldl/3
(stdlib) lists.erl:1353: :lists.mapfoldl/3
(elixir) src/elixir.erl:170: :elixir.erl_eval/3
could not compile dependency apex, mix compile failed. You can recompile this dependency with `mix deps.compile apex` or update it with `mix deps.update apex`
or maybe it can just be implemented by defimpl Apex.Format, for: Set
either way, its too trivial to PR :)
Hi,
Can you add this?
defimpl Apex.Format, for: Reference do
import Apex.Format.Utils
def format(data, options \ []) do
colorize(inspect(data), data, options) <> new_line
end
end
If you want a pull req, let me know, otherwise if you have time, can you add it?
Thanks
Ernie
I want to use Apex in my logging, as it makes maps a whole lot easier to read.
To log something in Elixir, one would use Logger.debug(string)
, or variants of it.
doing Logger.debug(Apex.ap(something))
will not work, as Apex.ap
will actually print the formatted result of something to STDOUT, while something
will be returned to the input of Logger.debug
.
Now, Apex internally formats the string using Apex.Format.format
. I would like a shorter version of that, so the log-statements do not become hard to read.
Is this a good idea?
With pry and AwesomePrint, there is a way to make AwesomePrint the default inspector, so that just typing in an expression is equivalent to ap expression
. I believe you just need to require AwesomePrint in the .pryrc
and issue a AwesomePrint.pry!
which does the magic.
Is there any way you'd consider looking into this for Apex? The one thing I miss the most about Ruby is the combination of pry and AwesomePrint --> IEx isn't nearly as nice, but having Apex built in would go a long way :)
Hi,
Could you please add a git tag for the latest version? It would be quite useful for building FreeBSD ports.
This seems like an important compile warning for apex:
warning: function List.unzip/1 is undefined or private
lib/apex/awesome_def.ex:52
And indeed, there is no List.unzip function in the Elixir module list.
iex> Apex.ap {}
OR
iex> Apex.ap {1,2, {}}
** (ArgumentError) argument error
:erlang.hd([])
lib/apex/format/tuple.ex:15: Apex.Format.Tuple.do_format/2
lib/apex/format/seq.ex:23: Apex.Format.Seq.do_format/3
(elixir) lib/enum.ex:981: anonymous fn/3 in Enum.map/2
(elixir) lib/stream.ex:1155: anonymous fn/3 in Enumerable.Stream.reduce/3
(elixir) lib/stream.ex:761: anonymous fn/3 in Stream.with_index/1
(elixir) lib/enum.ex:2213: Enumerable.List.reduce/3
(elixir) lib/stream.ex:1175: Enumerable.Stream.do_each/4
How would I debug something like the following? I'm having trouble debugging controllers in Phoenix. This is just one example.
adef submitted(conn, _params) do
render(conn, "submitted.html")
end
When I do Apex.submitted(conn, params)
in the iex
console, I get iex:6: undefined function conn/0
. I had already imported the module itself.
Hi there,
Great package, but I was wondering if it would be possible to get Apex to return without all the [i]
- this for me makes it really hard to read! It would be great if we could pass an option to Apex.ap
to do this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.