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 
26 /** @file
27  *
28  * Message printing
29  *
30  */
31 
32 #include <stddef.h>
33 #include <stdint.h>
34 #include <stdarg.h>
35 #include <unistd.h>
36 #include <ipxe/ansicol.h>
37 #include <ipxe/message.h>
38 
39 /**
40  * Print message centred on specified row
41  *
42  * @v row Row
43  * @v fmt printf() format string
44  * @v args printf() argument list
45  */
46 static void vmsg ( unsigned int row, const char *fmt, va_list args ) {
47  char buf[COLS];
48  size_t len;
49 
50  len = vsnprintf ( buf, sizeof ( buf ), fmt, args );
51  mvprintw ( row, ( ( COLS - len ) / 2 ), "%s", buf );
52 }
53 
54 /**
55  * Print message centred on specified row
56  *
57  * @v row Row
58  * @v fmt printf() format string
59  * @v .. printf() arguments
60  */
61 void msg ( unsigned int row, const char *fmt, ... ) {
62  va_list args;
63 
64  va_start ( args, fmt );
65  vmsg ( row, fmt, args );
66  va_end ( args );
67 }
68 
69 /**
70  * Clear message on specified row
71  *
72  * @v row Row
73  */
74 void clearmsg ( unsigned int row ) {
75  move ( row, 0 );
76  clrtoeol();
77 }
78 
79 /**
80  * Show alert message
81  *
82  * @v row Row
83  * @v fmt printf() format string
84  * @v args printf() argument list
85  */
86 static void valert ( unsigned int row, const char *fmt, va_list args ) {
87 
88  clearmsg ( row );
90  vmsg ( row, fmt, args );
91  sleep ( 2 );
93  clearmsg ( row );
94 }
95 
96 /**
97  * Show alert message
98  *
99  * @v row Row
100  * @v fmt printf() format string
101  * @v ... printf() arguments
102  */
103 void alert ( unsigned int row, const char *fmt, ... ) {
104  va_list args;
105 
106  va_start ( args, fmt );
107  valert ( row, fmt, args );
108  va_end ( args );
109 }
#define va_end(ap)
Definition: stdarg.h:9
static void valert(unsigned int row, const char *fmt, va_list args)
Show alert message.
Definition: message.c:86
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:61
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void clearmsg(unsigned int row)
Clear message on specified row.
Definition: message.c:74
#define mvprintw(y, x, fmt,...)
Definition: curses.h:648
void alert(unsigned int row, const char *fmt,...)
Show alert message.
Definition: message.c:103
Message printing.
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
#define CPAIR_ALERT
Error text.
Definition: ansicol.h:52
#define COLS
Definition: vga.h:27
static int clrtoeol(void)
Definition: curses.h:553
static void vmsg(unsigned int row, const char *fmt, va_list args)
Print message centred on specified row.
Definition: message.c:46
__builtin_va_list va_list
Definition: stdarg.h:6
static int move(int y, int x)
Definition: curses.h:593
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define color_set(cpno, opts)
Definition: curses.h:240
#define va_start(ap, last)
Definition: stdarg.h:7
uint32_t len
Length.
Definition: ena.h:14
unsigned int sleep(unsigned int secs)
Sleep (interruptibly) for a fixed number of seconds.
Definition: timer.c:133
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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:351