iPXE
message.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 FILE_SECBOOT ( PERMITTED );
26 
27 /** @file
28  *
29  * Message printing
30  *
31  */
32 
33 #include <stddef.h>
34 #include <stdint.h>
35 #include <stdarg.h>
36 #include <unistd.h>
37 #include <ipxe/ansicol.h>
38 #include <ipxe/message.h>
39 
40 /**
41  * Print message centred on specified row
42  *
43  * @v row Row
44  * @v fmt printf() format string
45  * @v args printf() argument list
46  */
47 static void vmsg ( unsigned int row, const char *fmt, va_list args ) {
48  char buf[COLS];
49  size_t len;
50 
51  len = vsnprintf ( buf, sizeof ( buf ), fmt, args );
52  mvprintw ( row, ( ( COLS - len ) / 2 ), "%s", buf );
53 }
54 
55 /**
56  * Print message centred on specified row
57  *
58  * @v row Row
59  * @v fmt printf() format string
60  * @v .. printf() arguments
61  */
62 void msg ( unsigned int row, const char *fmt, ... ) {
63  va_list args;
64 
65  va_start ( args, fmt );
66  vmsg ( row, fmt, args );
67  va_end ( args );
68 }
69 
70 /**
71  * Clear message on specified row
72  *
73  * @v row Row
74  */
75 void clearmsg ( unsigned int row ) {
76  move ( row, 0 );
77  clrtoeol();
78 }
79 
80 /**
81  * Show alert message
82  *
83  * @v row Row
84  * @v fmt printf() format string
85  * @v args printf() argument list
86  */
87 static void valert ( unsigned int row, const char *fmt, va_list args ) {
88 
89  clearmsg ( row );
91  vmsg ( row, fmt, args );
92  sleep ( 2 );
94  clearmsg ( row );
95 }
96 
97 /**
98  * Show alert message
99  *
100  * @v row Row
101  * @v fmt printf() format string
102  * @v ... printf() arguments
103  */
104 void alert ( unsigned int row, const char *fmt, ... ) {
105  va_list args;
106 
107  va_start ( args, fmt );
108  valert ( row, fmt, args );
109  va_end ( args );
110 }
#define va_end(ap)
Definition: stdarg.h:10
static void valert(unsigned int row, const char *fmt, va_list args)
Show alert message.
Definition: message.c:87
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:62
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void clearmsg(unsigned int row)
Clear message on specified row.
Definition: message.c:75
#define mvprintw(y, x, fmt,...)
Definition: curses.h:649
void alert(unsigned int row, const char *fmt,...)
Show alert message.
Definition: message.c:104
Message printing.
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:41
ring len
Length.
Definition: dwmac.h:231
#define CPAIR_ALERT
Error text.
Definition: ansicol.h:53
#define COLS
Definition: vga.h:27
FILE_SECBOOT(PERMITTED)
static int clrtoeol(void)
Definition: curses.h:554
static void vmsg(unsigned int row, const char *fmt, va_list args)
Print message centred on specified row.
Definition: message.c:47
__builtin_va_list va_list
Definition: stdarg.h:7
static int move(int y, int x)
Definition: curses.h:594
int ssize_t const char * fmt
Definition: vsprintf.h:73
#define color_set(cpno, opts)
Definition: curses.h:241
#define va_start(ap, last)
Definition: stdarg.h:8
unsigned int sleep(unsigned int secs)
Sleep (interruptibly) for a fixed number of seconds.
Definition: timer.c:134
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
ANSI colours.
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition: vsprintf.c:352