better powerline and signal fixes
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
#ifndef MINISHELL_H
|
#ifndef MINISHELL_H
|
||||||
# define MINISHELL_H
|
# define MINISHELL_H
|
||||||
|
|
||||||
# define DEBUG 1
|
# define DEBUG 0
|
||||||
|
|
||||||
# ifndef DIO_PATH
|
# ifndef DIO_PATH
|
||||||
# define DIO_PATH "ast.xml"
|
# define DIO_PATH "ast.xml"
|
||||||
@@ -40,6 +40,8 @@ typedef struct s_msh
|
|||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
|
# include <termios.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
# include "../lib/libft/libft.h"
|
# include "../lib/libft/libft.h"
|
||||||
# include "parser/ast.h"
|
# include "parser/ast.h"
|
||||||
@@ -65,5 +67,6 @@ char *powerline(t_msh *msh);
|
|||||||
# define POW3 "\033[1;38;2;54;54;54;48;2;39;39;39m"
|
# define POW3 "\033[1;38;2;54;54;54;48;2;39;39;39m"
|
||||||
# define POW4 "\033[0;38;2;204;205;209;48;2;39;39;39m"
|
# define POW4 "\033[0;38;2;204;205;209;48;2;39;39;39m"
|
||||||
# define POW5 "\033[1;38;2;39;39;39m"
|
# define POW5 "\033[1;38;2;39;39;39m"
|
||||||
|
# define SEP "\033[38;2;64;64;64m"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
34
srcs/main.c
34
srcs/main.c
@@ -14,24 +14,6 @@
|
|||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
|
|
||||||
int g_sig = 0;
|
|
||||||
|
|
||||||
void handle_sigint(int sig)
|
|
||||||
{
|
|
||||||
(void)sig;
|
|
||||||
g_sig = SIGINT;
|
|
||||||
rl_replace_line("", 0);
|
|
||||||
// rl_on_new_line();
|
|
||||||
rl_done = 1;
|
|
||||||
rl_redisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_sigquit(int sig)
|
|
||||||
{
|
|
||||||
(void)sig;
|
|
||||||
// ft_printf("\b\b");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add_prevhistory(t_msh *msh)
|
static void add_prevhistory(t_msh *msh)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
@@ -52,9 +34,8 @@ int interactive_mode(t_msh *msh)
|
|||||||
{
|
{
|
||||||
msh->input = malloc(1);
|
msh->input = malloc(1);
|
||||||
msh->input[0] = 0;
|
msh->input[0] = 0;
|
||||||
while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT)
|
while (!msh->input[0] || is_only_space(msh->input))
|
||||||
{
|
{
|
||||||
g_sig = 0;
|
|
||||||
free(msh->input);
|
free(msh->input);
|
||||||
msh->input = powerline(msh);
|
msh->input = powerline(msh);
|
||||||
if (!msh->input)
|
if (!msh->input)
|
||||||
@@ -62,15 +43,19 @@ int interactive_mode(t_msh *msh)
|
|||||||
}
|
}
|
||||||
if (!msh->input)
|
if (!msh->input)
|
||||||
return (1);
|
return (1);
|
||||||
if (g_sig != SIGINT)
|
interpret_cmd(&msh->input, msh);
|
||||||
interpret_cmd(&msh->input, msh);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av, char **envp)
|
int main(int ac, char **av, char **envp)
|
||||||
{
|
{
|
||||||
t_msh *msh;
|
t_msh *msh;
|
||||||
|
struct termios term;
|
||||||
|
|
||||||
|
(void)av;
|
||||||
|
tcgetattr(STDIN_FILENO, &term);
|
||||||
|
term.c_cc[VQUIT] = _POSIX_VDISABLE;
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &term);
|
||||||
msh = init_msh(envp);
|
msh = init_msh(envp);
|
||||||
init_sig();
|
init_sig();
|
||||||
add_prevhistory(msh);
|
add_prevhistory(msh);
|
||||||
@@ -83,9 +68,6 @@ int main(int ac, char **av, char **envp)
|
|||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
ft_error("minishell : usages : - ./minishell\n");
|
||||||
msh->input = ft_strdup(av[1]);
|
|
||||||
interpret_cmd(&msh->input, msh);
|
|
||||||
}
|
|
||||||
free_msh(msh);
|
free_msh(msh);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,11 @@ char *powerline(t_msh *msh)
|
|||||||
char *pwd;
|
char *pwd;
|
||||||
char *input;
|
char *input;
|
||||||
char *prompt;
|
char *prompt;
|
||||||
|
struct winsize w;
|
||||||
|
|
||||||
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
pwd = get_pwd();
|
pwd = get_pwd();
|
||||||
prompt = ft_sprintf("\n%s MMOAT %s%s %s%s %s%s%s ", POW1, POW2, POW3,
|
prompt = ft_sprintf("%s%s%s\n%s MMOAT %s%s %s%s %s%s%s ", SEP, rep_c('-', w.ws_col), RESET, POW1, POW2, POW3,
|
||||||
POW4, pwd, RESET, POW5, RESET);
|
POW4, pwd, RESET, POW5, RESET);
|
||||||
input = readline(prompt);
|
input = readline(prompt);
|
||||||
handle_input(input, msh);
|
handle_input(input, msh);
|
||||||
|
|||||||
15
srcs/sig.c
15
srcs/sig.c
@@ -30,3 +30,18 @@ void init_sig(void)
|
|||||||
(sa[1]).sa_handler = handle_sigquit;
|
(sa[1]).sa_handler = handle_sigquit;
|
||||||
sigaction(SIGQUIT, &(sa[1]), NULL);
|
sigaction(SIGQUIT, &(sa[1]), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_sigint(int sig)
|
||||||
|
{
|
||||||
|
(void)sig;
|
||||||
|
write(2, "\n\n", 2);
|
||||||
|
rl_on_new_line();
|
||||||
|
rl_replace_line("", 0);
|
||||||
|
rl_redisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_sigquit(int sig)
|
||||||
|
{
|
||||||
|
(void)sig;
|
||||||
|
// ft_printf("\b\b");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user