Repository: livebook-dev/kino (elixir)

Issue:
Make communication upstream use a pubsub
VegaLite does not need to track IDs, instead it will send a message to the group leader with a pubsub topic that is sent to Livebook.

Pull request description:
Inspect non-utf8 binaries in Kino.DataTable
Closes https://github.com/livebook-dev/kino_db/issues/56.

Patch:
diff --git a/lib/kino/data_table.ex b/lib/kino/data_table.ex
index d02c443..0ed3a50 100644
--- a/lib/kino/data_table.ex
+++ b/lib/kino/data_table.ex
@@ -253,6 +253,11 @@ defmodule Kino.DataTable do
     end
   end
 
+  defp value_to_string(value) when is_binary(value) do
+    inspect_opts = Inspect.Opts.new([])
+    if String.printable?(value, inspect_opts.limit), do: value, else: inspect(value)
+  end
+
   defp value_to_string(value) do
     if mod = String.Chars.impl_for(value), do: mod.to_string(value), else: inspect(value)
   end


Test patch:
diff --git a/test/kino/data_table_test.exs b/test/kino/data_table_test.exs
index 68386b0..b5150fb 100644
--- a/test/kino/data_table_test.exs
+++ b/test/kino/data_table_test.exs
@@ -121,6 +121,21 @@ defmodule Kino.DataTableTest do
            } = data
   end
 
+  test "supports non-utf8 binary values" do
+    entries = [
+      binaries: [<<110, 120>>, <<200, 210>>]
+    ]
+
+    kino = Kino.DataTable.new(entries)
+    data = connect(kino)
+
+    assert %{
+             content: %{
+               data: [["nx"], ["<<200, 210>>"]]
+             }
+           } = data
+  end
+
   test "sends only relevant fields if user-specified keys are given" do
     kino = Kino.DataTable.new(@people_entries, keys: [:id])
     data = connect(kino)