iPXE
Data Structures | Functions
lineconsole.h File Reference

Line-based console. More...

#include <stdint.h>
#include <ipxe/ansiesc.h>

Go to the source code of this file.

Data Structures

struct  line_console
 A line-based console. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
size_t line_putchar (struct line_console *line, int character)
 Print a character to a line-based console.

Detailed Description

Line-based console.

Definition in file lineconsole.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
size_t line_putchar ( struct line_console line,
int  character 
)

Print a character to a line-based console.

Parameters:
characterCharacter to be printed
Return values:
printPrint line

Definition at line 43 of file lineconsole.c.

References ansiesc_process(), line_console::buffer, line_console::ctx, line_console::index, and line_console::len.

Referenced by syslog_putchar(), syslogs_putchar(), and vmconsole_putchar().

                                                                 {

        /* Strip ANSI escape sequences */
        character = ansiesc_process ( &line->ctx, character );
        if ( character < 0 )
                return 0;

        /* Handle backspace characters */
        if ( character == '\b' ) {
                if ( line->index )
                        line->index--;
                return 0;
        }

        /* Ignore carriage return */
        if ( character == '\r' )
                return 0;

        /* Treat newline as a terminator */
        if ( character == '\n' )
                character = 0;

        /* Add character to buffer */
        line->buffer[line->index++] = character;

        /* Do nothing more unless we reach end-of-line (or end-of-buffer) */
        if ( ( character != 0 ) &&
             ( line->index < ( line->len - 1 /* NUL */ ) ) ) {
                return 0;
        }

        /* Reset to start of buffer */
        line->index = 0;

        return 1;
}