mirror of
https://github.com/troglobit/finit.git
synced 2026-11-17 19:30:29 +00:00
Convert banner() and printv() to use new screen_init() values
This patch changes the traditional look of the Finit boot sequence. Now we stick to the screen width probed by screen_init(), or max 132 chars. Also, some minor cleanup of the currently unused print_timestamp() method used by printv() when showing [ OK ] or [FAIL] of services at boot. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
be6f0de0df
commit
99818f9ce0
2 files changed
+30
-26
No files matched your search
+4
-3
@@ -64,13 +64,14 @@ uev_ctx_t *ctx = NULL; /* Main loop context */
|
|||||||
|
|
||||||
static void banner(void)
|
static void banner(void)
|
||||||
{
|
{
|
||||||
char buf[42] = INIT_HEADING;
|
char *buf = INIT_HEADING;
|
||||||
const char separator[] = "========================================================================";
|
char separator[SCREEN_WIDTH];
|
||||||
|
|
||||||
if (log_is_silent())
|
if (log_is_silent())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf(stderr, "\e[2K\e[1m%s %.*s\e[0m\n", buf, 66 - (int)strlen(buf), separator);
|
memset(separator, '=', sizeof(separator));
|
||||||
|
fprintf(stderr, "\e[2K\e[1m%s %.*s\e[0m\n", buf, SCREEN_WIDTH - (int)strlen(buf) - 2, separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Requires /proc to be mounted */
|
/* Requires /proc to be mounted */
|
||||||
|
|||||||
+26
-23
@@ -57,52 +57,55 @@ char *strip_line(char *line)
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_timestamp(void)
|
static size_t print_timestamp(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_PRINTK_TIME)
|
#if defined(CONFIG_PRINTK_TIME)
|
||||||
FILE * uptimefile;
|
FILE *fp;
|
||||||
float num1, num2;
|
float stamp, dummy;
|
||||||
char uptime_str[30];
|
|
||||||
|
|
||||||
if((uptimefile = fopen("/proc/uptime", "r")) == NULL)
|
fp = fopen("/proc/uptime", "r");
|
||||||
return 1;
|
if (!fp)
|
||||||
|
return;
|
||||||
|
|
||||||
fgets(uptime_str, 20, uptimefile);
|
fgets(buf, len, fp);
|
||||||
fclose(uptimefile);
|
fclose(fp);
|
||||||
|
|
||||||
sscanf(uptime_str, "%f %f", &num1, &num2);
|
sscanf(buf, "%f %f", &stamp, &dummy);
|
||||||
sprintf(uptime_str, "[ %.6f ]", num1);
|
return snprintf(buf, len, "[ %.6f ]", stamp);
|
||||||
|
#else
|
||||||
write(STDERR_FILENO, uptime_str, strlen(uptime_str));
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void printv(const char *fmt, va_list ap)
|
void printv(const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char buf[SCREEN_WIDTH];
|
char buf[SCREEN_WIDTH];
|
||||||
size_t len;
|
size_t len;
|
||||||
const char dots[] = " .....................................................................";
|
|
||||||
|
|
||||||
if (!fmt || log_is_silent())
|
if (!fmt || log_is_silent())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
len = vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
||||||
delline();
|
delline();
|
||||||
print_timestamp();
|
|
||||||
|
|
||||||
write(STDERR_FILENO, "\r", 1);
|
memset(buf, 0, sizeof(buf));
|
||||||
write(STDERR_FILENO, buf, len);
|
len = print_timestamp(buf, sizeof(buf));
|
||||||
write(STDERR_FILENO, dots, 60 - len); /* pad with dots. */
|
vsnprintf(&buf[len], sizeof(buf) - len, fmt, ap);
|
||||||
|
|
||||||
|
len = strlen(buf);
|
||||||
|
buf[len++] = ' ';
|
||||||
|
for (int i = (int)len; i < (SCREEN_WIDTH - 8); i++)
|
||||||
|
buf[i] = '.'; /* pad with dots. */
|
||||||
|
|
||||||
|
fprintf(stderr, "\r%s ", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(int action, const char *fmt, ...)
|
void print(int action, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
const char success[] = " \e[1m[ OK ]\e[0m\n";
|
const char success[] = "\e[1m[ OK ]\e[0m\n";
|
||||||
const char failure[] = " \e[7m[FAIL]\e[0m\n";
|
const char failure[] = "\e[7m[FAIL]\e[0m\n";
|
||||||
const char warning[] = " \e[7m[WARN]\e[0m\n";
|
const char warning[] = "\e[7m[WARN]\e[0m\n";
|
||||||
const char pending[] = " \e[1m[ \\/ ]\e[0m\n";
|
const char pending[] = "\e[1m[ \\/ ]\e[0m\n";
|
||||||
|
|
||||||
if (log_is_silent())
|
if (log_is_silent())
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user