defmodule RaxolWeb.TerminalLive do @moduledoc """ LiveView component for the terminal interface. This component provides: - Terminal rendering - Input handling - Resize management - Theme customization - Scroll management - Session management """ use RaxolWeb, :live_view # alias Phoenix.PubSub # Unused # alias Phoenix.LiveView.JS # Unused # alias Raxol.Core.KeyboardShortcuts # Unused # alias Raxol.Terminal.PTY # Unused # alias Raxol.Terminal.Renderer @impl true def mount(_params, _session, socket) do if connected?(socket) do session_id = generate_session_id() socket = socket |> assign(:session_id, session_id) |> assign(:terminal_html, "") |> assign(:cursor, %{x: 0, y: 0, visible: true}) |> assign(:dimensions, %{width: 80, height: 24}) |> assign(:scroll_offset, 0) |> assign(:theme, default_theme()) |> assign(:connected, false) {:ok, socket, temporary_assigns: [terminal_html: ""]} else {:ok, assign(socket, :connected, false)} end end @impl true def handle_event("connect", _params, socket) do socket = socket |> assign(:connected, true) |> push_event("js-exec", %{ to: "#terminal", attr: "data-session-id", val: socket.assigns.session_id }) {:noreply, socket} end @impl true def handle_event( "terminal_output", %{"html" => html, "cursor" => cursor}, socket ) do {:noreply, assign(socket, terminal_html: html, cursor: cursor)} end @impl true def handle_event("resize", %{"width" => width, "height" => height}, socket) do socket = assign(socket, dimensions: %{width: width, height: height}) {:noreply, push_event(socket, "terminal_resize", %{width: width, height: height})} end @impl true def handle_event("scroll", %{"offset" => offset}, socket) do socket = assign(socket, scroll_offset: offset) {:noreply, push_event(socket, "terminal_scroll", %{offset: offset})} end @impl true def handle_event("theme", %{"theme" => theme}, socket) do socket = assign(socket, theme: theme) {:noreply, push_event(socket, "terminal_theme", %{theme: theme})} end @impl true def handle_event("disconnect", _params, socket) do {:noreply, assign(socket, connected: false)} end @impl true def render(assigns) do ~H"""