Skip to main content

src/etch/erlang/signal_handler.erl

-module(signal_handler).

-behaviour(gen_event).

-export([init/1, handle_event/2, handle_info/2, code_change/3, terminate/2,
         handle_call/2]).

init(Subject) ->
    ok = os:set_signal(sigwinch, handle),
    {ok, Subject}.

handle_event(sigwinch, State) ->
    case terminal_ffi:window_size() of
        {ok, {Cols, Rows}} ->
            input_ffi:push({ok, {resize, Cols, Rows}});
        _ ->
            input_ffi:push({error, could_not_get_window_size})
    end,
    {ok, State};
handle_event(_Event, State) ->
    {ok, State}.

handle_info(_Info, State) ->
    {ok, State}.

handle_call(_, State) ->
    {ok, State}.

terminate(_Reason, _State) ->
    ok.

code_change(_Old, State, _Extra) ->
    {ok, State}.