Skip to content

Repository files navigation

CodeFrame

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:

Picture of the code frame

Installation

The package can be installed by adding code_frame to your list of dependencies in mix.exs:

defdepsdo[{:code_frame,"~> 0.1.0"}]end

Don't forget to run mix deps.get to fetch the new dependencies.

Usage

Building a custom codeframe is pretty straightforward. Just pass the string and specify the line you want to draw attention to and thats it.

defmoduleFoodoimportCodeFramedefmain()domy_string="foo\nbar\nbaz"frame=build(my_string,1)IO.puts(frame)endend

build() has the following options:

OptionDescription
lines_before: integerNumber of lines to show before the highlighted one.
lines_after: integerNumber of lines to show after the highlighted one.
colors: booleanForce enabling/disabling of colorized output.

License

MIT, see License file.

About

Make beautiful errors by showing where they are in the code

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages