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
static int colour_exec (int argc, char **argv)
 "colour" command
static int cpair_exec (int argc, char **argv)
 "cpair" command

Variables

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

Detailed Description

Console management commands.

Definition in file console_cmd.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

References ansicol_set_pair(), console_options::config, console_configure(), CPAIR_DEFAULT, CSI, pixel_buffer::height, console_configuration::height, image_pixbuf(), imgacquire(), console_options::keep, NULL, parse_options(), console_options::picture, console_configuration::pixbuf, printf(), rc, strerror(), unregister_image(), pixel_buffer::width, and console_configuration::width.

                                                  {
        struct console_options opts;
        struct image *image = NULL;
        int rc;

        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &console_cmd, &opts ) ) != 0 )
                goto err_parse;

        /* Handle background picture, if applicable */
        if ( opts.picture ) {

                /* Acquire image */
                if ( ( rc = imgacquire ( opts.picture, 0, &image ) ) != 0 )
                        goto err_acquire;

                /* Convert to pixel buffer */
                if ( ( rc = image_pixbuf ( image, &opts.config.pixbuf ) ) != 0){
                        printf ( "Could not use picture: %s\n",
                                 strerror ( rc ) );
                        goto err_pixbuf;
                }

                /* Apply image's width and height if none specified */
                if ( ! opts.config.width )
                        opts.config.width = opts.config.pixbuf->width;
                if ( ! opts.config.height )
                        opts.config.height = opts.config.pixbuf->height;
        }

        /* Configure console */
        if ( ( rc = console_configure ( &opts.config ) ) != 0 ) {
                printf ( "Could not configure console: %s\n", strerror ( rc ) );
                goto err_configure;
        }

        /* Reapply default colour pair and clear screen */
        ansicol_set_pair ( CPAIR_DEFAULT );
        printf ( CSI "2J" CSI "H" );

 err_configure:
        pixbuf_put ( opts.config.pixbuf );
 err_pixbuf:
        /* Discard image unless --keep was specified */
        if ( image && ( ! opts.keep ) )
                unregister_image ( image );
 err_acquire:
 err_parse:
        return rc;
}
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.

References ansicol_define(), ANSICOL_NO_RGB, ansicol_set_pair(), colour_options::basic, colour, COLOUR_DEFAULT, CPAIR_DEFAULT, memset(), optind, parse_integer(), printf(), rc, reparse_options(), colour_options::rgb, and strerror().

                                                 {
        struct colour_options opts;
        unsigned int colour;
        int rc;

        /* Initialise options */
        memset ( &opts, 0, sizeof ( opts ) );
        opts.basic = COLOUR_DEFAULT;
        opts.rgb = ANSICOL_NO_RGB;

        /* Parse options */
        if ( ( rc = reparse_options ( argc, argv, &colour_cmd, &opts ) ) != 0 )
                return rc;

        /* Parse colour index */
        if ( ( rc = parse_integer ( argv[optind], &colour ) ) != 0 )
                return rc;

        /* Define colour */
        if ( ( rc = ansicol_define ( colour, opts.basic, opts.rgb ) ) != 0 ) {
                printf ( "Could not define colour: %s\n", strerror ( rc ) );
                return rc;
        }

        /* Reapply default colour pair, in case definition has changed */
        ansicol_set_pair ( CPAIR_DEFAULT );

        return 0;
}
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.

References ansicol_define_pair(), ansicol_set_pair(), cpair_options::background, COLOUR_DEFAULT, CPAIR_DEFAULT, cpair_options::foreground, memset(), optind, parse_integer(), printf(), rc, reparse_options(), and strerror().

                                                {
        struct cpair_options opts;
        unsigned int cpair;
        int rc;

        /* Initialise options */
        memset ( &opts, 0, sizeof ( opts ) );
        opts.foreground = COLOUR_DEFAULT;
        opts.background = COLOUR_DEFAULT;

        /* Parse options */
        if ( ( rc = reparse_options ( argc, argv, &cpair_cmd, &opts ) ) != 0 )
                return rc;

        /* Parse colour pair index */
        if ( ( rc = parse_integer ( argv[optind], &cpair ) ) != 0 )
                return rc;

        /* Define colour pair */
        if ( ( rc = ansicol_define_pair ( cpair, opts.foreground,
                                          opts.background ) ) != 0 ) {
                printf ( "Could not define colour pair: %s\n",
                         strerror ( rc ) );
                return rc;
        }

        /* Reapply default colour pair, in case definition has changed */
        ansicol_set_pair ( CPAIR_DEFAULT );

        return 0;
}

Variable Documentation

struct option_descriptor console_opts[] [static]
Initial value:
 {
        OPTION_DESC ( "x", 'x', required_argument,
                      struct console_options, config.width, parse_integer ),
        OPTION_DESC ( "y", 'y', required_argument,
                      struct console_options, config.height, parse_integer ),
        OPTION_DESC ( "left", 'l', required_argument,
                      struct console_options, config.left, parse_integer ),
        OPTION_DESC ( "right", 'r', required_argument,
                      struct console_options, config.right, parse_integer ),
        OPTION_DESC ( "top", 't', required_argument,
                      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 ),
}

"console" option list

Definition at line 54 of file console_cmd.c.

Initial value:

"console" command descriptor

Definition at line 76 of file console_cmd.c.

struct option_descriptor colour_opts[] [static]
Initial value:
 {
        OPTION_DESC ( "basic", 'b', required_argument,
                      struct colour_options, basic, parse_integer ),
        OPTION_DESC ( "rgb", 'r', required_argument,
                      struct colour_options, rgb, parse_integer ),
}

"colour" option list

Definition at line 146 of file console_cmd.c.

struct command_descriptor colour_cmd [static]
Initial value:
        COMMAND_DESC ( struct colour_options, colour_opts, 1, 1, "<colour>" )

"colour" command descriptor

Definition at line 154 of file console_cmd.c.

struct option_descriptor cpair_opts[] [static]
Initial value:

"cpair" option list

Definition at line 203 of file console_cmd.c.

struct command_descriptor cpair_cmd [static]
Initial value:
        COMMAND_DESC ( struct cpair_options, cpair_opts, 1, 1, "<cpair>" )

"cpair" command descriptor

Definition at line 211 of file console_cmd.c.

struct command console_commands [] __command
Initial value:
 {
        {
                .name = "console",
                .exec = console_exec,
        },
        {
                .name = "colour",
                .exec = colour_exec,
        },
        {
                .name = "cpair",
                .exec = cpair_exec,
        },
}

Console management commands.

Definition at line 254 of file console_cmd.c.