Handling ctrl d as eof

This commit is contained in:
Anonymus Raccoon
2020-05-06 20:50:14 +02:00
parent 2b90136b3a
commit 37fb052694
6 changed files with 28 additions and 4 deletions
+1
View File
@@ -31,6 +31,7 @@ SRC = src/shell.c \
src/utility/get_return.c \
src/key_bindings/basic_typing_functions.c \
src/key_bindings/default_bindings.c \
src/key_bindings/control_commands.c \
src/redirections/pty_pipe.c
OBJ = $(SRC:%.c=%.o)
+4 -1
View File
@@ -9,6 +9,8 @@
#include "shell.h"
#define CTRL(c) ((c) & 0x1F)
typedef struct key_function
{
const char *name;
@@ -25,4 +27,5 @@ extern const key_function_t key_functions[];
extern const binding_t emacs_bindings[];
int self_insert_command(int key, buffer_t *buffer, env_t *env);
int newline_command(int key, buffer_t *buffer, env_t *env);
int newline_command(int key, buffer_t *buffer, env_t *env);
int eof_command(int key, buffer_t *buffer, env_t *env);
+1 -1
View File
@@ -107,8 +107,8 @@ void run_cmd(char **argv, redirection *inout[2], env_t *env)
path = eval(argv[0], argv, env);
return (exec_error(path, argv[0]));
}
waitpid(pid, &status, 0);
if (handle_parent_inout(inout, env, false))
return;
waitpid(pid, &status, 0);
handle_signal(status, env);
}
+13
View File
@@ -0,0 +1,13 @@
/*
** EPITECH PROJECT, 2020
** ash
** File description:
** control_commands
*/
#include "shell.h"
int eof_command(int key, buffer_t *buffer, env_t *env)
{
return (-1);
}
+2
View File
@@ -13,10 +13,12 @@
const key_function_t key_functions[] = {
{"self-insert-command", &self_insert_command},
{"newline", &newline_command},
{"enf-of-file", &eof_command},
{NULL, NULL}
};
const binding_t emacs_bindings[] = {
{'\n', &newline_command},
{CTRL('d'), &eof_command},
{0, NULL}
};
+7 -2
View File
@@ -84,8 +84,13 @@ void pty_get_output(redirection *pty, env_t *env)
FILE *file = fdopen(pty->extra_data, "r");
int y = getcury(env->window);
while (getline(&line, &size, file) > 0)
mvaddstr(y++, 0, line);
close(pty->fd);
while (getline(&line, &size, file) > 0) {
dprintf(2, "Writing at %d: %s\n", y, line);
mvaddstr(y, 0, line);
y++;
}
if (line)
free(line);
fclose(file);
}