Build code frames that point to a specific location. Inspired by @babel/code-frame. This is mainly useful for error locations (syntax errors, etc).
Screenshot of colorized output:
The package can be installed by adding code_frame to your list of
dependencies in mix.exs:
def deps do
[{:code_frame, "~> 0.1.0"}]
endDon't forget to run mix deps.get to fetch the new dependencies.
Building a custom codeframe is pretty straightforward. Just pass the string and specify the line you want to draw attention to and thats it.
defmodule Foo do
import CodeFrame
def main() do
my_string = "foo\nbar\nbaz"
frame = build(my_string, 1)
IO.puts(frame)
end
endbuild() has the following options:
| Option | Description |
|---|---|
lines_before: integer |
Number of lines to show before the highlighted one. |
lines_after: integer |
Number of lines to show after the highlighted one. |
colors: boolean |
Force enabling/disabling of colorized output. |
MIT, see License file.
