summaryrefslogtreecommitdiff
path: root/lib/chessh/ssh/client/screen.ex
blob: 20273a52476fffcb8ae1e976335b9d8fd90070cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
defmodule Chessh.SSH.Client.Screen do
  @callback render(width :: integer(), height :: integer(), state :: any()) :: any()
  @callback input(
              width :: integer(),
              height :: integer(),
              action :: any(),
              data :: String.t(),
              state :: any()
            ) ::
              any()

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

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

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