~nloomans/ft_select

ref: a4ef762331941c5e33670f7bf81eb964fb761edb ft_select/src/render.debug.c -rw-r--r-- 1.9 KiB
a4ef7623Noah Loomans fix build on linux 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>
#include <ft_printf.h>
#include "state.h"
#include "terminal.h"
#include "render.h"

static void	render_option(struct s_state_option *option, bool focused)
{
	ft_dprintf(STDERR_FILENO,
		"    %p (%+d) {\"%s\", .selected = %s},%s\n",
		option, (char *)&option->conn - (char *)option,
		option->name,
		option->selected
			? "true" : "false",
		focused ? " // focused" : "");
}

void		render(const struct s_state state)
{
	struct s_state_option	*option;

	terminal_send(TERMINAL_CLEAR_SCREEN);
	ft_dprintf(STDERR_FILENO,
		"struct s_state {\n"
		"  .options = {\n");
	option = unpack_option(state.options.first);
	while (option != NULL)
	{
		render_option(option, state.cursor == &option->conn);
		option = unpack_option(option->conn.next);
	}
	ft_dprintf(STDERR_FILENO,
		"  },\n"
		"  .cursor = %p, // %s\n"
		"  .terminal = {\n"
		"    .rows = %u,\n"
		"    .columns = %u,\n"
		"  },\n"
		"}\n",
		state.cursor, unpack_option(state.cursor)->name,
		state.terminal.rows,
		state.terminal.columns);
}