diff --git a/Makefile b/Makefile index 45cb4f4..78c0632 100644 --- a/Makefile +++ b/Makefile @@ -41,10 +41,8 @@ SRC = src/shell.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 \ src/key_bindings/move_commands.c \ src/my_ncurses/my_ncurses.c \ - src/my_ncurses/clear_utils.c \ src/my_ncurses/string_utils.c OBJ = $(SRC:%.c=%.o) diff --git a/src/key_bindings/basic_typing_functions.c b/src/key_bindings/basic_typing_functions.c index 58a4187..5d3f3a8 100644 --- a/src/key_bindings/basic_typing_functions.c +++ b/src/key_bindings/basic_typing_functions.c @@ -67,6 +67,7 @@ int newline_command(int key, buffer_t *buffer, env_t *env) ret = eval_raw_cmd(buffer->buffer, env); buffer->buffer[0] = '\0'; buffer->pos = 0; + my_getcuryx(&env->window->y, &env->window->x); } if (env->window && ret >= 0) prompt_prepare(buffer, env); diff --git a/src/my_ncurses/my_ncurses.c b/src/my_ncurses/my_ncurses.c index 9a9ede8..bc13b0c 100644 --- a/src/my_ncurses/my_ncurses.c +++ b/src/my_ncurses/my_ncurses.c @@ -19,7 +19,6 @@ void on_resize(int sig, siginfo_t *info, void *context) { my_getmaxyx(&stdwin->h, &stdwin->w); my_getcuryx(&stdwin->y, &stdwin->x); - my_clrtobot(); } my_window *my_initwin(void) diff --git a/src/prompt.c b/src/prompt.c index e6b7efe..e9f0235 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -43,8 +43,6 @@ int prompt_run(char *cmd, redirection *inout[2], env_t *env) argv = globbing(argv); if (!argv) return (0); - if (env->window && inout[1] == NULL) - inout[1] = new_ncurses_pty(); if (**argv == '!' && argv[0][1] && argv[0][1] != ' ') return (run_builtin(&builtins[5], argv, inout, env)); for (int i = 0; builtins[i].name; i++) diff --git a/src/redirections/pty_pipe.c b/src/redirections/pty_pipe.c deleted file mode 100644 index 059e25a..0000000 --- a/src/redirections/pty_pipe.c +++ /dev/null @@ -1,102 +0,0 @@ -/* -** EPITECH PROJECT, 2020 -** ash -** File description: -** pty_pipe -*/ - -#include "redirections.h" -#include "my_ncurses.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _XOPEN_SOURCE 600 -#define __USE_XOPEN_EXTENDED -#include - - -const struct redirection_map pty_type = { - .key = NULL, - .get_fd = &pyt_get_fd, - .run_cmd = &pty_get_output, - .type = OUTPUT | PIPE | EX_PIPE | PTY -}; - -int pty_open(char **slave_name) -{ - int master = open("/dev/ptmx", O_RDWR | O_NOCTTY); - int my_errno; - - *slave_name = NULL; - if (master < 0) - return (-1); - if (grantpt(master) < 0 || unlockpt(master) < 0 - || !(*slave_name = ptsname(master))) { - my_errno = errno; - close(master); - errno = my_errno; - return (-1); - } - return (master); -} - -struct redirection *new_ncurses_pty(void) -{ - struct redirection *pty = malloc(sizeof(*pty)); - char *slave; - - if (!pty) - return (NULL); - pty->type = &pty_type; - pty->fd = -1; - pty->extra_data = pty_open(&slave); - if (pty->extra_data < 0) { - perror(SHELL_NAME); - return (pty); - } - pty->fd = open(slave, O_RDWR); - if (pty->fd == -1) - perror(SHELL_NAME); - return (pty); -} - -int pyt_get_fd(redirection *pty) -{ - struct termios termios; - struct winsize winsize; - - tcgetattr(0, &termios); - tcsetattr(pty->fd, TCSANOW, &termios); - - ioctl(0, TIOCGWINSZ, &winsize); - ioctl(pty->fd, TIOCSWINSZ, &winsize); - dup2(pty->fd, 2); - return (pty->fd); -} - -void pty_get_output(redirection *pty, env_t *env) -{ - char *line = NULL; - size_t size = 0; - FILE *file = fdopen(pty->extra_data, "r"); - - close(pty->fd); - while (getline(&line, &size, file) > 0) - my_addstr(env->window, line); - if (line) { - if (line[0] && !strchr(line, '\n')) { - my_attron(BACKGROUND_COLOR, WHITE); - my_attron(COLOR, BLACK); - my_addstr(env->window, "%\n"); - my_attrreset(); - } - free(line); - } - fclose(file); -} \ No newline at end of file