Merge branch 'prompt' of github.com:AnonymusRaccoon/ash into prompt

This commit is contained in:
Anonymus Raccoon
2020-05-24 21:41:33 +02:00
3 changed files with 33 additions and 1 deletions
+1
View File
@@ -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);
+8
View File
@@ -6,6 +6,7 @@
*/
#include <stdbool.h>
#include <ctype.h>
#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);
}
+24 -1
View File
@@ -15,6 +15,29 @@
#include <stdio.h>
#include <time.h>
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)