diff options
author | Pierre-Alexandre Meyer <pierre@mouraf.org> | 2009-09-04 16:59:53 -0700 |
---|---|---|
committer | Pierre-Alexandre Meyer <pierre@mouraf.org> | 2009-09-04 16:59:53 -0700 |
commit | 3f86e5ec0954aa2b2da60f007705cbe996820fc4 (patch) | |
tree | 8ddad87b56195539d3bd7a59a1861251b6db477e /com32 | |
parent | 4873366ee31786f10381427c5522543a82a9e2ab (diff) | |
parent | 1c50caaf9086cedc0af481094045f32a8f63e0a1 (diff) | |
download | syslinux-3f86e5ec0954aa2b2da60f007705cbe996820fc4.tar.gz syslinux-3f86e5ec0954aa2b2da60f007705cbe996820fc4.tar.xz syslinux-3f86e5ec0954aa2b2da60f007705cbe996820fc4.zip |
Merge commit 'origin/libansi' into cmenu-video
Diffstat (limited to 'com32')
-rw-r--r-- | com32/cmenu/libmenu/com32io.c | 98 | ||||
-rw-r--r-- | com32/cmenu/libmenu/com32io.h | 62 | ||||
-rw-r--r-- | com32/hdt/hdt-cli.c | 1 | ||||
-rw-r--r-- | com32/hdt/hdt-common.c | 1 | ||||
-rw-r--r-- | com32/hdt/hdt-common.h | 1 | ||||
-rw-r--r-- | com32/hdt/lib-ansi.h | 44 | ||||
-rw-r--r-- | com32/include/libansi.h | 106 | ||||
-rw-r--r-- | com32/lib/Makefile | 2 | ||||
-rw-r--r-- | com32/lib/sys/libansi.c (renamed from com32/hdt/lib-ansi.c) | 121 |
9 files changed, 222 insertions, 214 deletions
diff --git a/com32/cmenu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c index 3c4f9219..b910959f 100644 --- a/com32/cmenu/libmenu/com32io.c +++ b/com32/cmenu/libmenu/com32io.c @@ -18,104 +18,6 @@ com32sys_t inreg, outreg; // Global register sets for use -/** - * cprint_vga2ansi - given a VGA attribute, print a character - * @chr: character to print - * @attr: vga attribute - * - * Convert the VGA attribute @attr to an ANSI escape sequence and - * print it. - **/ -static void cprint_vga2ansi(const char chr, const char attr) -{ - static const char ansi_char[8] = "04261537"; - static uint8_t last_attr = 0x300; - char buf[16], *p; - - if (attr != last_attr) { - p = buf; - *p++ = '\033'; - *p++ = '['; - - if (last_attr & ~attr & 0x88) { - *p++ = '0'; - *p++ = ';'; - /* Reset last_attr to unknown to handle - * background/foreground attributes correctly */ - last_attr = 0x300; - } - if (attr & 0x08) { - *p++ = '1'; - *p++ = ';'; - } - if (attr & 0x80) { - *p++ = '4'; - *p++ = ';'; - } - if ((attr ^ last_attr) & 0x07) { - *p++ = '3'; - *p++ = ansi_char[attr & 7]; - *p++ = ';'; - } - if ((attr ^ last_attr) & 0x70) { - *p++ = '4'; - *p++ = ansi_char[(attr >> 4) & 7]; - *p++ = ';'; - } - p[-1] = 'm'; /* We'll have generated at least one semicolon */ - p[0] = '\0'; - - last_attr = attr; - - fputs(buf, stdout); - } - - putchar(chr); -} - -/** - * cprint - given a VGA attribute, print a single character at cursor - * @chr: character to print - * @attr: VGA attribute - * @times: number of times to print @chr - * - * Note: @attr is a VGA attribute. - **/ -void cprint(const char chr, const char attr, unsigned int times) -{ - while (times--) - cprint_vga2ansi(chr, attr); -} - -/** - * csprint - given a VGA attribute, print a NULL-terminated string - * @str: string to print - * @attr: VGA attribute - **/ -void csprint(const char *str, const char attr) -{ - while (*str) { - cprint(*str, attr, 1); - str++; - } -} - -/** - * clearwindow - fill a given a region on the screen - * @top, @left, @bot, @right: coordinates to fill - * @fillchar: character to use to fill the region - * @fillattr: character attribute (VGA) - **/ -void clearwindow(const char top, const char left, const char bot, - const char right, const char fillchar, const char fillattr) -{ - char x; - for (x = top; x < bot + 1; x++) { - gotoxy(x, left); - cprint(fillchar, fillattr, right - left + 1); - } -} - void getpos(char *row, char *col, char page) { REG_AH(inreg) = 0x03; diff --git a/com32/cmenu/libmenu/com32io.h b/com32/cmenu/libmenu/com32io.h index 91324d77..6a1b670b 100644 --- a/com32/cmenu/libmenu/com32io.h +++ b/com32/cmenu/libmenu/com32io.h @@ -15,59 +15,14 @@ #include <com32.h> #include <stdio.h> +#include <libansi.h> #ifndef NULL #define NULL ((void *)0) #endif -#define CSI "\e[" - -static inline void beep(void) -{ - fputs("\007", stdout); -} - /* BIOS Assisted output routines */ -// Print a C str (NUL-terminated) respecting the left edge of window -// i.e. \n in str will move cursor to column left -// Print a C str (NUL-terminated) - -void csprint(const char *, const char); - -//static inline void cswprint(const char *str, const char attr) -//{ -// csprint(str, attr); -//} - -void cprint(const char, const char, unsigned int); - -static inline void putch(const char x, char attr) -{ - cprint(x, attr, 1); -} - -void clearwindow(const char, const char, const char, const char, - const char, const char); - -/* - * cls - clear and initialize the entire screen - * - * Note: when initializing xterm, one has to specify that - * G1 points to the alternate character set (this is not true - * by default). Without the initial printf "\033)0", line drawing - * characters won't be displayed. - */ -static inline void cls(void) -{ - fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout); -} - -static inline void gotoxy(const char row, const char col) -{ - printf(CSI "%d;%dH", row + 1, col + 1); -} - void getpos(char *row, char *col, char page); char inputc(char *scancode); // Return ASCII char by val, and scancode by reference @@ -78,16 +33,6 @@ void getcursorshape(char *start, char *end); // Get shape for current page // Get char displayed at current position in specified page unsigned char getcharat(char page); -static inline void cursoroff(void) -{ /* Turns off cursor */ - setcursorshape(32, 33); -} - -static inline void cursoron(void) -{ /* Turns on cursor */ - setcursorshape(6, 7); -} - static inline unsigned char readbiosb(unsigned int ofs) { return *((unsigned char *)MK_PTR(0, ofs)); @@ -100,11 +45,6 @@ static inline char getshiftflags(void) void scrollupwindow(char top, char left, char bot, char right, char attr, char numlines); //Scroll up given window -static inline void scrollup(void) //Scroll up display screen by one line -{ - printf(CSI "S"); -} - void setvideomode(char mode); // Set the video mode. static inline char getvideomode(void) // Get the current video mode diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 0d38fb2b..2b11c98a 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -32,7 +32,6 @@ #include <getkey.h> #include "hdt-cli.h" #include "hdt-common.h" -#include "lib-ansi.h" struct cli_mode_descr *list_modes[] = { &hdt_mode, diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index 80305a3e..5afb3093 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -33,7 +33,6 @@ #include "syslinux/config.h" #include "../lib/sys/vesa/vesa.h" #include "hdt-common.h" -#include "lib-ansi.h" #include <disk/util.h> /* ISOlinux requires a 8.3 format */ diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h index 2b67f9ca..8e768f53 100644 --- a/com32/hdt/hdt-common.h +++ b/com32/hdt/hdt-common.h @@ -39,6 +39,7 @@ #include "hdt-ata.h" #include "../lib/sys/vesa/vesa.h" #include <vpd/vpd.h> +#include <libansi.h> /* Declare a variable or data structure as unused. */ #define __unused __attribute__ (( unused )) diff --git a/com32/hdt/lib-ansi.h b/com32/hdt/lib-ansi.h deleted file mode 100644 index 0b0d0d18..00000000 --- a/com32/hdt/lib-ansi.h +++ /dev/null @@ -1,44 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2009 Erwan Velu - All Rights Reserved - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * ----------------------------------------------------------------------- - */ - -#ifndef DEFINE_LIB_ANSI_H -#define DEFINE_LIB_ANSI_H -void display_cursor(bool status); -void clear_end_of_line(); -void move_cursor_left(int count); -void move_cursor_right(int count); -void clear_line(); -void clear_beginning_of_line(); -void move_cursor_to_column(int count); -void move_cursor_to_next_line(); -void disable_utf8(); -void set_g1_special_char(); -void set_us_g0_charset(); -void clear_entire_screen(); -void set_cursor_blink(bool status); -#endif diff --git a/com32/include/libansi.h b/com32/include/libansi.h new file mode 100644 index 00000000..f2ec4d55 --- /dev/null +++ b/com32/include/libansi.h @@ -0,0 +1,106 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2009 Erwan Velu - All Rights Reserved + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * ----------------------------------------------------------------------- + */ + +#ifndef DEFINE_LIB_ANSI_H +#define DEFINE_LIB_ANSI_H + +#define CSI "\e[" + +void display_cursor(bool status); +void clear_end_of_line(void); +void move_cursor_left(int count); +void move_cursor_right(int count); +void clear_line(void); +void clear_beginning_of_line(void); +void move_cursor_to_column(int count); +void move_cursor_to_next_line(void); +void disable_utf8(void); +void set_g1_special_char(void); +void set_us_g0_charset(void); +void clear_entire_screen(void); +void set_cursor_blink(bool status); +void move_cursor_to_next_line(void); +void disable_utf8(void); +void set_g1_special_char(void); +void set_us_g0_charset(void); +void clear_entire_screen(void); +void clearwindow(const char top, const char left, const char bot, + const char right, const char fillchar, const char fillattr); + +static inline void beep(void) +{ + fputs("\007", stdout); +} + +/* Print a string */ +void csprint(const char *, const char); + +/* Print one character, one or more times */ +void cprint(const char, const char, unsigned int); + +/* Print one character, once */ +static inline void putch(const char x, char attr) +{ + cprint(x, attr, 1); +} + +/* + * cls - clear and initialize the entire screen + * + * Note: when initializing xterm, one has to specify that + * G1 points to the alternate character set (this is not true + * by default). Without the initial printf "\033)0", line drawing + * characters won't be displayed. + */ +static inline void cls(void) +{ + fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout); +} + +static inline void cursoroff(void) +{ + display_cursor(false); +} + +static inline void cursoron(void) +{ + display_cursor(true); +} + +/* Scroll up display screen by one line */ +static inline void scrollup(void) +{ + printf(CSI "S"); +} + +static inline void gotoxy(const char row, const char col) +{ + printf(CSI "%d;%dH", row + 1, col + 1); +} + +#endif diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 2bcffe80..3a9eafd6 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -53,6 +53,8 @@ LIBOBJS = \ \ sys/ansi.o \ \ + sys/libansi.o \ + \ sys/ansicon_write.o sys/ansiserial_write.o \ \ sys/vesacon_write.o sys/vesaserial_write.o \ diff --git a/com32/hdt/lib-ansi.c b/com32/lib/sys/libansi.c index 411dba80..0f348426 100644 --- a/com32/hdt/lib-ansi.c +++ b/com32/lib/sys/libansi.c @@ -33,31 +33,34 @@ #include <stdio.h> #include <string.h> #include <stdbool.h> +#include <stdint.h> + +#include "libansi.h" void display_cursor(bool status) { if (status == true) { - fputs("\033[?25h", stdout); + fputs(CSI "?25h", stdout); } else { - fputs("\033[?25l", stdout); + fputs(CSI "?25l", stdout); } } void clear_end_of_line() { - fputs("\033[0K", stdout); + fputs(CSI "0K", stdout); } void move_cursor_left(int count) { char buffer[10]; memset(buffer,0,sizeof(buffer)); - sprintf(buffer,"\033[%dD",count); + sprintf(buffer,CSI "%dD",count); fputs(buffer, stdout); } void move_cursor_right(int count) { char buffer[10]; memset(buffer,0,sizeof(buffer)); - sprintf(buffer,"\033[%dC",count); + sprintf(buffer, CSI "%dC", count); fputs(buffer, stdout); } @@ -69,17 +72,17 @@ void set_cursor_blink(bool status) { } void clear_line() { - fputs("\033[2K", stdout); + fputs(CSI "2K", stdout); } void clear_beginning_of_line() { - fputs("\033[1K", stdout); + fputs(CSI "1K", stdout); } void move_cursor_to_column(int count) { char buffer[10]; memset(buffer,0,sizeof(buffer)); - sprintf(buffer,"\033[%dG",count); + sprintf(buffer, CSI "%dG", count); fputs(buffer, stdout); } @@ -100,5 +103,105 @@ void set_us_g0_charset() { } void clear_entire_screen() { - fputs("\033[2J", stdout); + fputs(CSI "2J", stdout); } + +/** + * cprint_vga2ansi - given a VGA attribute, print a character + * @chr: character to print + * @attr: vga attribute + * + * Convert the VGA attribute @attr to an ANSI escape sequence and + * print it. + **/ +static void cprint_vga2ansi(const char chr, const char attr) +{ + static const char ansi_char[8] = "04261537"; + static uint16_t last_attr = 0x300; + char buf[16], *p; + + if (attr != last_attr) { + p = buf; + *p++ = '\033'; + *p++ = '['; + + if (last_attr & ~attr & 0x88) { + *p++ = '0'; + *p++ = ';'; + /* Reset last_attr to unknown to handle + * background/foreground attributes correctly */ + last_attr = 0x300; + } + if (attr & 0x08) { + *p++ = '1'; + *p++ = ';'; + } + if (attr & 0x80) { + *p++ = '4'; + *p++ = ';'; + } + if ((attr ^ last_attr) & 0x07) { + *p++ = '3'; + *p++ = ansi_char[attr & 7]; + *p++ = ';'; + } + if ((attr ^ last_attr) & 0x70) { + *p++ = '4'; + *p++ = ansi_char[(attr >> 4) & 7]; + *p++ = ';'; + } + p[-1] = 'm'; /* We'll have generated at least one semicolon */ + p[0] = '\0'; + + last_attr = attr; + + fputs(buf, stdout); + } + + putchar(chr); +} + +/** + * cprint - given a VGA attribute, print a single character at cursor + * @chr: character to print + * @attr: VGA attribute + * @times: number of times to print @chr + * + * Note: @attr is a VGA attribute. + **/ +void cprint(const char chr, const char attr, unsigned int times) +{ + while (times--) + cprint_vga2ansi(chr, attr); +} + +/** + * csprint - given a VGA attribute, print a NULL-terminated string + * @str: string to print + * @attr: VGA attribute + **/ +void csprint(const char *str, const char attr) +{ + while (*str) { + cprint(*str, attr, 1); + str++; + } +} + +/** + * clearwindow - fill a given a region on the screen + * @top, @left, @bot, @right: coordinates to fill + * @fillchar: character to use to fill the region + * @fillattr: character attribute (VGA) + **/ +void clearwindow(const char top, const char left, const char bot, + const char right, const char fillchar, const char fillattr) +{ + char x; + for (x = top; x < bot + 1; x++) { + gotoxy(x, left); + cprint(fillchar, fillattr, right - left + 1); + } +} + + |