aboutsummaryrefslogtreecommitdiff
path: root/lib/ssh/screen.ex
blob: 8f0c7bde5efb6a659d67c42df26c697fa9c1875d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
defmodule TrongleSSH.SSH.Screen do
  @callback render(width :: integer(), height :: integer(), state :: any()) :: any()
  @callback input(width :: integer(), height :: integer(), action :: any(), state :: any()) ::
              any()

  defmacro __using__(_) do
    quote do
      @behaviour TrongleSSH.SSH.Screen
      use GenServer

      def handle_info({:render, width, height}, state),
        do: {:noreply, render(width, height, state)}

      def handle_info({:input, width, height, action}, state),
        do: {:noreply, input(width, height, action, state)}
    end
  end
end