Raxol.Terminal.Window (Raxol v0.5.0)

View Source

Represents a terminal window with its properties and state.

This module provides functionality for managing terminal windows, including:

  • Window creation and configuration
  • State management (active, inactive, minimized, maximized)
  • Size and position control
  • Parent-child window relationships
  • Terminal emulator integration

Window States

  • :active - Window is currently focused
  • :inactive - Window is not focused
  • :minimized - Window is minimized
  • :maximized - Window is maximized

Usage

# Create a new window with default size
window = Window.new(Config.new())

# Create a window with custom dimensions
window = Window.new(100, 50)

# Update window title
{:ok, window} = Window.set_title(window, "My Terminal")

Summary

Functions

Adds a child window.

Clears a hyperlink by ID.

Gets the window's child windows.

Gets the window's clipboard content.

Gets the window's cursor shape.

Gets the window's current dimensions.

Gets the window's font.

Gets a hyperlink by ID.

Gets the window's icon name.

Gets the window's parent window.

Gets the window's current position.

Gets the window's current size.

Gets the window's current state.

Gets the window's working directory.

Creates a new window with the given configuration.

Creates a new window with custom dimensions.

Removes a child window.

Restores the previous window size.

Updates the window's clipboard content.

Updates the window's cursor shape.

Updates the window's font.

Sets a hyperlink with the given ID and URL.

Updates the window's icon name.

Sets the parent window.

Updates the window position.

Updates the window size.

Updates the window state.

Updates the window title.

Sets the window's working directory.

Types

t()

@type t() :: %Raxol.Terminal.Window{
  children: [String.t()],
  clipboard: String.t(),
  config: Raxol.Terminal.Config.t(),
  cursor_shape: String.t(),
  emulator: Raxol.Terminal.Emulator.t(),
  font: String.t(),
  icon_name: String.t(),
  id: String.t() | nil,
  parent: String.t() | nil,
  position: window_position(),
  previous_size: window_size() | nil,
  size: window_size(),
  state: window_state(),
  title: String.t()
}

window_position()

@type window_position() :: {integer(), integer()}

window_size()

@type window_size() :: {non_neg_integer(), non_neg_integer()}

window_state()

@type window_state() :: :active | :inactive | :minimized | :maximized

Functions

add_child(window, child_id)

@spec add_child(t(), String.t()) :: {:ok, t()} | {:error, term()}

Adds a child window.

clear_hyperlink(window, id)

@spec clear_hyperlink(t(), String.t()) :: t()

Clears a hyperlink by ID.

get_children(window)

@spec get_children(t()) :: {:ok, [String.t()]} | {:error, term()}

Gets the window's child windows.

get_clipboard(window)

@spec get_clipboard(t()) :: String.t()

Gets the window's clipboard content.

get_cursor_shape(window)

@spec get_cursor_shape(t()) :: String.t()

Gets the window's cursor shape.

get_dimensions(window)

@spec get_dimensions(t()) :: {:ok, window_size()} | {:error, term()}

Gets the window's current dimensions.

get_font(window)

@spec get_font(t()) :: String.t()

Gets the window's font.

get_hyperlink(window, id)

@spec get_hyperlink(t(), String.t()) :: String.t() | nil

Gets a hyperlink by ID.

get_icon_name(window)

@spec get_icon_name(t()) :: String.t()

Gets the window's icon name.

get_parent(window)

@spec get_parent(t()) :: {:ok, String.t() | nil} | {:error, term()}

Gets the window's parent window.

get_position(window)

@spec get_position(t()) :: {:ok, window_position()} | {:error, term()}

Gets the window's current position.

get_size(window)

@spec get_size(t()) :: window_size()

Gets the window's current size.

get_state(window)

@spec get_state(t()) :: {:ok, window_state()} | {:error, term()}

Gets the window's current state.

get_working_directory(window)

@spec get_working_directory(t()) :: String.t()

Gets the window's working directory.

new(config)

@spec new(Raxol.Terminal.Config.t()) :: t()

Creates a new window with the given configuration.

Parameters

  • config - Terminal configuration (Config.t())

Returns

  • A new window instance with the specified configuration

Examples

iex> config = Config.new()
iex> window = Window.new(config)
iex> window.size
{80, 24}

new(width, height)

@spec new(non_neg_integer(), non_neg_integer()) :: t()

Creates a new window with custom dimensions.

Parameters

  • width - Window width in characters (positive integer)
  • height - Window height in characters (positive integer)

Returns

  • A new window instance with the specified dimensions

Examples

iex> window = Window.new(100, 50)
iex> window.size
{100, 50}

remove_child(window, child_id)

@spec remove_child(t(), String.t()) :: {:ok, t()} | {:error, term()}

Removes a child window.

restore_size(window)

@spec restore_size(t()) :: {:ok, t()} | {:error, term()}

Restores the previous window size.

set_clipboard(window, content)

@spec set_clipboard(t(), String.t()) :: t()

Updates the window's clipboard content.

set_cursor_shape(window, shape)

@spec set_cursor_shape(t(), String.t()) :: t()

Updates the window's cursor shape.

set_font(window, font)

@spec set_font(t(), String.t()) :: {:ok, t()} | {:error, term()}

Updates the window's font.

set_hyperlink(window, id, url)

@spec set_hyperlink(t(), String.t(), String.t()) :: t()

Sets a hyperlink with the given ID and URL.

set_icon_name(window, name)

@spec set_icon_name(t(), String.t()) :: {:ok, t()} | {:error, term()}

Updates the window's icon name.

set_parent(window, parent_id)

@spec set_parent(t(), String.t()) :: {:ok, t()} | {:error, term()}

Sets the parent window.

set_position(window, x, y)

@spec set_position(t(), integer(), integer()) :: {:ok, t()} | {:error, term()}

Updates the window position.

set_size(window, width, height)

@spec set_size(t(), non_neg_integer(), non_neg_integer()) ::
  {:ok, t()} | {:error, term()}

Updates the window size.

set_state(window, state)

@spec set_state(t(), window_state()) :: {:ok, t()} | {:error, term()}

Updates the window state.

set_title(window, title)

@spec set_title(t(), String.t()) :: {:ok, t()} | {:error, term()}

Updates the window title.

Parameters

  • window - The window to update
  • title - New window title

Returns

  • {:ok, updated_window} - Title updated successfully
  • {:error, reason} - Failed to update title

Examples

iex> window = Window.new(80, 24)
iex> {:ok, window} = Window.set_title(window, "My Terminal")
iex> window.title
"My Terminal"

set_working_directory(window, dir)

@spec set_working_directory(t(), String.t()) :: t()

Sets the window's working directory.