~nloomans/ft_select

1e1794e18e668196cc6b0e137316f1903964b06d — Noah Loomans 1 year, 9 months ago 9783305
display message when terminal is too small to display all options
3 files changed, 32 insertions(+), 1 deletions(-)

M inc/derive.h
M src/derive.c
M src/render.c
M inc/derive.h => inc/derive.h +4 -0
@@ 43,6 43,10 @@ t_error	derive_column_width(
			size_t **res,
			struct s_derived_dimensions dimensions,
			t_list2 options);
bool	derive_enough_columns(
			struct s_state_terminal terminal,
			struct s_derived_dimensions dimensions,
			size_t *column_width);
t_error	derive_rows(
			struct s_state_option ****res,
			struct s_derived_dimensions dimensions,

M src/derive.c => src/derive.c +20 -1
@@ 13,7 13,7 @@ t_error			derive_dimensions(
					t_list2 options)
{
	if (DERIVE_PADDING_TOP + DERIVE_PADDING_BOTTOM + 1 > terminal.rows)
		return (errorf("not enough height to display options"));
		return (errorf("terminal too short to display options"));
	dimensions->rows =
		terminal.rows - DERIVE_PADDING_TOP - DERIVE_PADDING_BOTTOM;
	dimensions->columns =


@@ 103,6 103,25 @@ t_error			derive_rows(
	return (ERROR_NULL);
}

bool			derive_enough_columns(
					struct s_state_terminal terminal,
					struct s_derived_dimensions dimensions,
					size_t *column_width)
{
	size_t	total_width;
	size_t	i;

	total_width = DERIVE_PADDING_LEFT + DERIVE_PADDING_RIGHT;
	i = 0;
	while (i < dimensions.columns)
	{
		total_width += DERIVE_OPTION_PADDING_LEFT
			+ column_width[i] + DERIVE_OPTION_PADDING_RIGHT;
		i++;
	}
	return (total_width <= terminal.columns);
}

void			derive_free_rows(
					struct s_derived_dimensions dimensions,
					struct s_state_option ****rows)

M src/render.c => src/render.c +8 -0
@@ 62,15 62,23 @@ void		render(const struct s_state state)
	error = derive_dimensions(&dimensions, state.terminal, state.options);
	if (is_error(error))
	{
		terminal_send(TERMINAL_CLEAR_SCREEN);
		ft_dprintf(STDERR_FILENO, "%s", error.msg);
		return ;
	}
	error = derive_column_width(&column_width, dimensions, state.options);
	if (is_error(error))
	{
		terminal_send(TERMINAL_CLEAR_SCREEN);
		ft_dprintf(STDERR_FILENO, "%s", error.msg);
		return ;
	}
	if (!derive_enough_columns(state.terminal, dimensions, column_width))
	{
		terminal_send(TERMINAL_CLEAR_SCREEN);
		ft_dprintf(STDERR_FILENO, "terminal too small to display options");
		return ;
	}
	error = derive_rows(&rows, dimensions, state.options);
	if (is_error(error))
	{