defmodule KinoPHP do @doc """ Executes a PHP script the result. """ def eval(code, on_output) do # I can't get the code editor to highlight properly without using # " on_output.(data) stream_output(port, on_output) {^port, {:exit_status, status}} -> status {^port, {:exit_signal, signal}} -> signal {^port, {:error, reason}} -> raise reason end end @doc """ Prints Terminal output into a Kino frame. ## Examples ```elixir frame = Kino.Frame.new() |> Kino.render() KinoPHP.append_to_frame(frame, "hello") KinoPHP.append_to_frame(frame, [:green, " world"]) ``` """ def append_to_frame(frame, text) do text |> IO.ANSI.format() |> IO.iodata_to_binary() |> Kino.Text.new(terminal: true, chunk: true) |> then(&Kino.Frame.append(frame, &1)) end def get_notebook_path!() do Kino.Bridge.get_evaluation_file() |> String.split("#") |> hd() |> Path.dirname() end end