A tag struct.
Use Owl.Data.tag/2 to build a tag.
A tag is a container for data and ANSI sequences associated with it. It provides a local binding for styles in the console, similar to HTML tags.
Suppose you have a string that should be written to stdout in red. This can be easily done by using a naive approach:
substring = "world"
IO.puts([IO.ANSI.red(), "Hello #{substring}!!"])It works for simple cases. If you want to make substring another color, you might try this:
substring = [IO.ANSI.green(), "world"]
IO.puts([IO.ANSI.red(), "Hello #{substring}!!"])but you'll notice the text after substring is green too. To make the "!!" part red again, you must
set the color explicitly:
IO.puts([IO.ANSI.red(), "Hello #{substring}#{IO.ANSI.red()}!!"])If substring changes the background color, you must restore the previous one too:
substring = [IO.ANSI.green(), IO.ANSI.red_background(), "world"]
IO.puts([IO.ANSI.red(), "Hello #{substring}#{[IO.ANSI.red(), IO.ANSI.default_background()]}!!"])Such code is hard to maintain.
Here's how to address the issue with Owl.Data.tag/2:
substring = Owl.Data.tag("world", :green)
Owl.IO.puts(Owl.Data.tag(["Hello ", substring, "!!"], :red))
substring = Owl.Data.tag("world", [:green, :red_background])
Owl.IO.puts(Owl.Data.tag(["Hello ", substring, "!!"], :red))
Summary
Functions
new(data, sequences)
deprecated
Use Owl.Data.tag/2 instead
Types
@type t(data) :: %Owl.Tag{data: data, sequences: [Owl.Data.sequence()]}
Functions
This function is deprecated. Use `Owl.Data.tag/2` instead.
Use Owl.Data.tag/2 instead