Skip to content

Commit

Permalink
Split segments on longer whitespace (than just single space)
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Mar 18, 2024
1 parent 29bfa86 commit a501af0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/asciinema/recordings/snapshot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ defmodule Asciinema.Recordings.Snapshot do
end

defp split_on_whitespace({text, attrs, 1}) do
~r/\s+/
~r/(^\s+)|\s{2,}/
|> Regex.split(text, include_captures: true)
|> Enum.filter(&(String.length(&1) > 0))
|> Enum.map(&{&1, attrs, 1})
Expand Down
14 changes: 7 additions & 7 deletions test/asciinema/recordings/snapshot_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ defmodule Asciinema.Recordings.SnapshotTest do
end

@lines [
[[" foo bar ", %{"bg" => 2}, 1], ["!", %{"fg" => 1}, 1]],
[["baz", %{"bg" => 2}, 1], ["连", %{}, 2], ["接", %{}, 2]]
[[" foo bar baz", %{"bg" => 2}, 1], ["!", %{"fg" => 1}, 1]],
[["qux", %{"bg" => 2}, 1], ["连", %{}, 2], ["接", %{}, 2]]
]

describe "text_coords/1" do
Expand All @@ -105,15 +105,15 @@ defmodule Asciinema.Recordings.SnapshotTest do
%{
y: 0,
segments: [
%{text: "foo", attrs: %{"bg" => 2}, x: 1, width: 3},
%{text: "bar", attrs: %{"bg" => 2}, x: 5, width: 3},
%{text: "!", attrs: %{"fg" => 1}, x: 9, width: 1}
%{text: "foo bar", attrs: %{"bg" => 2}, x: 1, width: 7},
%{text: "baz", attrs: %{"bg" => 2}, x: 10, width: 3},
%{text: "!", attrs: %{"fg" => 1}, x: 13, width: 1}
]
},
%{
y: 1,
segments: [
%{text: "baz", attrs: %{"bg" => 2}, x: 0, width: 3},
%{text: "qux", attrs: %{"bg" => 2}, x: 0, width: 3},
%{text: "连", attrs: %{}, x: 3, width: 2},
%{text: "接", attrs: %{}, x: 5, width: 2}
]
Expand All @@ -133,7 +133,7 @@ defmodule Asciinema.Recordings.SnapshotTest do
%{
y: 0,
segments: [
%{attrs: %{"bg" => 2}, x: 0, width: 9}
%{attrs: %{"bg" => 2}, x: 0, width: 13}
]
},
%{
Expand Down

0 comments on commit a501af0

Please sign in to comment.