From 723dd13aba0603323daebfffac709a37d3e53b0a Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Thu, 21 May 2020 18:23:50 +0200 Subject: [PATCH] Starting the autocompletion --- Makefile | 3 ++- include/key_functions.h | 2 ++ src/key_bindings/autocompletion.c | 16 ++++++++++++++++ src/key_bindings/default_bindings.c | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/key_bindings/autocompletion.c diff --git a/Makefile b/Makefile index 8980c7b..5977f96 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,8 @@ SRC = src/shell.c \ src/key_bindings/move_commands.c \ src/my_ncurses/my_ncurses.c \ src/my_ncurses/string_utils.c \ - src/my_ncurses/pause_utils.c + src/my_ncurses/pause_utils.c \ + src/key_bindings/autocompletion.c OBJ = $(SRC:%.c=%.o) OBJ += src/main.o diff --git a/include/key_functions.h b/include/key_functions.h index ff31335..467eb43 100644 --- a/include/key_functions.h +++ b/include/key_functions.h @@ -41,3 +41,5 @@ int end_of_line_command(int key, buffer_t *buffer, env_t *env); int up_history_command(int key, buffer_t *buffer, env_t *env); int down_history_command(int key, buffer_t *buffer, env_t *env); + +int complete_command(int key, buffer_t *buffer, env_t *env); \ No newline at end of file diff --git a/src/key_bindings/autocompletion.c b/src/key_bindings/autocompletion.c new file mode 100644 index 0000000..4f6619b --- /dev/null +++ b/src/key_bindings/autocompletion.c @@ -0,0 +1,16 @@ +/* +** EPITECH PROJECT, 2020 +** ash +** File description: +** autocompletion +*/ + +#include "shell.h" + +int complete_command(int key, buffer_t *buffer, env_t *env) +{ + if (!buffer->buffer || + (!strchr(buffer->buffer, ' ') && !strchr(buffer->buffer, '\t'))) + return (0); + return (0); +} \ No newline at end of file diff --git a/src/key_bindings/default_bindings.c b/src/key_bindings/default_bindings.c index 91595af..406c350 100644 --- a/src/key_bindings/default_bindings.c +++ b/src/key_bindings/default_bindings.c @@ -20,6 +20,8 @@ const key_function_t key_functions[] = { {"forward-char", &forward_char_command}, {"beginning-of-line", &beginning_of_line_command}, {"end-of-line", &end_of_line_command}, + {"up-history", &up_history_command}, + {"down-history", &down_history_command}, {NULL, NULL} }; @@ -35,5 +37,6 @@ const binding_t emacs_bindings[] = { {KEY_END, &end_of_line_command}, {KEY_UP, &up_history_command}, {KEY_DOWN, &down_history_command}, + {'\t', &complete_command}, {0, NULL} }; \ No newline at end of file