2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.ElixirStandaloneLive do
|
|
|
|
use LivebookWeb, :live_view
|
2021-02-27 03:53:29 +08:00
|
|
|
|
2021-03-04 05:56:28 +08:00
|
|
|
alias Livebook.{Session, Runtime}
|
2021-02-27 03:53:29 +08:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def mount(_params, %{"session_id" => session_id}, socket) do
|
|
|
|
{:ok, assign(socket, session_id: session_id, output: nil)}
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
|
|
|
~L"""
|
|
|
|
<div class="flex-col space-y-3">
|
|
|
|
<p class="text-gray-500">
|
|
|
|
Start a new local node to handle code evaluation.
|
|
|
|
This is the default runtime and is started automatically
|
|
|
|
as soon as you evaluate the first cell.
|
|
|
|
</p>
|
2021-03-12 18:57:01 +08:00
|
|
|
<button class="button-base" phx-click="init">
|
2021-02-27 03:53:29 +08:00
|
|
|
Connect
|
|
|
|
</button>
|
|
|
|
<%= if @output do %>
|
|
|
|
<div class="markdown max-h-20 overflow-y-auto tiny-scrollbar">
|
|
|
|
<pre><code><%= @output %></code></pre>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def handle_event("init", _params, socket) do
|
|
|
|
{:ok, runtime} = Runtime.ElixirStandalone.init()
|
|
|
|
Session.connect_runtime(socket.assigns.session_id, runtime)
|
|
|
|
{:noreply, socket}
|
|
|
|
end
|
|
|
|
end
|