-
Notifications
You must be signed in to change notification settings - Fork 0
/
press_key5.c
executable file
·75 lines (68 loc) · 2.35 KB
/
press_key5.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* press_key5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bde-maze <bde-maze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/28 14:36:05 by bde-maze #+# #+# */
/* Updated: 2016/08/29 17:43:15 by bde-maze ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/shell.h"
int press_enter_key(void)
{
press_end_key();
if (ft_init_verif())
return (0);
if (ft_strcmp(g_shell.shell_line, "") != 0 && g_shell.shell_heredoc == 0 && g_shell.shell_line[0] != '!')
add_to_history(g_shell.history, g_shell.shell_line);
g_shell.backslash_index = -1;
if (g_shell.shell_heredoc == 0)
g_shell.history_index = get_history_length();
ft_putstr("\n");
return (1);
}
void press_shift_direction_key(char *buffer)
{
if (is_shift_right(buffer[5]))
press_shift_right(g_cursor, g_shell);
else if (is_shift_left(buffer[5]))
press_shift_left(g_cursor, g_shell);
else if (is_shift_up(buffer[5]))
press_shift_up();
else if (is_shift_down(buffer[5]))
press_shift_down();
}
void press_shift_left(void)
{
int index_nw;
int index_c;
index_c = g_cursor.position_line - 1;
index_nw = get_next_word_before(g_shell.shell_line, index_c);
if (index_nw < g_shell.last_backslash)
index_nw = g_shell.last_backslash;
while (index_c >= index_nw)
{
if (g_shell.backslash_index > 0)
g_shell.backslash_index--;
go_left(g_cursor, g_shell);
move_cursor_left(g_cursor, g_shell);
index_c--;
}
}
void press_shift_right(void)
{
int index_nw;
int index_c;
index_c = g_cursor.position_line;
index_nw = get_next_word_after(g_shell.shell_line, index_c);
while (index_c <= index_nw)
{
if (g_shell.backslash_index != -1)
g_shell.backslash_index++;
go_right(g_cursor, g_shell);
move_cursor_right(g_cursor, g_shell);
index_c++;
}
}