Drafter.Terminal.SignalWatcher (drafter v0.3.2)

Copy Markdown View Source

Forwards SIGWINCH to the terminal driver.

A :gen_event handler for :erl_signal_server, which is where OTP delivers a signal once :os.set_signal/2 has marked it as handled. SIGWINCH is relayed to the driver given to init/1 as {:signal, :winch}. Every other signal is ignored.

Install it with the driver as both the handler argument and the supervising process:

:os.set_signal(:sigwinch, :handle)

:gen_event.add_sup_handler(
  :erl_signal_server,
  {Drafter.Terminal.SignalWatcher, self()},
  self()
)

Summary

Types

Where {:signal, :winch} is sent: the driver named at installation.

Functions

Reply :ok to every call, leaving the state unchanged.

Relay :sigwinch to the driver as {:signal, :winch} and ignore every other signal.

Ignore every message.

Keep driver as the handler state. driver is where signals are relayed.

Remove the handler without touching the driver.

Types

driver()

@type driver() :: pid() | atom()

Where {:signal, :winch} is sent: the driver named at installation.

Functions

handle_call(request, driver)

@spec handle_call(term(), driver()) :: {:ok, :ok, driver()}

Reply :ok to every call, leaving the state unchanged.

handle_event(arg1, driver)

@spec handle_event(term(), driver()) :: {:ok, driver()}

Relay :sigwinch to the driver as {:signal, :winch} and ignore every other signal.

iex> {:ok, driver} = Drafter.Terminal.SignalWatcher.init(self())
iex> Drafter.Terminal.SignalWatcher.handle_event(:sigwinch, driver)
iex> Drafter.Terminal.SignalWatcher.handle_event(:sigterm, driver)
iex> receive do
...>   message -> message
...> after
...>   0 -> :nothing
...> end
{:signal, :winch}

handle_info(message, driver)

@spec handle_info(term(), driver()) :: {:ok, driver()}

Ignore every message.

init(driver)

@spec init(driver()) :: {:ok, driver()}

Keep driver as the handler state. driver is where signals are relayed.

iex> Drafter.Terminal.SignalWatcher.init(self())
{:ok, self()}

terminate(reason, driver)

@spec terminate(term(), driver()) :: :ok

Remove the handler without touching the driver.