hdt-cli-cpu.o hdt-cli-pxe.o hdt-cli-kernel.o \
hdt-cli-syslinux.o hdt-cli-vesa.o\
hdt-menu-pxe.o hdt-menu-summary.o hdt-menu-vesa.o\
+ lib-ansi.o\
$(LIBS)
@$(LD) $(LDFLAGS) -o $@ $^
#include <getkey.h>
#include "hdt-cli.h"
#include "hdt-common.h"
+#include "lib-ansi.h"
struct cli_mode_descr *list_modes[] = {
&hdt_mode,
more_printf("Entering CLI mode\n");
/* Display the cursor */
- fputs("\033[?25h", stdout);
+ display_cursor(true);
reset_prompt();
/* clear until then end of line */
case KEY_CTRL('k'):
/* Clear the end of the line */
- fputs("\033[0K", stdout);
+ clear_end_of_line();
memset(&hdt_cli.input[hdt_cli.cursor_pos], 0,
strlen(hdt_cli.input) - hdt_cli.cursor_pos);
break;
case KEY_LEFT:
if (hdt_cli.cursor_pos > 0) {
- fputs("\033[1D", stdout);
+ move_cursor_left(1);
hdt_cli.cursor_pos--;
}
break;
case KEY_RIGHT:
if (hdt_cli.cursor_pos < (int)strlen(hdt_cli.input)) {
- fputs("\033[1C", stdout);
+ move_cursor_right(1);
hdt_cli.cursor_pos++;
}
break;
/* Calling with a 0 value will make the cursor move */
/* So, let's move the cursor only if needed */
if ((strlen(hdt_cli.input) - hdt_cli.cursor_pos) > 0) {
- memset(temp_command, 0, sizeof(temp_command));
- sprintf(temp_command, "\033[%dC",
- strlen(hdt_cli.input) - hdt_cli.cursor_pos);
/* Return to the begining of line */
- fputs(temp_command, stdout);
+ move_cursor_right(strlen(hdt_cli.input) - hdt_cli.cursor_pos);
hdt_cli.cursor_pos = strlen(hdt_cli.input);
}
break;
/* Calling with a 0 value will make the cursor move */
/* So, let's move the cursor only if needed */
if (hdt_cli.cursor_pos > 0) {
- memset(temp_command, 0, sizeof(temp_command));
- sprintf(temp_command, "\033[%dD",
- hdt_cli.cursor_pos);
/* Return to the begining of line */
- fputs(temp_command, stdout);
+ move_cursor_left(hdt_cli.cursor_pos);
hdt_cli.cursor_pos = 0;
}
break;
hdt_cli.history_pos=future_history_pos;
/* Clear the line */
- fputs("\033[2K", stdout);
+ clear_line();
/* Move to the begining of line*/
- fputs("\033[0G", stdout);
+ move_cursor_to_column(0);
reset_prompt();
printf("%s",hdt_cli.history[hdt_cli.history_pos]);
hdt_cli.history_pos=future_history_pos;
/* Clear the line */
- fputs("\033[2K", stdout);
+ clear_line();
/* Move to the begining of line*/
- fputs("\033[0G", stdout);
+ move_cursor_to_column(0);
reset_prompt();
printf("%s",hdt_cli.history[hdt_cli.history_pos]);
case KEY_TAB:
if (autocomplete_backlog) {
- /* XXX Will go away */
- fputs("\033[2K", stdout);
- fputs("\033[0G", stdout);
+ clear_line();
+ /* Move to the begining of line*/
+ move_cursor_to_column(0);
reset_prompt();
printf("%s",autocomplete_last_seen->autocomplete_token);
strncpy(hdt_cli.input,autocomplete_last_seen->autocomplete_token,sizeof(hdt_cli.input));
hdt_cli.input[strlen(hdt_cli.input) - 1] = '\0';
/* Get one char back */
- fputs("\033[1D", stdout);
+ move_cursor_left(1);
+
/* Clear the end of the line */
- fputs("\033[0K", stdout);
+ clear_end_of_line();
/* Print the resulting buffer */
printf("%s", hdt_cli.input + hdt_cli.cursor_pos - 1);
/* Realing to the place we were */
- memset(temp_command, 0, sizeof(temp_command));
- sprintf(temp_command, "\033[%dD",
- strlen(hdt_cli.input + hdt_cli.cursor_pos - 1));
- fputs(temp_command, stdout);
- fputs("\033[1C", stdout);
+ move_cursor_left(strlen(hdt_cli.input + hdt_cli.cursor_pos - 1));
+ move_cursor_right(1);
+
/* Don't decrement the position unless
* if we are at then end of the line*/
if (hdt_cli.cursor_pos > (int)strlen(hdt_cli.input))
temp_command);
/* Clear the end of the line */
- fputs("\033[0K", stdout);
+ clear_end_of_line();
/* Print the resulting buffer */
printf("%s", hdt_cli.input + hdt_cli.cursor_pos);
- sprintf(temp_command, "\033[%dD",
- trailing_chars);
+
/* Return where we must put the new char */
- fputs(temp_command, stdout);
+ move_cursor_left(trailing_chars);
} else {
putchar(current_key);
#include <getkey.h>
#include "syslinux/config.h"
#include "../lib/sys/vesa/vesa.h"
-
#include "hdt-common.h"
+#include "lib-ansi.h"
void detect_parameters(const int argc, const char *argv[],
struct s_hardware *hardware)
void clear_screen(void)
{
- fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
+ move_cursor_to_next_line();
+ disable_utf8();
+ set_g1_special_char();
+ set_us_g0_charset();
+ display_cursor(false);
+ clear_entire_screen();
display_line_nb = 0;
}
--- /dev/null
+/* ----------------------------------------------------------------------- *
+ *
+ * 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.
+ *
+ * -----------------------------------------------------------------------
+ * Ansi Sequences can be found here :
+ * http://ascii-table.com/ansi-escape-sequences-vt-100.php
+ * http://en.wikipedia.org/wiki/ANSI_escape_code
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+void display_cursor(bool status)
+{
+ if (status == true) {
+ fputs("\033[?25h", stdout);
+ } else {
+ fputs("\033[?25l", stdout);
+ }
+}
+
+void clear_end_of_line() {
+ fputs("\033[0K", stdout);
+}
+
+void move_cursor_left(int count) {
+ char buffer[10];
+ memset(buffer,0,sizeof(buffer));
+ sprintf(buffer,"\033[%dD",count);
+ fputs(buffer, stdout);
+}
+
+void move_cursor_right(int count) {
+ char buffer[10];
+ memset(buffer,0,sizeof(buffer));
+ sprintf(buffer,"\033[%dC",count);
+ fputs(buffer, stdout);
+}
+
+void clear_line() {
+ fputs("\033[2K", stdout);
+}
+
+void clear_beginning_of_line() {
+ fputs("\033[1K", stdout);
+}
+
+void move_cursor_to_column(int count) {
+ char buffer[10];
+ memset(buffer,0,sizeof(buffer));
+ sprintf(buffer,"\033[%dG",count);
+ fputs(buffer, stdout);
+}
+
+void move_cursor_to_next_line() {
+ fputs("\033e", stdout);
+}
+
+void disable_utf8() {
+ fputs("\033%@", stdout);
+}
+
+void set_g1_special_char(){
+ fputs("\033)0", stdout);
+}
+
+void set_us_g0_charset() {
+ fputs("\033(B\1#0", stdout);
+}
+
+void clear_entire_screen() {
+ fputs("\033[2J", stdout);
+}
--- /dev/null
+/* ----------------------------------------------------------------------- *
+ *
+ * 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();
+#endif