random colored PID in DG()

This commit is contained in:
Jack Halford 2017-03-10 17:08:34 +01:00
parent 61f790b8fc
commit 81c7802c71
6 changed files with 21 additions and 15 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ /* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
/* Updated: 2017/02/18 13:21:03 by jhalford ### ########.fr */ /* Updated: 2017/03/10 16:56:01 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,7 +50,7 @@ extern t_conv g_convs[];
t_fmt *ft_fmt_init(void); t_fmt *ft_fmt_init(void);
void ft_fmt_print(t_fmt *fmt); void ft_fmt_print(t_fmt *fmt);
void ft_printf_color(int fd, char **final, char **str); void ft_printf_color(char **final, char **str, va_list ap);
t_fmt *ft_printf_parse(char **format, va_list ap); t_fmt *ft_printf_parse(char **format, va_list ap);
char *ft_transform(t_fmt *fmt, va_list ap); char *ft_transform(t_fmt *fmt, va_list ap);

View file

@ -6,15 +6,15 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
/* Updated: 2017/03/08 11:59:43 by jhalford ### ########.fr */ /* Updated: 2017/03/10 16:52:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef LIBFT_H #ifndef LIBFT_H
# define LIBFT_H # define LIBFT_H
# define DG_MSG0 "{inv}{yel}%21s {bol}{blu}%-3d{eoc}" # define DG_MSG0 "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
# define DG_MSG1 ft_path_notdir(__FILE__), __LINE__ # define DG_MSG1 getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
# define DG(f, ...) ft_dprintf(STDBUG, DG_MSG0 f "{eoc}\n", DG_MSG1, ##__VA_ARGS__) # define DG(f, ...) ft_dprintf(STDBUG, DG_MSG0 f "{eoc}\n", DG_MSG1, ##__VA_ARGS__)
# include <string.h> # include <string.h>

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
/* Updated: 2017/01/22 16:28:55 by jhalford ### ########.fr */ /* Updated: 2017/03/10 16:58:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
/* Updated: 2017/03/07 15:14:03 by jhalford ### ########.fr */ /* Updated: 2017/03/10 16:54:15 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,7 +53,7 @@ int ft_vdprintf(int fd, const char *format, va_list ap)
{ {
tmp = final; tmp = final;
if (*str == '{') if (*str == '{')
ft_printf_color(fd, &final, &str); ft_printf_color(&final, &str, ap);
else if (*str == '%') else if (*str == '%')
{ {
if (ft_fmtcalc(&final, &str, ap)) if (ft_fmtcalc(&final, &str, ap))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */ /* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
/* Updated: 2016/12/09 22:09:21 by jhalford ### ########.fr */ /* Updated: 2017/03/10 16:58:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,6 @@
t_stos g_colors[] = t_stos g_colors[] =
{ {
{"{bol}", ON_BOLD},
{"{und}", ON_UNDERLINED},
{"{inv}", ON_INVERTED},
{"{bla}", FG_BLACK}, {"{bla}", FG_BLACK},
{"{red}", FG_RED}, {"{red}", FG_RED},
{"{gre}", FG_GREEN}, {"{gre}", FG_GREEN},
@ -25,19 +22,28 @@ t_stos g_colors[] =
{"{mag}", FG_MAGENTA}, {"{mag}", FG_MAGENTA},
{"{cya}", FG_CYAN}, {"{cya}", FG_CYAN},
{"{eoc}", FG_DEFAULT}, {"{eoc}", FG_DEFAULT},
{"{bol}", ON_BOLD},
{"{und}", ON_UNDERLINED},
{"{inv}", ON_INVERTED},
{NULL, NULL}, {NULL, NULL},
}; };
void ft_printf_color(int fd, char **final, char **str) void ft_printf_color(char **final, char **str, va_list ap)
{ {
int i; int i;
i = 0; i = 0;
if (ft_strncmp(*str, "{ran}", 5) == 0)
{
i = va_arg(ap, int) % 7 + 1;
*final = ft_strjoin(*final, g_colors[i].val);
*str += 5;
return ;
}
while(g_colors[i].key) while(g_colors[i].key)
{ {
if (ft_strncmp(*str, g_colors[i].key, 5) == 0) if (ft_strncmp(*str, g_colors[i].key, 5) == 0)
{ {
(void)fd;
/* if (isatty(fd)) */ /* if (isatty(fd)) */
*final = ft_strjoin(*final, g_colors[i].val); *final = ft_strjoin(*final, g_colors[i].val);
*str += 5; *str += 5;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
/* Updated: 2016/11/16 17:46:16 by jhalford ### ########.fr */ /* Updated: 2017/03/10 16:54:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */