ansi_screen.c File Reference

#include <stdio.h>
#include <curses.h>
#include <console.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static void ansiscr_reset (struct _curses_screen *scr) __nonnull
static void ansiscr_movetoyx (struct _curses_screen *scr, unsigned int y, unsigned int x) __nonnull
static void ansiscr_putc (struct _curses_screen *scr, chtype c) __nonnull
static int ansiscr_getc (struct _curses_screen *scr __unused)
static bool ansiscr_peek (struct _curses_screen *scr __unused)

Variables

unsigned short _COLS = 80
unsigned short _LINES = 24
SCREEN _ansi_screen


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static void ansiscr_reset ( struct _curses_screen scr  )  [static]

Definition at line 15 of file ansi_screen.c.

References _curses_screen::attrs, _curses_screen::curs_x, _curses_screen::curs_y, and printf().

00015                                                          {
00016         /* Reset terminal attributes and clear screen */
00017         scr->attrs = 0;
00018         scr->curs_x = 0;
00019         scr->curs_y = 0;
00020         printf ( "\033[0m" );
00021 }

static void ansiscr_movetoyx ( struct _curses_screen scr,
unsigned int  y,
unsigned int  x 
) [static]

Definition at line 23 of file ansi_screen.c.

References _curses_screen::curs_x, _curses_screen::curs_y, and printf().

00024                                                                 {
00025         if ( ( x != scr->curs_x ) || ( y != scr->curs_y ) ) {
00026                 /* ANSI escape sequence to update cursor position */
00027                 printf ( "\033[%d;%dH", ( y + 1 ), ( x + 1 ) );
00028                 scr->curs_x = x;
00029                 scr->curs_y = y;
00030         }
00031 }

static void ansiscr_putc ( struct _curses_screen scr,
chtype  c 
) [static]

Definition at line 33 of file ansi_screen.c.

References _COLS, A_ATTRIBUTES, A_BOLD, A_CHARTEXT, A_COLOR, _curses_screen::attrs, _curses_screen::curs_x, _curses_screen::curs_y, pair_content(), PAIR_NUMBER, printf(), and putchar().

00033                                                                   {
00034         unsigned int character = ( c & A_CHARTEXT );
00035         attr_t attrs = ( c & ( A_ATTRIBUTES | A_COLOR ) );
00036         int bold = ( attrs & A_BOLD );
00037         attr_t cpair = PAIR_NUMBER ( attrs );
00038         short fcol;
00039         short bcol;
00040 
00041         /* Update attributes if changed */
00042         if ( attrs != scr->attrs ) {
00043                 scr->attrs = attrs;
00044                 pair_content ( cpair, &fcol, &bcol );
00045                 /* ANSI escape sequence to update character attributes */
00046                 printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
00047         }
00048 
00049         /* Print the actual character */
00050         putchar ( character );
00051 
00052         /* Update expected cursor position */
00053         if ( ++(scr->curs_x) == _COLS ) {
00054                 scr->curs_x = 0;
00055                 ++scr->curs_y;
00056         }
00057 }

static int ansiscr_getc ( struct _curses_screen *scr  __unused  )  [static]

Definition at line 59 of file ansi_screen.c.

References getchar().

00059                                                                 {
00060         return getchar();
00061 }

static bool ansiscr_peek ( struct _curses_screen *scr  __unused  )  [static]

Definition at line 63 of file ansi_screen.c.

References iskey().

00063                                                                  {
00064         return iskey();
00065 }


Variable Documentation

unsigned short _COLS = 80

Definition at line 12 of file ansi_screen.c.

Referenced by ansiscr_putc().

unsigned short _LINES = 24

Definition at line 13 of file ansi_screen.c.

Initial value:

 {
        .init           = ansiscr_reset,
        .exit           = ansiscr_reset,
        .movetoyx       = ansiscr_movetoyx,
        .putc           = ansiscr_putc,
        .getc           = ansiscr_getc,
        .peek           = ansiscr_peek,
}

Definition at line 67 of file ansi_screen.c.


Generated on Tue Apr 6 20:01:46 2010 for gPXE by  doxygen 1.5.7.1