fixed readline() prompt offset with '\001' and '\002' escape characters.
Colors change works, still bug with special chars like '€' .
This commit is contained in:
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "libft"]
|
[submodule "libft"]
|
||||||
path = libft
|
path = libft
|
||||||
url = https://github.com/LuckyLaszlo/libft
|
url = https://LuckyLaszlo@bitbucket.org/LuckyLaszlo/libft.git
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -13,7 +13,7 @@ HEADERS_D = ./headers
|
|||||||
HEADERS = minishell.h
|
HEADERS = minishell.h
|
||||||
|
|
||||||
LIBS = -L $(LIBFT_D) -lft \
|
LIBS = -L $(LIBFT_D) -lft \
|
||||||
-lreadline
|
-lreadline -ltermcap
|
||||||
|
|
||||||
LIBFT_D = ./libft
|
LIBFT_D = ./libft
|
||||||
LIBFT = $(LIBFT_D)/libft.a
|
LIBFT = $(LIBFT_D)/libft.a
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/03 19:14:46 by lperrey #+# #+# */
|
/* Created: 2021/10/03 19:14:46 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/10/03 19:14:49 by lperrey ### ########.fr */
|
/* Updated: 2021/10/07 06:33:55 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
** <signal.h>: sigaction()
|
** <signal.h>: sigaction()
|
||||||
** <readline/readline.h>,
|
** <readline/readline.h>,
|
||||||
** <readline/history.h>,
|
** <readline/history.h>,
|
||||||
** lib readline (-lreadline),
|
** Readline Library (-lreadline),
|
||||||
** readline(), rl_clear_history(), rl_on_new_line(),
|
** readline(), rl_clear_history(), rl_on_new_line(),
|
||||||
** rl_replace_line(), rl_redisplay(), add_history()
|
** rl_replace_line(), rl_redisplay(), add_history()
|
||||||
** ------------------
|
** ------------------
|
||||||
@@ -58,8 +58,9 @@
|
|||||||
** <dirent.h>: opendir(), readdir(), closedir()
|
** <dirent.h>: opendir(), readdir(), closedir()
|
||||||
** <termios.h>: tcsetattr(), tcgetattr()
|
** <termios.h>: tcsetattr(), tcgetattr()
|
||||||
** <curses.h>,
|
** <curses.h>,
|
||||||
** <term.h>: tgetent(), tgetflag(), tgetnum(),
|
** <term.h>: Termcap Library (-ltermcap)
|
||||||
** tgetstr(), tgoto(), tputs()
|
** tgetent(), tgetflag(), tgetnum(), tgetstr(),
|
||||||
|
** tgoto(), tputs()
|
||||||
** ------------------
|
** ------------------
|
||||||
** <sys/stat.h>: open(), stat(), lstat(), fstat()
|
** <sys/stat.h>: open(), stat(), lstat(), fstat()
|
||||||
** <sys/types.h>: open(), wait(), waitpid(), wait3(), wait4(), kill()
|
** <sys/types.h>: open(), wait(), waitpid(), wait3(), wait4(), kill()
|
||||||
|
|||||||
68
srcs/main.c
68
srcs/main.c
@@ -6,29 +6,31 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/10/04 06:13:56 by lperrey ### ########.fr */
|
/* Updated: 2021/10/07 07:20:04 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
#define TERM_RESET "\e[0m"
|
// Macro RL_PROMPT_START_IGNORE == '\001'
|
||||||
#define TERM_BLACK "\e[0;30m"
|
// Macro RL_PROMPT_END_IGNORE == '\002'
|
||||||
#define TERM_GRAY "\e[1;30m"
|
#define TERM_RESET "\001\e[0m\002"
|
||||||
#define TERM_RED "\e[0;31m"
|
#define TERM_BLACK "\001\e[0;30m\002"
|
||||||
#define TERM_LIGHT_RED "\e[1;31m"
|
#define TERM_GRAY "\001\e[1;30m\002"
|
||||||
#define TERM_GREEN "\e[0;32m"
|
#define TERM_RED "\001\e[0;31m\002"
|
||||||
#define TERM_LIGHT_GREEN "\e[1;32m"
|
#define TERM_LIGHT_RED "\001\e[1;31m\002"
|
||||||
#define TERM_BROWN "\e[0;33m"
|
#define TERM_GREEN "\001\e[0;32m\002"
|
||||||
#define TERM_YELLOW "\e[1;33m"
|
#define TERM_LIGHT_GREEN "\001\e[1;32m\002"
|
||||||
#define TERM_BLUE "\e[0;34m"
|
#define TERM_BROWN "\001\e[0;33m\002"
|
||||||
#define TERM_LIGHT_BLUE "\e[1;34m"
|
#define TERM_YELLOW "\001\e[1;33m\002"
|
||||||
#define TERM_PURPLE "\e[0;35m"
|
#define TERM_BLUE "\001\e[0;34m\002"
|
||||||
#define TERM_LIGHT_PURPLE "\e[1;35m"
|
#define TERM_LIGHT_BLUE "\001\e[1;34m\002"
|
||||||
#define TERM_CYAN "\e[0;36m"
|
#define TERM_PURPLE "\001\e[0;35m\002"
|
||||||
#define TERM_LIGHT_CYAN "\e[1;36m"
|
#define TERM_LIGHT_PURPLE "\001\e[1;35m\002"
|
||||||
#define TERM_LIGHT_GRAY "\e[0;37m"
|
#define TERM_CYAN "\001\e[0;36m\002"
|
||||||
#define TERM_WHITE "\e[1;37m"
|
#define TERM_LIGHT_CYAN "\001\e[1;36m\002"
|
||||||
|
#define TERM_LIGHT_GRAY "\001\e[0;37m\002"
|
||||||
|
#define TERM_WHITE "\001\e[1;37m\002"
|
||||||
|
|
||||||
char *ft_strjoinfree_s1(char *s1, const char *s2)
|
char *ft_strjoinfree_s1(char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
@@ -50,17 +52,37 @@ char *ft_strjoinfree_s2(const char *s1, char *s2)
|
|||||||
|
|
||||||
int main(int argc, char *argv[], char *envp[])
|
int main(int argc, char *argv[], char *envp[])
|
||||||
{
|
{
|
||||||
char *path;
|
|
||||||
char *prompt_base;
|
char *prompt_base;
|
||||||
char *prompt;
|
char *prompt;
|
||||||
char *line_input;
|
char *line_input;
|
||||||
|
char term_desc[2048];
|
||||||
|
char *term_type;
|
||||||
|
int term_width;
|
||||||
|
int term_height;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
//ft_putendl_arr_fd(envp, 1);
|
||||||
|
//char *path = getenv("PATH");
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
(void)envp;
|
(void)envp;
|
||||||
ft_putendl_arr_fd(envp, 1);
|
|
||||||
path = getenv("PATH");
|
term_type = getenv("TERM");
|
||||||
//printf("%s", path);
|
if (term_type == 0)
|
||||||
|
ft_putstr_fd("Specify a terminal type with `setenv TERM <yourtype>'.\n", 2);
|
||||||
|
ret = tgetent(term_desc, term_type);
|
||||||
|
if (ret < 0)
|
||||||
|
ft_putstr_fd("Could not access the termcap data base.\n", 2);
|
||||||
|
if (ret == 0)
|
||||||
|
ft_putstr_fd("Terminal type `%s' is not defined.\n", 2);
|
||||||
|
term_height = tgetnum ("li");
|
||||||
|
term_width = tgetnum ("co");
|
||||||
|
/* Extract information that termcap functions use. */
|
||||||
|
/* temp = tgetstr ("pc", BUFFADDR);
|
||||||
|
PC = temp ? *temp : 0;
|
||||||
|
BC = tgetstr ("le", BUFFADDR);
|
||||||
|
UP = tgetstr ("up", BUFFADDR); */
|
||||||
|
|
||||||
prompt_base = ft_strjoin(TERM_LIGHT_GREEN, getenv("USER"));
|
prompt_base = ft_strjoin(TERM_LIGHT_GREEN, getenv("USER"));
|
||||||
prompt_base = ft_strjoinfree_s1(prompt_base, "@");
|
prompt_base = ft_strjoinfree_s1(prompt_base, "@");
|
||||||
prompt_base = ft_strjoinfree_s1(prompt_base, getenv("NAME"));
|
prompt_base = ft_strjoinfree_s1(prompt_base, getenv("NAME"));
|
||||||
@@ -73,7 +95,7 @@ int main(int argc, char *argv[], char *envp[])
|
|||||||
free(line_input);
|
free(line_input);
|
||||||
free(prompt);
|
free(prompt);
|
||||||
prompt = ft_strjoinfree_s2(prompt_base, getcwd(NULL, 0));
|
prompt = ft_strjoinfree_s2(prompt_base, getcwd(NULL, 0));
|
||||||
prompt = ft_strjoinfree_s1(prompt, TERM_RESET"€ ");
|
prompt = ft_strjoinfree_s1(prompt, TERM_RESET"& ");
|
||||||
line_input = readline(prompt);
|
line_input = readline(prompt);
|
||||||
if (line_input && *line_input)
|
if (line_input && *line_input)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user