-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
139 lines (121 loc) · 3.63 KB
/
main.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: tishj <tishj@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/03/05 21:13:58 by tishj #+# #+# */
/* Updated: 2021/05/18 16:55:01 by tbruinem ######## odam.nl */
/* */
/* ************************************************************************** */
#include "reins.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define PROMPT "\e[1;31mreins \e[0m\e[1;33m❯\e[0m "
void print_up(void *yeet)
{
(void)yeet;
printf("UP\n");
}
void print_a(void *yeet)
{
(void)yeet;
printf("\nAAAAAHHH\n");
}
int up_function(t_input *line, char *buf, t_hook *hook)
{
(void)line;
(void)buf;
(void)hook;
reins_hook_run(hook);
printf("\nOVERWRITTEN UP FUNCTION!\n");
return (RD_IDLE);
}
int insert_numbers(t_input *line, char *buf, t_hook *hook)
{
(void)buf;
(void)hook;
reins_input_add(line, "123456789", 9);
return (RD_IDLE);
}
int insert_X(t_input *line, char *buf, t_hook *hook)
{
(void)buf;
(void)hook;
reins_input_add(line, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 188);
return (RD_IDLE);
}
int insert_a_truckload(t_input *input, char *buf, t_hook *hook)
{
(void)buf;
(void)hook;
reins_input_add(input, "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 188);
return (RD_IDLE);
}
int delete_characters(t_input *input, char *buf, t_hook *hook)
{
(void)buf;
(void)hook;
return (reins_input_del(input, 30));
}
int delete_row(t_input *input, char *buf, t_hook *hook)
{
(void)buf;
(void)hook;
// columns = input->max_col - (!input->shell_cursor.row * input->prompt_size);
return (reins_input_del(input, 5));
}
int clear_input(t_input *input, char *buf, t_hook *hook)
{
(void)buf;
(void)hook;
return (reins_input_clear(input));
}
int reins_start(t_reins **reins)
{
*reins = reins_init();
if (!*reins)
return (!!printf("Failed to init reins!\n"));
if (!reins_key(*reins, KEY_ESC "[" KEY_UP, up_function))
return (!!printf("Failed to overwrite/add key!\n"));
if (!reins_hook(*reins, KEY_ESC "[" KEY_UP, &print_up, NULL))
return (!!printf("Failed to hook!\n"));
if (!reins_key(*reins, "A", insert_a_truckload))
return (1);
if (!reins_key(*reins, "x", insert_X))
return (1);
if (!reins_key(*reins, KEY_ESC "[3~", delete_characters))
return (1);
if (!reins_key(*reins, KEY_CNTRL_U, clear_input))
return (1);
return (0);
}
int main(void)
{
t_reins *reins;
char *line;
int ret;
line = NULL;
ret = 1;
if (reins_start(&reins))
return (-1);
while (ret)
{
write(1, PROMPT, sizeof(PROMPT));
// ret = reins_get_input(reins, &line);
ret = reins_print_keycodes(reins);
reins_disable(reins);
printf("\nLINE: |%s|\n", line);
free(line);
if (ret != 1)
break ;
}
reins_destroy(reins);
if (!ret)
return (!printf("\nexit\n"));
else if (ret == -1)
return (!!printf("reins_get_input failed!\n"));
return (0);
}