     case :unicode.characters_to_binary(chars, encoding, :unicode) do
       string when is_binary(string) ->
         {:ok, %{state | output: output <> string}}
+
       {_, _, _} ->
         {{:error, req}, state}
     end

  end

  defp state_after_read(%{capture_prompt: true, output: output} = state, remainder, prompt, count) do
    %{state | input: remainder, output: <<output::binary, :binary.copy(IO.chardata_to_string(prompt), count)::binary>>}
  end

  defp bytes_until_eol("", _, count), do: {:split, count}

    case bytes_until_eol(input, encoding, 0) do
      {:split, 0} ->
        {:eof, state_after_read(state, "", prompt, 1)}

      {:split, count} ->
        {result, remainder} = :erlang.split_binary(input, count)
        {result, state_after_read(state, remainder, prompt, 1)}

      {:replace_split, count} ->
        {result, remainder} = :erlang.split_binary(input, count)
        result = binary_part(result, 0, byte_size(result) - 2) <> "\n"
        {result, state_after_read(state, remainder, prompt, 1)}

      :error ->
        {{:error, :collect_line}, state}
    end
  end

