Owl.Data (Owl v0.1.0) View Source
A set of functions for iodata/0 with tags.
Link to this section Summary
Types
A recursive data type that is similar to iodata/0, but additionally supports Owl.Tag.t/1.
Functions
Adds a prefix before each line of the data.
Returns list of t() containing count elements each.
Returns length of the data.
Splits data by new lines.
Divides data into parts based on a pattern saving sequences for tagged data in new tags.
Transforms data to IO.ANSI.ansidata/0 format which can be consumed by IO module.
Zips corresponding lines into 1 line.
Link to this section Types
Specs
A recursive data type that is similar to iodata/0, but additionally supports Owl.Tag.t/1.
Can be written to stdout using Owl.IO.puts/2.
Link to this section Functions
Specs
Adds a prefix before each line of the data.
An important feature is that styling of the data will be saved for each line.
Example
iex> "first\nsecond" |> Owl.Tag.new(:red) |> Owl.Data.add_prefix(Owl.Tag.new("test: ", :yellow))
[
[Owl.Tag.new("test: ", :yellow), Owl.Tag.new(["first"], :red)],
"\n",
[Owl.Tag.new("test: ", :yellow), Owl.Tag.new(["second"], :red)]
]
Specs
chunk_every(data :: t(), count :: pos_integer()) :: [t()]
Returns list of t() containing count elements each.
Example
iex> Owl.Data.chunk_every(
...> ["first second ", Owl.Tag.new(["third", Owl.Tag.new(" fourth", :blue)], :red)],
...> 7
...> )
[
"first s",
["econd ", Owl.Tag.new(["t"], :red)],
Owl.Tag.new(["hird", Owl.Tag.new([" fo"], :blue)], :red),
Owl.Tag.new(["urth"], :blue)
]
Specs
length(t()) :: non_neg_integer()
Returns length of the data.
Examples
iex> Owl.Data.length(["222"])
3
iex> Owl.Data.length([222])
1
iex> Owl.Data.length([[[]]])
0
iex> Owl.Data.length(["222", Owl.Tag.new(["333", "444"], :green)])
9
Specs
Splits data by new lines.
A special case of split/2.
Example
iex> Owl.Data.lines(["first\nsecond\n", Owl.Tag.new("third\nfourth", :red)])
["first", "second", Owl.Tag.new(["third"], :red), Owl.Tag.new(["fourth"], :red)]
Divides data into parts based on a pattern saving sequences for tagged data in new tags.
Example
iex> Owl.Data.split(["first second ", Owl.Tag.new("third fourth", :red)], " ")
["first", "second", Owl.Tag.new(["third"], :red), Owl.Tag.new(["fourth"], :red)]
Specs
to_ansidata(t()) :: IO.ANSI.ansidata()
Transforms data to IO.ANSI.ansidata/0 format which can be consumed by IO module.
Examples
iex> "hello" |> Owl.Tag.new([:red, :cyan_background]) |> Owl.Data.to_ansidata()
[[[[[[[] | "[46m"] | "[31m"], "hello"] | "[39m"] | "[49m"] | "[0m"]
Specs
Zips corresponding lines into 1 line.
The zipping finishes as soon as either data completes.
Examples
iex> Owl.Data.zip("a\nb\nc", "d\ne\nf")
[["a", "d"], "\n", ["b", "e"], "\n", ["c", "f"]]
iex> Owl.Data.zip("a\nb", "c")
[["a", "c"]]
iex> 1..3
...> |> Enum.map(&to_string/1)
...> |> Enum.map(&Owl.Box.new/1) |> Enum.reduce(&Owl.Data.zip/2) |> to_string()
"""
┌─┐┌─┐┌─┐
│3││2││1│
└─┘└─┘└─┘
""" |> String.trim_trailing()