IO.ANSI
module docs have less test approaches. They did not specify any good examples for the definitions in the module.
did anybody find the good docs with examples to try IO.ANSI
module?
Elixir v1.4
Thanks in advance
Just had a look at it now… it’s really just a collection of functions that will give you ANSI codes back, so you can use them in eg. terminal output:
Even better, of course, to use iolists:
There’s also some useful formatting functionality, that will convert atoms to the corresponding ANSI codes, with the option of rendering the ANSI output or not (the boolean at the end):
As for the IO.ANSI.Docs.* functions though, I’m not sure… going to look at the source for a bit
Well said
Thanks for the Reply
As for the IO.ANSI.Docs stuff, it’s not documented so I’d be wary of using it except for playing around… BUT it seems to render markdown quite nicely for terminal output.
If we do something like this in iex
…
my_title = "It's a Title"
my_doc = """
# Heading
Paragraph..
- list item 1
- list item 2
## Heading 2
This is some code:
x = 15
y = 5
IO.inspect(x + y)
..and a table:
Column A | Column B
-- | --
10 | 20
20 | 40
We can _underline_ text and make it *bold,* of course!
Linking also.. [foo](https://bar.baaz/).
"""
doc_printer = fn(heading, doc) ->
IO.ANSI.Docs.print_heading(heading)
IO.ANSI.Docs.print(doc)
end
doc_printer.(my_title, my_doc)
…then we get the following output:
You just need to learn about ANSI codes to use the ANSI module.
As always, going to plug my text style library that uses ANSI under the hood: https://github.com/sotojuan/exchalk
awesome thanks for pointing out,and your lib exchalk
is fantastic .