-module(terminal_ffi).
-export([enter_raw/0, exit_raw/0, window_size/0]).
enter_raw() ->
try
shell:start_interactive({noshell, raw}),
tty_state:set_raw(true),
input_ffi:restart_or_start_input_loop(),
{ok, nil}
catch
_:_ ->
{error, failed_to_enter_raw_mode}
end.
exit_raw() ->
try
shell:start_interactive(noshell),
tty_state:set_raw(false),
input_ffi:restart_or_start_input_loop(),
{ok, nil}
catch
_:_ ->
{error, failed_to_exit_raw_mode}
end.
window_size() ->
case io:columns() of
{ok, Cols} ->
case io:rows() of
{ok, Rows} ->
{ok, {Cols, Rows}};
_ ->
{error, could_not_get_window_size}
end;
_ ->
{error, could_not_get_window_size}
end.