-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade user and recording controllers to Phx 1.7 style, refactor Rec…
…ordings module
- Loading branch information
Showing
59 changed files
with
1,303 additions
and
1,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Asciinema.Recordings.Markers do | ||
def validate(_, markers) do | ||
case parse(markers) do | ||
{:ok, _} -> [] | ||
{:error, index} -> [markers: "invalid syntax in line #{index + 1}"] | ||
end | ||
end | ||
|
||
def parse(markers) do | ||
results = | ||
markers | ||
|> String.trim() | ||
|> String.split("\n") | ||
|> Enum.map(&parse_one/1) | ||
|
||
case Enum.find_index(results, fn result -> result == :error end) do | ||
nil -> {:ok, results} | ||
index -> {:error, index} | ||
end | ||
end | ||
|
||
defp parse_one(marker) do | ||
parts = | ||
marker | ||
|> String.trim() | ||
|> String.split(~r/\s+-\s+/, parts: 2) | ||
|> Kernel.++([""]) | ||
|> Enum.take(2) | ||
|
||
with [t, l] <- parts, | ||
{t, ""} <- Float.parse(t), | ||
true <- String.length(l) < 100 do | ||
{t, l} | ||
else | ||
_ -> :error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule Asciinema.Recordings.Snapshot do | ||
def split_segments(lines) do | ||
Enum.map(lines, fn line -> | ||
Enum.flat_map(line, &split_segment/1) | ||
end) | ||
end | ||
|
||
defp split_segment([text, attrs]), do: split_segment({text, attrs}) | ||
|
||
defp split_segment({text, attrs}) do | ||
text | ||
|> String.codepoints() | ||
|> Enum.map(&{&1, attrs}) | ||
end | ||
|
||
def group_segments(lines), do: Enum.map(lines, &group_line_segments/1) | ||
|
||
defp group_line_segments([]), do: [] | ||
|
||
defp group_line_segments([first_segment | segments]) do | ||
{segments, last_segment} = | ||
Enum.reduce(segments, {[], first_segment}, fn {text, attrs}, | ||
{segments, {prev_text, prev_attrs}} -> | ||
if attrs == prev_attrs do | ||
{segments, {prev_text <> text, attrs}} | ||
else | ||
{[{prev_text, prev_attrs} | segments], {text, attrs}} | ||
end | ||
end) | ||
|
||
Enum.reverse([last_segment | segments]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.