From a501af0bd9ccb6fff024232ecd4f3effb37388de Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 18 Mar 2024 10:44:06 +0100 Subject: [PATCH] Split segments on longer whitespace (than just single space) --- lib/asciinema/recordings/snapshot.ex | 2 +- test/asciinema/recordings/snapshot_test.exs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/asciinema/recordings/snapshot.ex b/lib/asciinema/recordings/snapshot.ex index cdba3ac3e..1a437e80f 100644 --- a/lib/asciinema/recordings/snapshot.ex +++ b/lib/asciinema/recordings/snapshot.ex @@ -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}) diff --git a/test/asciinema/recordings/snapshot_test.exs b/test/asciinema/recordings/snapshot_test.exs index 7a3328a36..852bf4832 100644 --- a/test/asciinema/recordings/snapshot_test.exs +++ b/test/asciinema/recordings/snapshot_test.exs @@ -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 @@ -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} ] @@ -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} ] }, %{