diff --git a/include/prompt.h b/include/prompt.h index 020e07a..a51ab25 100644 --- a/include/prompt.h +++ b/include/prompt.h @@ -11,6 +11,7 @@ char *prompt_attr(int attr, bool off); char *minimal_hostname(char *hostname); char *date_format(int date); +char *str_tolower(char *str); char *get_prompt_value(char c, env_t *env); diff --git a/src/prompt/prompt_utilities.c b/src/prompt/prompt_utilities.c index c0aab23..72ac184 100644 --- a/src/prompt/prompt_utilities.c +++ b/src/prompt/prompt_utilities.c @@ -6,6 +6,7 @@ */ #include +#include #include "my_ncurses.h" char *minimal_hostname(char *hostname) @@ -33,4 +34,11 @@ char *date_format(int date) sprintf(format, "%02d", date); return (format); +} + +char *str_tolower(char *str) +{ + for (int i = 0; str[i]; i++) + str[i] = tolower(str[i]); + return (str); } \ No newline at end of file diff --git a/src/prompt/prompt_values.c b/src/prompt/prompt_values.c index ed1a31c..8e9e30a 100644 --- a/src/prompt/prompt_values.c +++ b/src/prompt/prompt_values.c @@ -15,6 +15,29 @@ #include #include +char *get_prompt_value4(char c, env_t *env, struct tm *tm) +{ + static char time[11]; + + if (c == 't' || c == '@') { + strftime(time, sizeof(time), "%I:%M%p", tm); + return (str_tolower(time)); + } + if (c == 'T') { + strftime(time, sizeof(time), "%H:%M", tm); + return (time); + } + if (c == 'p') { + strftime(time, sizeof(time), "%I:%M:%S%p", tm); + return (str_tolower(time)); + } + if (c == 'P') { + strftime(time, sizeof(time), "%H:%M:%S", tm); + return (time); + } + return (time); +} + char *get_prompt_value3(char c, env_t *env) { time_t t = time(NULL); @@ -37,7 +60,7 @@ char *get_prompt_value3(char c, env_t *env) return (&tostr(tm->tm_year + 1900)[2]); if (c == 'Y') return (tostr(tm->tm_year + 1900)); - return (NULL); + return (get_prompt_value4(c, env, tm)); } char *get_prompt_value2(char c, env_t *env)