/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_select :+: :+: */
/* +:+ */
/* Author: Noah Loomans +#+ */
/* <nloomans@student.codam.nl> +#+ */
/* #+# #+# */
/* License: GPLv3 ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <libft.h>
#include <ft_printf.h>
#include "terminal.h"
#include "event.h"
#include "action.h"
#include "state.h"
#include "render.h"
#include "error.h"
static t_error loop(struct s_state *state)
{
t_error error;
t_action action;
error = event_next(&action);
if (is_error(error))
return (errorf("failed to get next event: %s", error.msg));
if (action != NULL)
{
(*action)(state);
render(*state);
}
return (ERROR_NULL);
}
int main(int argc, char **argv)
{
t_error error;
struct s_state state;
ft_memset(&state, '\0', sizeof(state));
error = event_init();
if (is_error(error))
{
return (ft_eprintf(1, "ft_select: failed to initialize events: %s\n",
error.msg));
}
action_update_size(&state);
error = state_make_options(&state.options, argc, argv);
if (is_error(error))
{
return (ft_eprintf(1, "ft_select: failed to initialize options: %s\n",
error.msg));
}
state.cursor = state.options.first;
terminal_configure(TERMINAL_CONFIGURE_SETUP);
render(state);
while (!is_error(error))
error = loop(&state);
terminal_configure(TERMINAL_CONFIGURE_RESTORE);
return (ft_eprintf(1, "ft_select: %s\n", error.msg));
}