mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-04 20:14:57 +08:00
Support setopts request with binary option in IO proxy (#2983)
This commit is contained in:
parent
710957b265
commit
331efa04f7
2 changed files with 22 additions and 6 deletions
|
@ -228,12 +228,11 @@ defmodule Livebook.Runtime.Evaluator.IOProxy do
|
|||
{{:error, :enotsup}, state}
|
||||
end
|
||||
|
||||
defp io_request({:setopts, [encoding: encoding]}, state) when encoding in [:latin1, :unicode] do
|
||||
{:ok, %{state | encoding: encoding}}
|
||||
end
|
||||
|
||||
defp io_request({:setopts, _opts}, state) do
|
||||
{{:error, :enotsup}, state}
|
||||
defp io_request({:setopts, opts}, state) do
|
||||
case setopts(opts, state) do
|
||||
{:ok, state} -> {:ok, state}
|
||||
:error -> {{:error, :enotsup}, state}
|
||||
end
|
||||
end
|
||||
|
||||
defp io_request(:getopts, state) do
|
||||
|
@ -465,6 +464,17 @@ defmodule Livebook.Runtime.Evaluator.IOProxy do
|
|||
ArgumentError -> {{:error, req}, state}
|
||||
end
|
||||
|
||||
defp setopts([{:encoding, encoding} | opts], state) when encoding in [:latin1, :unicode] do
|
||||
setopts(opts, %{state | encoding: encoding})
|
||||
end
|
||||
|
||||
defp setopts([opt | opts], state) when opt in [:binary, {:binary, true}] do
|
||||
setopts(opts, state)
|
||||
end
|
||||
|
||||
defp setopts([], state), do: {:ok, state}
|
||||
defp setopts(_opts, _state), do: :error
|
||||
|
||||
defp request_input_value(input_id, state) do
|
||||
request = {:runtime_evaluation_input_request, state.ref, self(), input_id}
|
||||
reply_tag = :runtime_evaluation_input_reply
|
||||
|
|
|
@ -44,6 +44,12 @@ defmodule Livebook.Runtime.Evaluator.IOProxyTest do
|
|||
test "IO.gets", %{io: io} do
|
||||
assert IO.gets(io, "name: ") == {:error, :enotsup}
|
||||
end
|
||||
|
||||
test ":io.setopts", %{io: io} do
|
||||
assert :ok = :io.setopts(io, encoding: :unicode)
|
||||
assert :ok = :io.setopts(io, [:binary])
|
||||
assert {:error, :enotsup} = :io.setopts(io, [:unknown_option])
|
||||
end
|
||||
end
|
||||
|
||||
describe "input" do
|
||||
|
|
Loading…
Add table
Reference in a new issue