Packages
Multi-surface application runtime for Elixir. One TEA module renders to terminal, browser (LiveView), SSH, and MCP (agents). 30+ widgets, flexbox + CSS grid, AI agent runtime, distributed swarm with CRDTs, time-travel debugging, session recording, sandboxed REPL, and agentic commerce.
Current section
Files
Jump to
Current section
Files
lib/raxol/terminal/modes/handlers/standard_handler.ex
defmodule Raxol.Terminal.Modes.Handlers.StandardHandler do
@moduledoc """
Handles standard mode operations and their side effects.
Manages standard terminal modes like insert mode and line feed mode.
"""
require Raxol.Core.Runtime.Log
alias Raxol.Terminal.Emulator
alias Raxol.Terminal.Modes.Types.ModeTypes
@doc """
Handles a standard mode change and applies its effects to the emulator.
"""
@spec handle_mode_change(atom(), ModeTypes.mode_value(), Emulator.t()) ::
{:ok, Emulator.t()} | {:error, term()}
def handle_mode_change(mode_name, value, emulator) do
case find_mode_definition(mode_name) do
%{category: :standard} = mode_def ->
apply_mode_effects(mode_def, value, emulator)
_ ->
{:error, :invalid_mode}
end
end
# Private Functions
defp find_mode_definition(mode_name) do
ModeTypes.get_all_modes()
|> Map.values()
|> Enum.find(&(&1.name == mode_name))
end
defp apply_mode_effects(mode_def, value, emulator) do
case mode_def.name do
:irm ->
handle_insert_mode(value, emulator)
:lnm ->
handle_line_feed_mode(value, emulator)
_ ->
{:error, :unsupported_mode}
end
end
defp handle_insert_mode(true, emulator) do
# Insert Mode (IRM)
# When enabled, new text is inserted at the cursor position
{:ok, %{emulator | insert_mode: true}}
end
defp handle_insert_mode(false, emulator) do
# Replace Mode (default)
# When disabled, new text overwrites existing text
{:ok, %{emulator | insert_mode: false}}
end
defp handle_line_feed_mode(true, emulator) do
# Line Feed Mode (LNM)
# When enabled, line feed also performs carriage return
{:ok, %{emulator | line_feed_mode: true}}
end
defp handle_line_feed_mode(false, emulator) do
# New Line Mode (default)
# When disabled, line feed only moves down one line
{:ok, %{emulator | line_feed_mode: false}}
end
end