Bsp.Layout (Jigsaw v0.1.0)

Copy Markdown View Source
This module allows for manipulation of the layout tree.

Summary

Functions

Returns a Node struct, or {:error, :node_not_found} or {:error, :no_children}.

Takes in a layout and a pane_id to close. Returns a new layout with the pane with the specified pane_id removed from the tree.

Finds a pane with the specified pane_id in the tree. Returns a pane struct or {:error, :pane_not_found}

Returns {:ok, pane_id} with pane_id being the id of the pane in focus. Could also return nil if there are no panes.

Returns pane_id in focus or nil.

Queries whether a pane is in focus or not. Returns a boolean or {:error, :pane_not_found} if the pane_id doesn't exist

Takes an empty layout and a pane and returns the layout with the pane.

Creates a new empty layout

Creates a new Layout with a single pane

Returns a list of pane_ids that exist in the layout tree

Returns a Node struct, or {:error, :pane_not_found} or {:error, :no_parent}.

Takes in a layout, a pane ID and a new pane ID to split it with. Returns an updated layout with the specified pane split into a node with 2 panes.

Swaps the positions of panes. For now you can only swap panes on the same node.

Validates the layout based on specified invariants on nodes, panes and other crucial elements

Types

t()

@type t() :: %{root: tree(), focused: String.t(), pane_ids: [String.t()]}

tree()

@type tree() :: Bsp.Pane.t() | Bsp.Node.t()

Functions

children(layout, node_id)

@spec children(
  %Bsp.Layout{focused: term(), pane_ids: term(), root: term()},
  String.t()
) ::
  {:ok, [Bsp.Pane.t()]} | {:error, :node_not_found} | {:error, :no_children}

Returns a Node struct, or {:error, :node_not_found} or {:error, :no_children}.

close(layout, pane_id)

@spec close(
  %Bsp.Layout{focused: term(), pane_ids: term(), root: term()},
  Types.Id.t()
) ::
  {:ok, %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}}
  | {:error, :pane_not_found}

Takes in a layout and a pane_id to close. Returns a new layout with the pane with the specified pane_id removed from the tree.

find(layout, pane_id)

@spec find(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, Types.Id.t()) ::
  Bsp.Pane.t() | {:error, :pane_not_found}

Finds a pane with the specified pane_id in the tree. Returns a pane struct or {:error, :pane_not_found}

focus(layout, target_id)

@spec focus(
  %Bsp.Layout{focused: term(), pane_ids: term(), root: term()},
  Types.Id.t()
) ::
  {:ok, %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}}
  | {:error, :pane_not_found}

focused(layout)

@spec focused(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) ::
  {:ok, Types.Id.t()}

Returns {:ok, pane_id} with pane_id being the id of the pane in focus. Could also return nil if there are no panes.

focused!(layout)

@spec focused!(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) ::
  Types.Id.t()

Returns pane_id in focus or nil.

focused?(layout, pane_id)

@spec focused?(
  %Bsp.Layout{focused: term(), pane_ids: term(), root: term()},
  Types.Id.t()
) :: boolean()

Queries whether a pane is in focus or not. Returns a boolean or {:error, :pane_not_found} if the pane_id doesn't exist

insert(layout, pane)

@spec insert(t(), Bsp.Pane.t()) :: t() | {:error, :invalid_layout}

Takes an empty layout and a pane and returns the layout with the pane.

Examples

iex> Bsp.Layout.insert(%Bsp.Layout{root: nil, focused: nil, pane_ids: []}, %Bsp.Pane{id: "temp"})
%Bsp.Layout{root: %Bsp.Pane{id: "temp"}, focused: "temp", pane_ids: ["temp"]}

new()

@spec new() :: %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}

Creates a new empty layout

new(root_pane)

@spec new(Bsp.Pane.t()) :: %Bsp.Layout{
  focused: term(),
  pane_ids: term(),
  root: term()
}

Creates a new Layout with a single pane

panes(layout)

@spec panes(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) :: [
  Types.Id.t()
]

Returns a list of pane_ids that exist in the layout tree

parent(layout, pane_id)

@spec parent(
  %Bsp.Layout{focused: term(), pane_ids: term(), root: term()},
  Types.Id.t()
) ::
  {:ok, Bsp.Node.t()} | {:error, :pane_not_found} | {:error, :no_parent}

Returns a Node struct, or {:error, :pane_not_found} or {:error, :no_parent}.

split(layout, target_id, new_id)

@spec split(
  %Bsp.Layout{focused: term(), pane_ids: term(), root: term()},
  Types.Id.t(),
  Types.Id.t()
) ::
  {:ok, %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}}
  | {:error, :pane_not_found}
  | {:error, :duplicate_pane_id}

Takes in a layout, a pane ID and a new pane ID to split it with. Returns an updated layout with the specified pane split into a node with 2 panes.

swap(layout, pane_1_id, pane_2_id)

@spec swap(
  %Bsp.Layout{focused: term(), pane_ids: term(), root: term()},
  Types.Id.t(),
  Types.Id.t()
) ::
  {:ok, %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}}
  | {:error, :pane_not_found}
  | {:error, :swap_failed}

Swaps the positions of panes. For now you can only swap panes on the same node.

validate(layout)

@spec validate(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) ::
  {:ok, :valid} | {:error, :invalid}

Validates the layout based on specified invariants on nodes, panes and other crucial elements

validate_node(arg1)