Adding quoted insert commandé

This commit is contained in:
Anonymus Raccoon
2020-05-24 15:37:12 +02:00
parent 74d2348558
commit 7548d7fbac
6 changed files with 27 additions and 3 deletions
+2 -1
View File
@@ -52,7 +52,8 @@ SRC = src/shell.c \
src/my_ncurses/string_utils.c \
src/my_ncurses/pause_utils.c \
src/key_bindings/autocompletion.c \
src/builtin/builtin_bindkey.c
src/builtin/builtin_bindkey.c \
src/key_bindings/other_bindings.c
OBJ = $(SRC:%.c=%.o)
OBJ += src/main.o
+1 -1
View File
@@ -44,6 +44,6 @@ 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 quoted_insert_command(int key, buffer_t *buffer, env_t *env);
int clear_screen_command(int key, buffer_t *buffer, env_t *env);
int complete_command(int key, buffer_t *buffer, env_t *env);
+1
View File
@@ -33,6 +33,7 @@ typedef struct buffer
int startx;
int history_index;
char *saved_buffer;
bool quoted_insert;
} buffer_t;
typedef struct alias_s
+2
View File
@@ -24,6 +24,7 @@ const key_function_t key_functions[] = {
{"down-history", &down_history_command},
{"complete-command", &complete_command},
{"clear-screen", &clear_screen_command},
{"quoted-insert", &quoted_insert_command},
{NULL, NULL}
};
@@ -41,6 +42,7 @@ const binding_t emacs_bindings[] = {
{KEY_DOWN, &down_history_command},
{'\t', &complete_command},
{CTRL('l'), &clear_screen_command},
{CTRL('v'), &quoted_insert_command},
{0, NULL}
};
+16
View File
@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2020
** ash
** File description:
** other_bindings
*/
#include "shell.h"
#include "key_functions.h"
#include <stdbool.h>
int quoted_insert_command(int key, buffer_t *buffer, env_t *env)
{
buffer->quoted_insert = true;
return (0);
}
+5 -1
View File
@@ -24,6 +24,10 @@ int process_key(int key, buffer_t *buffer, env_t *env)
if (key <= 0)
return (0);
my_clrtobot();
if (buffer->quoted_insert) {
buffer->quoted_insert = false;
return (self_insert_command(key, buffer, env));
}
for (int i = 0; env->bindings[i].func; i++)
if (key == env->bindings[i].key)
return (env->bindings[i].func(key, buffer, env));
@@ -67,7 +71,7 @@ void shell_refresh(buffer_t *buffer, env_t *env)
void start_shell(env_t *env)
{
buffer_t buffer = {NULL, 0, 0, 0, 0, NULL};
buffer_t buffer = {NULL, 0, 0, 0, 0, NULL, false};
int key;
if (isatty(0)) {