Yeesh.Session (Yeesh v0.8.3)

View Source

Per-terminal session state, managed as a GenServer.

Each terminal instance gets its own session holding command history, environment variables, working directory, prompt config, and the Dune sandbox state for Elixir evaluation.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the full history list.

Gets the current mode.

Gets the current prompt string.

Returns the current session state.

Gets the next history entry (down arrow), optionally filtered by prefix.

Gets the previous history entry (up arrow), optionally filtered by prefix.

Searches history for entries containing query, returning the skip-th match.

Adds a command to the history.

Resets the history navigation index.

Starts a new session under the DynamicSupervisor.

Starts a session linked to the caller.

Updates the session state with the given function.

Types

t()

@type t() :: %Yeesh.Session{
  context: map(),
  cwd: String.t(),
  dune_session: Yeesh.Sandbox.dune_state(),
  env: %{required(String.t()) => String.t()},
  history: [String.t()],
  history_index: integer(),
  history_max_size: pos_integer(),
  history_prefix: String.t() | nil,
  mode: :normal | :elixir_repl | :mix_task,
  prompt: String.t(),
  started_at: DateTime.t()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_history(pid)

@spec get_history(pid()) :: [String.t()]

Returns the full history list.

get_mode(pid)

@spec get_mode(pid()) :: :normal | :elixir_repl | :mix_task

Gets the current mode.

get_prompt(pid)

@spec get_prompt(pid()) :: String.t()

Gets the current prompt string.

get_state(pid)

@spec get_state(pid()) :: t()

Returns the current session state.

history_next(pid, prefix \\ nil)

@spec history_next(pid(), String.t() | nil) :: {:ok, String.t()} | :end

Gets the next history entry (down arrow), optionally filtered by prefix.

history_prev(pid, prefix \\ nil)

@spec history_prev(pid(), String.t() | nil) :: {:ok, String.t()} | :empty

Gets the previous history entry (up arrow), optionally filtered by prefix.

history_search(pid, query, skip \\ 0)

@spec history_search(pid(), String.t(), non_neg_integer()) ::
  {:ok, String.t()} | :no_match

Searches history for entries containing query, returning the skip-th match.

push_history(pid, command)

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

Adds a command to the history.

reset_history_index(pid)

@spec reset_history_index(pid()) :: :ok

Resets the history navigation index.

start(opts \\ [])

@spec start(keyword()) :: {:ok, pid()} | {:error, term()}

Starts a new session under the DynamicSupervisor.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a session linked to the caller.

update(pid, fun)

@spec update(pid(), (t() -> t())) :: t()

Updates the session state with the given function.