iPXE
Functions
lineconsole.c File Reference

Line-based console. More...

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

Go to the source code of this file.

Functions

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

Detailed Description

Line-based console.

Definition in file lineconsole.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ line_putchar()

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 44 of file lineconsole.c.

44  {
45 
46  /* Strip ANSI escape sequences */
47  character = ansiesc_process ( &line->ctx, character );
48  if ( character < 0 )
49  return 0;
50 
51  /* Handle backspace characters */
52  if ( character == '\b' ) {
53  if ( line->index )
54  line->index--;
55  return 0;
56  }
57 
58  /* Ignore carriage return */
59  if ( character == '\r' )
60  return 0;
61 
62  /* Treat newline as a terminator */
63  if ( character == '\n' )
64  character = 0;
65 
66  /* Add character to buffer */
67  line->buffer[line->index++] = character;
68 
69  /* Do nothing more unless we reach end-of-line (or end-of-buffer) */
70  if ( ( character != 0 ) &&
71  ( line->index < ( line->len - 1 /* NUL */ ) ) ) {
72  return 0;
73  }
74 
75  /* Reset to start of buffer */
76  line->index = 0;
77 
78  return 1;
79 }
size_t index
Current index within buffer.
Definition: lineconsole.h:24
size_t len
Length of buffer.
Definition: lineconsole.h:30
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition: ansiesc.c:75
struct ansiesc_context ctx
ANSI escape sequence context.
Definition: lineconsole.h:32
char * buffer
Data buffer.
Definition: lineconsole.h:22

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