iPXE
Data Structures | Functions | Variables
console_cmd.c File Reference

Console management commands. More...

#include <string.h>
#include <getopt.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/console.h>
#include <ipxe/image.h>
#include <ipxe/pixbuf.h>
#include <ipxe/ansiesc.h>
#include <ipxe/ansicol.h>
#include <usr/imgmgmt.h>

Go to the source code of this file.

Data Structures

struct  console_options
 "console" options More...
 
struct  colour_options
 "colour" options More...
 
struct  cpair_options
 "cpair" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int console_exec (int argc, char **argv)
 "console" command More...
 
static int colour_exec (int argc, char **argv)
 "colour" command More...
 
static int cpair_exec (int argc, char **argv)
 "cpair" command More...
 

Variables

static struct option_descriptor console_opts []
 "console" option list More...
 
static struct command_descriptor console_cmd
 "console" command descriptor More...
 
static struct option_descriptor colour_opts []
 "colour" option list More...
 
static struct command_descriptor colour_cmd
 "colour" command descriptor More...
 
static struct option_descriptor cpair_opts []
 "cpair" option list More...
 
static struct command_descriptor cpair_cmd
 "cpair" command descriptor More...
 
struct command console_commands [] __command
 Console management commands. More...
 

Detailed Description

Console management commands.

Definition in file console_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ console_exec()

static int console_exec ( int  argc,
char **  argv 
)
static

"console" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 86 of file console_cmd.c.

86  {
87  struct console_options opts;
88  struct image *image = NULL;
89  int rc;
90 
91  /* Parse options */
92  if ( ( rc = parse_options ( argc, argv, &console_cmd, &opts ) ) != 0 )
93  goto err_parse;
94 
95  /* Handle background picture, if applicable */
96  if ( opts.picture ) {
97 
98  /* Acquire image */
99  if ( ( rc = imgacquire ( opts.picture, 0, &image ) ) != 0 )
100  goto err_acquire;
101 
102  /* Convert to pixel buffer */
103  if ( ( rc = image_pixbuf ( image, &opts.config.pixbuf ) ) != 0){
104  printf ( "Could not use picture: %s\n",
105  strerror ( rc ) );
106  goto err_pixbuf;
107  }
108 
109  /* Apply image's width and height if none specified */
110  if ( ! opts.config.width )
111  opts.config.width = opts.config.pixbuf->width;
112  if ( ! opts.config.height )
113  opts.config.height = opts.config.pixbuf->height;
114  }
115 
116  /* Configure console */
117  if ( ( rc = console_configure ( &opts.config ) ) != 0 ) {
118  printf ( "Could not configure console: %s\n", strerror ( rc ) );
119  goto err_configure;
120  }
121 
122  /* Reapply default colour pair and clear screen */
124  printf ( CSI "2J" CSI "H" );
125 
126  err_configure:
127  pixbuf_put ( opts.config.pixbuf );
128  err_pixbuf:
129  /* Discard image unless --keep was specified */
130  if ( image && ( ! opts.keep ) )
132  err_acquire:
133  err_parse:
134  return rc;
135 }
int image_pixbuf(struct image *image, struct pixel_buffer **pixbuf)
Create pixel buffer from image.
Definition: pixbuf.c:97
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
An executable image.
Definition: image.h:24
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:89
#define CSI
Control Sequence Introducer.
Definition: ansiesc.h:95
"console" options
Definition: console_cmd.c:44
static struct command_descriptor console_cmd
"console" command descriptor
Definition: console_cmd.c:76
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int console_configure(struct console_configuration *config)
Configure console.
Definition: console.c:146
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:37
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:322
static union @438 opts
"cert<xxx>" option list
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition: imgmgmt.c:141

References ansicol_set_pair(), console_cmd, console_configure(), CPAIR_DEFAULT, CSI, image_pixbuf(), imgacquire(), NULL, opts, parse_options(), printf(), rc, strerror(), and unregister_image().

◆ colour_exec()

static int colour_exec ( int  argc,
char **  argv 
)
static

"colour" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 164 of file console_cmd.c.

164  {
165  struct colour_options opts;
166  unsigned int colour;
167  int rc;
168 
169  /* Initialise options */
170  memset ( &opts, 0, sizeof ( opts ) );
171  opts.basic = COLOUR_DEFAULT;
172  opts.rgb = ANSICOL_NO_RGB;
173 
174  /* Parse options */
175  if ( ( rc = reparse_options ( argc, argv, &colour_cmd, &opts ) ) != 0 )
176  return rc;
177 
178  /* Parse colour index */
179  if ( ( rc = parse_integer ( argv[optind], &colour ) ) != 0 )
180  return rc;
181 
182  /* Define colour */
183  if ( ( rc = ansicol_define ( colour, opts.basic, opts.rgb ) ) != 0 ) {
184  printf ( "Could not define colour: %s\n", strerror ( rc ) );
185  return rc;
186  }
187 
188  /* Reapply default colour pair, in case definition has changed */
190 
191  return 0;
192 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int optind
Current option index.
Definition: getopt.c:51
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:89
static struct command_descriptor colour_cmd
"colour" command descriptor
Definition: console_cmd.c:154
#define colour
Colour for debug messages.
Definition: acpi.c:39
int ansicol_define(unsigned int colour, unsigned int basic, uint32_t rgb)
Define ANSI colour.
Definition: ansicoldef.c:125
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition: parseopt.c:401
#define COLOUR_DEFAULT
Default colour (usually white foreground, black background)
Definition: ansicol.h:16
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ANSICOL_NO_RGB
RGB value for "not defined".
Definition: ansicol.h:29
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:37
static union @438 opts
"cert<xxx>" option list
"colour" options
Definition: console_cmd.c:138
void * memset(void *dest, int character, size_t len) __nonnull

References ansicol_define(), ANSICOL_NO_RGB, ansicol_set_pair(), colour, colour_cmd, COLOUR_DEFAULT, CPAIR_DEFAULT, memset(), optind, opts, parse_integer(), printf(), rc, reparse_options(), and strerror().

◆ cpair_exec()

static int cpair_exec ( int  argc,
char **  argv 
)
static

"cpair" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 221 of file console_cmd.c.

221  {
222  struct cpair_options opts;
223  unsigned int cpair;
224  int rc;
225 
226  /* Initialise options */
227  memset ( &opts, 0, sizeof ( opts ) );
228  opts.foreground = COLOUR_DEFAULT;
229  opts.background = COLOUR_DEFAULT;
230 
231  /* Parse options */
232  if ( ( rc = reparse_options ( argc, argv, &cpair_cmd, &opts ) ) != 0 )
233  return rc;
234 
235  /* Parse colour pair index */
236  if ( ( rc = parse_integer ( argv[optind], &cpair ) ) != 0 )
237  return rc;
238 
239  /* Define colour pair */
240  if ( ( rc = ansicol_define_pair ( cpair, opts.foreground,
241  opts.background ) ) != 0 ) {
242  printf ( "Could not define colour pair: %s\n",
243  strerror ( rc ) );
244  return rc;
245  }
246 
247  /* Reapply default colour pair, in case definition has changed */
249 
250  return 0;
251 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int optind
Current option index.
Definition: getopt.c:51
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:89
int ansicol_define_pair(unsigned int cpair, unsigned int foreground, unsigned int background)
Define ANSI colour pair.
Definition: ansicol.c:110
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition: parseopt.c:401
#define COLOUR_DEFAULT
Default colour (usually white foreground, black background)
Definition: ansicol.h:16
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:37
static struct command_descriptor cpair_cmd
"cpair" command descriptor
Definition: console_cmd.c:211
static union @438 opts
"cert<xxx>" option list
"cpair" options
Definition: console_cmd.c:195
void * memset(void *dest, int character, size_t len) __nonnull

References ansicol_define_pair(), ansicol_set_pair(), COLOUR_DEFAULT, cpair_cmd, CPAIR_DEFAULT, memset(), optind, opts, parse_integer(), printf(), rc, reparse_options(), and strerror().

Variable Documentation

◆ console_opts

struct option_descriptor console_opts[]
static
Initial value:
= {
struct console_options, config.width, parse_integer ),
struct console_options, config.height, parse_integer ),
struct console_options, config.left, parse_integer ),
OPTION_DESC ( "right", 'r', required_argument,
struct console_options, config.right, parse_integer ),
struct console_options, config.top, parse_integer ),
OPTION_DESC ( "bottom", 'b', required_argument,
struct console_options, config.bottom, parse_integer ),
OPTION_DESC ( "depth", 'd', required_argument,
struct console_options, config.depth, parse_integer ),
OPTION_DESC ( "picture", 'p', required_argument,
struct console_options, picture, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument,
struct console_options, keep, parse_flag ),
}
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
"console" options
Definition: console_cmd.c:44
int parse_string(char *text, char **value)
Parse string value.
Definition: parseopt.c:73
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:226
Option does not take an argument.
Definition: getopt.h:16
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18

"console" option list

Definition at line 54 of file console_cmd.c.

◆ console_cmd

struct command_descriptor console_cmd
static
Initial value:
=
static struct option_descriptor console_opts[]
"console" option list
Definition: console_cmd.c:54
"console" options
Definition: console_cmd.c:44
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

"console" command descriptor

Definition at line 76 of file console_cmd.c.

Referenced by console_exec().

◆ colour_opts

struct option_descriptor colour_opts[]
static
Initial value:
= {
OPTION_DESC ( "basic", 'b', required_argument,
struct colour_options, basic, parse_integer ),
struct colour_options, rgb, parse_integer ),
}
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
"colour" options
Definition: console_cmd.c:138

"colour" option list

Definition at line 146 of file console_cmd.c.

◆ colour_cmd

struct command_descriptor colour_cmd
static
Initial value:
=
COMMAND_DESC ( struct colour_options, colour_opts, 1, 1, "<colour>" )
static struct option_descriptor colour_opts[]
"colour" option list
Definition: console_cmd.c:146
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
"colour" options
Definition: console_cmd.c:138

"colour" command descriptor

Definition at line 154 of file console_cmd.c.

Referenced by colour_exec().

◆ cpair_opts

struct option_descriptor cpair_opts[]
static
Initial value:
= {
OPTION_DESC ( "foreground", 'f', required_argument,
OPTION_DESC ( "background", 'b', required_argument,
}
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
unsigned int background
Background colour.
Definition: console_cmd.c:199
unsigned int foreground
Foreground colour.
Definition: console_cmd.c:197
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
"cpair" options
Definition: console_cmd.c:195

"cpair" option list

Definition at line 203 of file console_cmd.c.

◆ cpair_cmd

struct command_descriptor cpair_cmd
static
Initial value:
=
COMMAND_DESC ( struct cpair_options, cpair_opts, 1, 1, "<cpair>" )
static struct option_descriptor cpair_opts[]
"cpair" option list
Definition: console_cmd.c:203
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
"cpair" options
Definition: console_cmd.c:195

"cpair" command descriptor

Definition at line 211 of file console_cmd.c.

Referenced by cpair_exec().

◆ __command

struct command console_commands [] __command
Initial value:
= {
{
.name = "console",
.exec = console_exec,
},
{
.name = "colour",
.exec = colour_exec,
},
{
.name = "cpair",
.exec = cpair_exec,
},
}
static int console_exec(int argc, char **argv)
"console" command
Definition: console_cmd.c:86
static int cpair_exec(int argc, char **argv)
"cpair" command
Definition: console_cmd.c:221
static int colour_exec(int argc, char **argv)
"colour" command
Definition: console_cmd.c:164

Console management commands.

Definition at line 254 of file console_cmd.c.