Raxol.Terminal.Window.Manager (Raxol v2.0.1)

View Source

Refactored Window.Manager that delegates to GenServer implementation.

This module provides the same API as the original Terminal.Window.Manager but uses a supervised GenServer instead of the Process dictionary for state management.

Migration Notice

This module is a drop-in replacement for Raxol.Terminal.Window.Manager. All functions maintain backward compatibility while providing improved fault tolerance and functional programming patterns.

Benefits over Process Dictionary

  • Supervised state management with fault tolerance
  • Pure functional window management
  • Z-order window stacking support
  • Spatial navigation mapping
  • Better debugging and testing capabilities
  • No global state pollution

New Features

  • Window Z-ordering for proper stacking
  • Spatial position tracking for navigation
  • Custom navigation paths between windows
  • Hierarchical window relationships

Summary

Functions

Cleanup the window manager. Alias for reset/0.

Counts the number of windows.

Creates a child window.

Creates a new window with the given configuration.

Creates a new window with dimensions.

Defines a navigation path between windows.

Destroys a window by ID.

Ensures the Window Manager server is started.

Gets the active window.

Gets child windows of a parent.

Gets the parent window of a child.

Gets the window manager state as a map.

Gets a window by ID.

Gets the window size.

Gets the window state.

Lists all windows.

Move a window to the specified position.

Moves a window to the back (bottom of Z-order).

Moves a window to the front (top of Z-order).

Creates a new window manager instance. For backward compatibility, returns {:ok, pid()} of the GenServer.

Creates a new window manager instance for testing. Returns a simple map structure instead of a process.

Registers a window's spatial position for navigation.

Resets the window manager to initial state.

Resizes a window. Alias for set_window_size/3.

Sets the active window.

Sets the icon name.

Set the stacking order of a window.

Set the title of a window.

Sets the window position.

Sets the window size.

Sets the window state.

Sets the window title.

Split a window horizontally or vertically.

Starts the window manager.

Updates the window manager configuration.

Checks if a window exists.

Types

t()

@type t() :: %{tabs: map()}

window_id()

@type window_id() :: String.t()

window_state()

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

Functions

cleanup()

Cleanup the window manager. Alias for reset/0.

count_windows()

Counts the number of windows.

create_child_window(parent_id, config)

@spec create_child_window(window_id(), Raxol.Terminal.Config.t()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, term()}

Creates a child window.

create_window(config)

@spec create_window(Raxol.Terminal.Config.t()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, term()}

Creates a new window with the given configuration.

create_window(width, height)

@spec create_window(integer(), integer()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, term()}

Creates a new window with dimensions.

define_navigation_path(from_id, direction, to_id)

Defines a navigation path between windows.

destroy_window(id)

@spec destroy_window(window_id()) :: :ok | {:error, :not_found}

Destroys a window by ID.

ensure_started()

Ensures the Window Manager server is started.

get_active_window()

Gets the active window.

get_child_windows(parent_id)

@spec get_child_windows(window_id()) ::
  {:ok, [Raxol.Terminal.Window.t()]} | {:error, :not_found}

Gets child windows of a parent.

get_parent_window(child_id)

@spec get_parent_window(window_id()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, :not_found | :no_parent}

Gets the parent window of a child.

get_state(pid)

@spec get_state(pid()) :: map()

Gets the window manager state as a map.

get_window(id)

@spec get_window(window_id()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, :not_found}

Gets a window by ID.

get_window_size(pid)

@spec get_window_size(pid()) :: {integer(), integer()}

Gets the window size.

get_window_state(pid)

@spec get_window_state(pid()) :: atom()

Gets the window state.

list_windows()

@spec list_windows() :: {:ok, [Raxol.Terminal.Window.t()]}

Lists all windows.

move(window_id, x, y)

Move a window to the specified position.

move_window_to_back(window_id)

Moves a window to the back (bottom of Z-order).

move_window_to_front(window_id)

Moves a window to the front (top of Z-order).

new()

@spec new() :: {:ok, pid()}

Creates a new window manager instance. For backward compatibility, returns {:ok, pid()} of the GenServer.

new_for_test()

@spec new_for_test() :: map()

Creates a new window manager instance for testing. Returns a simple map structure instead of a process.

register_window_position(window_id, x, y, width, height)

Registers a window's spatial position for navigation.

reset()

Resets the window manager to initial state.

resize(window_id, width, height)

@spec resize(window_id(), integer(), integer()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, :not_found}

Resizes a window. Alias for set_window_size/3.

set_active_window(window_id)

Sets the active window.

set_icon_name(pid, icon_name)

@spec set_icon_name(pid(), String.t()) :: :ok
@spec set_icon_name(t(), String.t()) :: t()

Sets the icon name.

set_stacking_order(window_id, order)

Set the stacking order of a window.

set_title(window_id, title)

Set the title of a window.

set_window_position(id, x, y)

@spec set_window_position(window_id(), integer(), integer()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, :not_found}

Sets the window position.

set_window_size(pid, width, height)

@spec set_window_size(pid(), integer(), integer()) :: :ok
@spec set_window_size(window_id(), integer(), integer()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, :not_found}

Sets the window size.

set_window_state(pid, state)

@spec set_window_state(pid(), atom()) :: :ok
@spec set_window_state(window_id(), window_state()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, :not_found}

Sets the window state.

set_window_title(pid, title)

@spec set_window_title(pid(), String.t()) :: :ok
@spec set_window_title(window_id(), String.t()) ::
  {:ok, Raxol.Terminal.Window.t()} | {:error, :not_found}

Sets the window title.

split_window(window_id, direction)

Split a window horizontally or vertically.

start_link()

@spec start_link() :: {:ok, pid()}

Starts the window manager.

start_link(opts)

@spec start_link(list()) :: {:ok, pid()}

update_config(config)

Updates the window manager configuration.

window_exists?(window_id)

Checks if a window exists.